@clipchamp/json-delta
Version:
Json object diff / patching with configurable short-circuit tolerance. Forked from: github.com/corps
31 lines (30 loc) • 1.43 kB
TypeScript
declare type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
export interface JsonMap {
[key: string]: AnyJson;
}
export interface JsonArray extends Array<AnyJson> {
}
export declare type ObjPath = (string | number)[];
export declare type DiffInsert<T> = [ObjPath, T];
export declare type DiffPart<T> = DiffInsert<T> | ObjPath;
export declare type Diff<T> = DiffPart<T>[];
export declare function isObject(o: any): o is {
[k: string]: any;
};
export declare function shallowCopy<T>(o: T): T;
export declare function getContainer<T>(orig: T, result: T, path: ObjPath): AnyJson | void;
export declare function getVal(container: AnyJson, path: ObjPath): AnyJson;
export declare function applyDiff<T>(o: T, d: Diff<T> | void): T;
export declare function applyInsert<T>(orig: T, result: T, insert: DiffInsert<T>): T;
export declare function applyDelete<T>(orig: T, result: T, path: ObjPath): T;
export declare function diff<T>(a: T, b: T, tolerance?: number): Diff<T> | null;
export declare function deepEqual(a: AnyJson, b: AnyJson): boolean;
/**
* Finds the longest common subsequence between a and b,
* optionally shortcutting any search whose removed elements
* would exceed the provided tolerance value.
* If there is no match within the provided tolerance, this function
* returns null.
*/
export declare function lcs(a: AnyJson[], b: AnyJson[], tolerance?: number): AnyJson[] | void;
export {};