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
BREAKING CHANGE: subPropertiesDiff has been removed from the getObjectDiff output. There is now a single recursive diff key for more simplicity. The types have also been improved.
This library compares two arrays or objects and returns a full diff of their differences.
14
+
15
+
<hr/>
16
+
12
17
## WHY YOU SHOULD USE THIS LIBRARY
13
18
14
-
All other existing solutions return a strange diff format that often requires additional parsing. They are also limited to object comparison. 👎
19
+
All other existing solutions return a strange diff format that often requires additional parsing. They are also limited to object comparison.
15
20
16
21
**Superdiff** gives you a complete diff for both array <u>and</u> objects in a very readable format. Last but not least, it's battle-tested and super fast. Import. Enjoy. 👍
17
22
23
+
<hr/>
24
+
18
25
## DONORS
19
26
20
27
I am grateful to the generous donors of **Superdiff**!
@@ -27,111 +34,7 @@ I am grateful to the generous donors of **Superdiff**!
27
34
28
35
</div>
29
36
30
-
## DIFF FORMAT COMPARISON
31
-
32
-
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
33
-
34
-
input:
35
-
36
-
```diff
37
-
const objectA = {
38
-
id: 54,
39
-
user: {
40
-
name: "joe",
41
-
- member: true,
42
-
- hobbies: ["golf", "football"],
43
-
age: 66,
44
-
},
45
-
}
46
-
47
-
const objectB = {
48
-
id: 54,
49
-
user: {
50
-
name: "joe",
51
-
+ member: false,
52
-
+ hobbies: ["golf", "chess"],
53
-
age: 66,
54
-
},
55
-
}
56
-
```
57
-
58
-
**Deep-Diff** output:
59
-
60
-
```js
61
-
[
62
-
{
63
-
kind:"E",
64
-
path: ["user", "member"],
65
-
lhs:true,
66
-
rhs:false,
67
-
},
68
-
{
69
-
kind:"E",
70
-
path: ["user", "hobbies", 1],
71
-
lhs:"football",
72
-
rhs:"chess",
73
-
},
74
-
];
75
-
```
76
-
77
-
**SuperDiff** output:
78
-
79
-
```diff
80
-
{
81
-
type: "object",
82
-
+ status: "updated",
83
-
diff: [
84
-
{
85
-
property: "id",
86
-
previousValue: 54,
87
-
currentValue: 54,
88
-
status: "equal",
89
-
},
90
-
{
91
-
property: "user",
92
-
previousValue: {
93
-
name: "joe",
94
-
member: true,
95
-
hobbies: ["golf", "football"],
96
-
age: 66,
97
-
},
98
-
currentValue: {
99
-
name: "joe",
100
-
member: false,
101
-
hobbies: ["golf", "chess"],
102
-
age: 66,
103
-
},
104
-
+ status: "updated",
105
-
subPropertiesDiff: [
106
-
{
107
-
property: "name",
108
-
previousValue: "joe",
109
-
currentValue: "joe",
110
-
status: "equal",
111
-
},
112
-
+ {
113
-
+ property: "member",
114
-
+ previousValue: true,
115
-
+ currentValue: false,
116
-
+ status: "updated",
117
-
+ },
118
-
+ {
119
-
+ property: "hobbies",
120
-
+ previousValue: ["golf", "football"],
121
-
+ currentValue: ["golf", "chess"],
122
-
+ status: "updated",
123
-
+ },
124
-
{
125
-
property: "age",
126
-
previousValue: 66,
127
-
currentValue: 66,
128
-
status: "equal",
129
-
},
130
-
],
131
-
},
132
-
],
133
-
}
134
-
```
37
+
<hr/>
135
38
136
39
## FEATURES
137
40
@@ -158,17 +61,17 @@ type ObjectDiff = {
158
61
status:"added"|"deleted"|"equal"|"updated";
159
62
diff: {
160
63
property:string;
161
-
previousValue:any;
162
-
currentValue:any;
64
+
previousValue:unknown;
65
+
currentValue:unknow;
163
66
status:"added"|"deleted"|"equal"|"updated";
164
67
// only appears if some subproperties have been added/deleted/updated
165
-
subPropertiesDiff?: {
68
+
diff?: {
166
69
property:string;
167
-
previousValue:any;
168
-
currentValue:any;
70
+
previousValue:unknown;
71
+
currentValue:unknown;
169
72
status:"added"|"deleted"|"equal"|"updated";
170
-
//subDiff is a recursive diff in case of nested subproperties
Copy file name to clipboardExpand all lines: package.json
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "@donedeal0/superdiff",
3
-
"version": "1.1.3",
3
+
"version": "2.0.0",
4
4
"description": "SuperDiff checks the changes between two objects or arrays. It returns a complete diff with relevant information for each property or piece of data",
0 commit comments