Skip to content

Commit 0e078a7

Browse files
authored
Merge pull request benjamine#186 from nchen63/typings
Add Typescript Typings
2 parents 0fe51f8 + 2d44532 commit 0e078a7

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"cover-publish": "istanbul cover _mocha --report lcovonly && codeclimate < coverage/lcov.info"
1818
},
1919
"main": "./src/main",
20+
"types": "./src/index",
2021
"repository": {
2122
"type": "git",
2223
"url": "https://github.com/benjamine/jsondiffpatch.git"

src/index.d.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

0 commit comments

Comments
 (0)