Skip to content

Commit 1606a01

Browse files
committed
feat: add tests
1 parent 24faa25 commit 1606a01

File tree

10 files changed

+1058
-1002
lines changed

10 files changed

+1058
-1002
lines changed

dist/index.d.ts

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,69 @@
1-
type DiffStatus = "added" | "equal" | "moved" | "deleted" | "updated";
1+
declare const GRANULARITY: Record<string, "basic" | "deep">;
2+
type ListDiffStatus = "added" | "equal" | "moved" | "deleted" | "updated";
3+
type ObjectDiffStatus = "added" | "equal" | "deleted" | "updated";
24
type ObjectData = Record<string, any> | undefined | null;
35
type ListData = any;
4-
type Options = {
5-
ignoreArrayOrder?: boolean;
6+
type ObjectStatusTuple = readonly [
7+
"added",
8+
"equal",
9+
"deleted",
10+
"updated"
11+
];
12+
type ListStatusTuple = readonly [
13+
"added",
14+
"equal",
15+
"deleted",
16+
"moved",
17+
"updated"
18+
];
19+
type isEqualOptions = {
20+
ignoreArrayOrder?: boolean;
21+
};
22+
type ObjectOptions = {
23+
ignoreArrayOrder?: boolean;
24+
showOnly?: {
25+
statuses: Array<ObjectStatusTuple[number]>;
26+
granularity?: typeof GRANULARITY[keyof typeof GRANULARITY];
27+
};
28+
};
29+
type ListOptions = {
30+
showOnly?: Array<ListStatusTuple[number]>;
631
};
732
type ListDiff = {
8-
type: "list";
9-
status: DiffStatus;
10-
diff: {
11-
value: ListData;
12-
prevIndex: number | null;
13-
newIndex: number | null;
14-
indexDiff: number | null;
15-
status: DiffStatus;
16-
}[];
33+
type: "list";
34+
status: ListDiffStatus;
35+
diff: {
36+
value: ListData;
37+
prevIndex: number | null;
38+
newIndex: number | null;
39+
indexDiff: number | null;
40+
status: ListDiffStatus;
41+
}[];
1742
};
1843
type SubProperties = {
19-
name: string;
20-
previousValue: any;
21-
currentValue: any;
22-
status: DiffStatus;
23-
subDiff?: SubProperties[];
24-
};
25-
type ObjectDiff = {
26-
type: "object";
27-
status: DiffStatus;
28-
diff: {
2944
property: string;
3045
previousValue: any;
3146
currentValue: any;
32-
status: DiffStatus;
47+
status: ObjectDiffStatus;
3348
subPropertiesDiff?: SubProperties[];
34-
}[];
49+
};
50+
type ObjectDiff = {
51+
type: "object";
52+
status: ObjectDiffStatus;
53+
diff: {
54+
property: string;
55+
previousValue: any;
56+
currentValue: any;
57+
status: ObjectDiffStatus;
58+
subPropertiesDiff?: SubProperties[];
59+
}[];
3560
};
3661

37-
declare function getObjectDiff(
38-
prevData: ObjectData,
39-
nextData: ObjectData,
40-
options?: Options
41-
): ObjectDiff;
62+
declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, options?: ObjectOptions): ObjectDiff;
4263

43-
declare const getListDiff: (
44-
prevList: ListData[] | undefined | null,
45-
nextList: ListData[] | undefined | null
46-
) => ListDiff;
64+
declare const getListDiff: (prevList: ListData[] | undefined | null, nextList: ListData[] | undefined | null, options?: ListOptions) => ListDiff;
4765

48-
declare function isEqual(a: any, b: any, options?: Options): boolean;
66+
declare function isEqual(a: any, b: any, options?: isEqualOptions): boolean;
4967
declare function isObject(value: any): value is Record<string, any>;
5068

5169
export { getListDiff, getObjectDiff, isEqual, isObject };

dist/index.js

Lines changed: 6 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)