1 | export type Formatter = (delta: Delta, original: any) => string;
|
2 |
|
3 | export interface Delta {
|
4 | [key: string]: any;
|
5 | [key: number]: any;
|
6 | }
|
7 |
|
8 | export interface DiffContext {
|
9 | left: any;
|
10 | right: any;
|
11 | }
|
12 |
|
13 | export interface Config {
|
14 | // used to match objects when diffing arrays, by default only === operator is used
|
15 | objectHash?: (item: any) => string;
|
16 | arrays?: {
|
17 | // default true, detect items moved inside the array (otherwise they will be registered as remove+add)
|
18 | detectMove: boolean,
|
19 | // default false, the value of items moved is not included in deltas
|
20 | includeValueOnMove: boolean,
|
21 | };
|
22 | textDiff?: {
|
23 | // default 60, minimum string length (left and right sides) to use text diff algorythm: google-diff-match-patch
|
24 | minLength: number,
|
25 | };
|
26 | /*
|
27 | this optional function can be specified to ignore object properties (eg. volatile data)
|
28 | name: property name, present in either context.left or context.right objects
|
29 | context: the diff context (has context.left and context.right objects)
|
30 | */
|
31 | propertyFilter?: (name: string, context: DiffContext) => boolean;
|
32 | /*
|
33 | default false. if true, values in the obtained delta will be cloned (using jsondiffpatch.clone by default),
|
34 | to ensure delta keeps no references to left or right objects. this becomes useful if you're diffing and patching
|
35 | the same objects multiple times without serializing deltas.
|
36 |
|
37 | instead of true, a function can be specified here to provide a custom clone(value)
|
38 | */
|
39 | cloneDiffValues?: boolean | ((value: any) => any);
|
40 | }
|
41 |
|
42 | export class DiffPatcher {
|
43 | constructor(options?: any);
|
44 |
|
45 | clone: (value: any) => any;
|
46 | dateReviver: (key: string, value: any) => any;
|
47 | diff: (left: any, right: any) => Delta | undefined;
|
48 | formatters: {
|
49 | annotated: Formatter;
|
50 | console: Formatter;
|
51 | html: Formatter;
|
52 | };
|
53 | patch: (left: any, delta: Delta) => any;
|
54 | reverse: (delta: Delta) => Delta | undefined;
|
55 | unpatch: (right: any, delta: Delta) => any;
|
56 | }
|