@audc/json-diff-ts
Version:
A diff tool for JavaScript based on https://www.npmjs.com/package/diff-json written in TypeScript.
32 lines (31 loc) • 1.18 kB
TypeScript
import { Dictionary } from 'lodash';
declare type FunctionKey = (obj: any) => any;
export declare const getTypeOfObj: (obj: any) => string;
export declare const diff: (oldObj: any, newObj: any, embeddedObjKeys?: Dictionary<string | FunctionKey>, keysToSkip?: string[]) => IChange[];
export declare const applyChangeset: (obj: any, changeset: Changeset) => any;
export declare const revertChangeset: (obj: any, changeset: Changeset) => any;
export declare enum Operation {
REMOVE = "REMOVE",
ADD = "ADD",
UPDATE = "UPDATE"
}
export interface IChange {
type: Operation;
key: string;
embeddedKey?: string | FunctionKey;
value?: any | any[];
oldValue?: any;
changes?: IChange[];
}
export declare type Changeset = IChange[];
export interface IFlatChange {
type: Operation;
key: string;
path: string;
valueType: string | null;
value?: any;
oldValue?: any;
}
export declare const flattenChangeset: (obj: Changeset | IChange, path?: string, embeddedKey?: string | FunctionKey) => IFlatChange[];
export declare const unflattenChanges: (changes: IFlatChange | IFlatChange[]) => IChange[];
export {};