differrer
Version:
> Utility to perform deep diff on any data types with smart order detection in arrays and different views implemented for convenience
39 lines (38 loc) • 1.86 kB
TypeScript
export { diffJsView } from './diffJsView/diffJsView';
export { diffSortedView } from './diffSortedView/diffSortedView';
export { diffChangesViewConsole, diffChangesViewRaw } from './diffChangesView/diffChangesView';
export declare const isPlainObject: (value: any) => value is Record<string, unknown>;
export declare const getType: (value: any) => "object" | "array" | "string" | "number" | "boolean" | "null" | "undefined" | "unknown";
export type GetArrayElementId = (value: unknown, path: (string | number)[] | null, parent?: unknown) => unknown;
export type ValueForDiff = null | undefined | string | number | boolean | ValueForDiff[] | {
[key: string]: ValueForDiff;
};
export type DiffDetails = {
sourcePath: (string | number)[] | null;
targetPath: (string | number)[] | null;
sourceValue: ValueForDiff;
targetValue: ValueForDiff;
sameValue: boolean;
sameValueZero: boolean;
retrievedId: string | number | null;
sourceOrder: string | number | null;
targetOrder: string | number | null;
sameOrder: boolean | null;
sourceType: string;
targetType: string;
sameType: boolean;
added: boolean;
removed: boolean;
changed: boolean;
children: DiffDetails[] | {
[key: string]: DiffDetails;
} | null;
};
export type DiffOptions = {
sortArrayItems?: boolean;
getArrayElementId: GetArrayElementId;
getValue?: (value: ValueForDiff, path: (string | number)[] | null) => ValueForDiff;
};
export declare const getArrayElementIdWrapper: (getArrayElementId: GetArrayElementId) => (value: unknown, path: (string | number)[] | null, parent?: unknown) => string | number | null;
export declare const diff: ({ sortArrayItems, getArrayElementId: getArrayElementIdRaw, getValue, }: DiffOptions) => (source: ValueForDiff, target: ValueForDiff) => DiffDetails;
export default diff;