@smartimpact-it/json-merge-shopify
Version:
The library handles merging JSON objects and arrays.
73 lines (72 loc) • 2.23 kB
TypeScript
import { Path } from './Merger';
export interface ComparisonResult {
equal: boolean;
couldBeEqual?: boolean;
similarity?: number;
}
export interface NormalizedComparisonResult extends ComparisonResult {
couldBeEqual: boolean;
similarity: number;
}
export interface ArrayComparisonSource {
base: any[];
ours: any[];
theirs: any[];
}
export type ArrayElementPosition = number | Array<{
index: number;
similarity: number;
}> | null;
export interface ArrayElementResult {
object: any;
basePosition: ArrayElementPosition;
oursPosition: ArrayElementPosition;
theirsPosition: ArrayElementPosition;
}
export declare class Comparer {
/**
* Compare two variables, of any type.
*/
compare(a: any, b: any, parentPath?: Path, filename?: string | null): ComparisonResult;
/**
* Compare two arrays.
*/
compareArrays(a: any, b: any, parentPath?: Path, filename?: string | null): ComparisonResult | null;
/**
* Compare two objects (not arrays).
*/
compareObjects(a: any, b: any, parentPath?: Path, filename?: string | null): ComparisonResult | null;
/**
* Compare blocks of settings
*/
private compareSettingBlocks;
/**
* Compare Shopify setting fields
*/
private compareSettings;
/**
* Compare two strings.
*/
compareStrings(a: string, b: string, parentPath?: string[] | null, filename?: string | null): ComparisonResult;
/**
* Default values for non-equal comparison results.
*/
private unequal;
/**
* Default values for equal comparison results.
*/
private equal;
/**
* Normalize the comparison result.
*/
normalizeComparisonResult(result: ComparisonResult): NormalizedComparisonResult;
/**
* Get the possible positions of an object in an array.
*/
getArrayElementPossiblePositions(object: Object, source: Array<any>, path?: Path, filename?: string | null): ArrayElementPosition;
/**
* Do a 3-way comparison of an object in 3 arrays.
*/
getArrayElementDiff3(object: Object, sources: ArrayComparisonSource, path?: Path, filename?: string | null): ArrayElementResult;
}
export default Comparer;