UNPKG

@smartimpact-it/json-merge-shopify

Version:

The library handles merging JSON objects and arrays.

62 lines (61 loc) 2.04 kB
export interface MergerConstructorOptions { ours: any; theirs: any; ancestor: any; filename?: string; preferred?: PreferredSide; /** Whether deletions are allowed in "our" side. */ deletionsAllowed?: boolean; } export type PreferredSide = 'ours' | 'theirs' | null; export type Path = string[]; declare const ConflictSeparator: "<<<<<<<<>>>>>>>>"; export interface ConflictNode { CONFLICT: typeof ConflictSeparator; OURS: any; THEIRS: any; ANCESTOR: any; PATH: string; } export declare class Merger { ours: any; theirs: any; ancestor: any; filename?: string | null; preferred?: PreferredSide; deletionsAllowed: boolean; _hasConflicts: boolean; constructor({ ours, theirs, ancestor, filename, preferred, deletionsAllowed, }: MergerConstructorOptions); /** * Merge the 3 JSON objects and return the result */ merge(): any; /** * The main merge function; we call it with the 3 json objects, and then * it recursively calls itself. It modifies ourNode with the result * of the merge. * * Path is an array of key names indicating where we are in the object */ mergeObject(ancestorNode: any, ourNode: any, theirNode: any, path?: Path): Object | ConflictNode; /** * Merge two arrays */ mergeArray(ancestorArray: Array<any>, ourArray: Array<any>, theirArray: Array<any>, path?: Path): Array<any> | ConflictNode; /** * Generate a node to indicate a conflict * We include `<<<<<<<<>>>>>>>>` so that developers used to searching for <<<< * to find conflicts can maintain their current habits */ createConflictNode(ancestorValue: any, ourValue: any, theirValue: any, path: Path): ConflictNode; /** * Get the element at a path */ getElementForPath(obj: Object, path: Path): any; /** * Get the parent element at a path */ getParentElementForPath(obj: Object, path: Path): any; hasConflicts(): boolean; } export default Merger;