Skip to content

Commit 51bfed7

Browse files
committed
added types
1 parent 3abd2c5 commit 51bfed7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "simple-diff",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "simple diff for object and arrays with options",
55
"main": "simple-diff.js",
6+
"types": "simple-diff.d.ts",
67
"scripts": {
78
"test": "mocha -R spec"
89
},

simple-diff.d.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
declare function diff(oldObj: any, newObj: any, ops?: DiffOptions): DiffEvent[];
2+
3+
export default diff;
4+
5+
export interface DiffOptions extends Partial<PathChange> {
6+
idProp?: string,
7+
addEvent?: string,
8+
removeEvent?: string,
9+
changeEvent?: string,
10+
addItemEvent?: string,
11+
removeItemEvent?: string,
12+
moveItemEvent?: string,
13+
callback?: (event: DiffEvent) => void,
14+
comparators?: Array<[any, Comparator]>,
15+
ignore?: Comparator,
16+
}
17+
18+
export type Path = Array<string | number>;
19+
20+
export interface PathChange {
21+
oldPath: Path,
22+
newPath: Path,
23+
}
24+
25+
export type Comparator = (oldValue: any, newValue: any, options: PathChange) => boolean;
26+
27+
export interface DiffEvent extends PathChange {
28+
type: 'add' | 'remove' | 'change' | 'add-item' | 'remove-item' | 'move-item',
29+
oldValue: any,
30+
newValue: any,
31+
}

0 commit comments

Comments
 (0)