You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library compares two arrays or objects and return a complete diff of their differences.
4
4
5
-
## Object exemple:
5
+
## WHY YOU SHOULD USE THIS LIB
6
6
7
-
`getObjectDiff()` checks base properties but also provides a complete diff of nested properties.
7
+
All other existing solutions return a weird diff format which often require an additionnal parsing. They are also limited to object comparison. Some even have CPU spikes issues. 👎
8
8
9
-
Input
9
+
**Superdiff** gives you a complete diff for both array <u>and</u> objects with a very readable format. Last but not least, it's battled tested. Import. Enjoy. 👍
10
+
11
+
## DIFF FORMAT COMPARISON
12
+
13
+
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
14
+
15
+
input:
10
16
11
17
```diff
12
-
getObjectDiff(
13
-
{
14
-
id: 54,
15
-
user: {
16
-
name: "joe",
17
-
-member: true,
18
-
-hobbies: ["golf", "football"],
19
-
age: 66,
20
-
},
21
-
},
22
-
{
23
-
id: 54,
24
-
user: {
25
-
name: "joe",
26
-
+ member: false,
27
-
+ hobbies: ["golf", "chess"],
28
-
age: 66,
29
-
},
18
+
const objectA = {
19
+
id: 54,
20
+
user: {
21
+
name: "joe",
22
+
- member: true,
23
+
- hobbies: ["golf", "football"],
24
+
age: 66,
25
+
},
26
+
}
27
+
28
+
const objectB = {
29
+
id: 54,
30
+
user: {
31
+
name: "joe",
32
+
+member: false,
33
+
+hobbies: ["golf", "chess"],
34
+
age: 66,
35
+
},
30
36
}
31
-
);
32
37
```
33
38
34
-
Output
39
+
**Deep-Diff**
40
+
41
+
````js
42
+
**Deep-Diff** output:
43
+
44
+
```js
45
+
[
46
+
DiffEdit {
47
+
kind: 'E',
48
+
path: [ 'user', 'member' ],
49
+
lhs: true,
50
+
rhs: false
51
+
},
52
+
DiffEdit {
53
+
kind: 'E',
54
+
path: [ 'user', 'hobbies', 1 ],
55
+
lhs: 'football',
56
+
rhs: 'chess'
57
+
}
58
+
]
59
+
60
+
````
61
+
62
+
**SuperDiff** output:
35
63
36
64
```diff
37
65
{
@@ -90,12 +118,81 @@ Output
90
118
}
91
119
```
92
120
93
-
## List exemple:
121
+
## FEATURES
122
+
123
+
**Superdiff**exports4 functions:
124
+
125
+
### getObjectDiff()
126
+
127
+
compare two objects and return a diff for each value and their potential subvalues:
128
+
129
+
- property name
130
+
- status: added, deleted, equal, updated
131
+
- previous value, current value
132
+
- supports deeply nested objects with any kind of values
0 commit comments