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
Copy file name to clipboardExpand all lines: README.md
+75-51Lines changed: 75 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,10 @@ This library compares two arrays or objects and return a complete diff of their
6
6
7
7
## WHY YOU SHOULD USE THIS LIB
8
8
9
-
All other existing solutions return a weird diff format which often require an additional parsing. They are also slow and limited to object comparison. 👎
9
+
All other existing solutions return a weird diff format which often require an additional parsing. They are also limited to object comparison. 👎
10
10
11
11
**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 and super fast. Import. Enjoy. 👍
12
12
13
-
**Benchmark**:
14
-
15
-
| Objects | Deep-diff 🐢 | Superdiff ⚡ |
16
-
| --------- | ------------ | ------------ |
17
-
| 1.000 | 10.47ms | 5.73ms |
18
-
| 10.000 | 43.05ms | 18.60ms |
19
-
| 100.000 | 289.71ms | 50.96ms |
20
-
| 1.000.000 | 2786.70ms | 389.78ms |
21
-
22
13
## DIFF FORMAT COMPARISON
23
14
24
15
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
// subDiff is a recursive diff in case of nested subproperties
164
-
subDiff?:Subproperties[];
154
+
subDiff?:SubProperties[];
165
155
}[];
166
156
}[];
167
157
};
168
158
```
169
159
160
+
**Options**
161
+
162
+
You can add a third `options` parameter to `getObjectDiff`.
163
+
164
+
```ts
165
+
{
166
+
ignoreArrayOrder?:boolean// false by default,
167
+
showOnly?: {
168
+
statuses: ("added"|"deleted"|"updated"|"equal")[], // [] by default
169
+
granularity?: "basic"|"deep"// "basic" by default
170
+
}
171
+
}
172
+
```
173
+
174
+
-`ignoreArrayOrder`: if set to `true`, `["hello", "world"]` and `["world", "hello"]` will be considered as `equal`, because the two arrays have the same value, just not in the same order.
175
+
-`showOnly`: only returns the values whose status interest you. It has two parameters:
176
+
177
+
-`statuses`: status you want to see in the output (ex: `["added", "equal"]`)
178
+
-`granularity`:
179
+
-`basic` only returns the main properties whose status match your request.
180
+
-`deep` can return main properties if some of their subproperties' status match your request. The subproperties will be filtered accordingly.
181
+
170
182
### getListDiff()
171
183
172
184
```js
@@ -197,6 +209,18 @@ type ListDiff = {
197
209
};
198
210
```
199
211
212
+
**Options**
213
+
214
+
You can add a third `options` parameter to `getListDiff`.
215
+
216
+
```ts
217
+
{
218
+
showOnly?: ("added"|"deleted"|"moved"|"updated"|"equal")[], // [] by default
219
+
}
220
+
```
221
+
222
+
-`showOnly` gives you the option to only return the values whose status interest you (ex: `["added", "equal"]`).
223
+
200
224
### isEqual()
201
225
202
226
```js
@@ -205,6 +229,18 @@ import { isEqual } from "@donedeal0/superdiff";
205
229
206
230
Checks if two values are equal.
207
231
232
+
**Options**
233
+
234
+
You can add a third `options` parameter to `isEqual`.
235
+
236
+
```ts
237
+
{
238
+
ignoreArrayOrder?:boolean// false by default,
239
+
}
240
+
```
241
+
242
+
-`ignoreArrayOrder`: if set to `true`, `["hello", "world"]` and `["world", "hello"]` will be considered as `equal`, because the two arrays have the same value, just not in the same order.
243
+
208
244
### isObject()
209
245
210
246
```js
@@ -329,25 +365,25 @@ output
329
365
+ status: "updated",
330
366
subPropertiesDiff: [
331
367
{
332
-
name: "name",
368
+
property: "name",
333
369
previousValue: "joe",
334
370
currentValue: "joe",
335
371
status: "equal",
336
372
},
337
373
+ {
338
-
+name: "member",
374
+
+property: "member",
339
375
+ previousValue: true,
340
376
+ currentValue: false,
341
377
+ status: "updated",
342
378
+ },
343
379
+ {
344
-
+name: "hobbies",
380
+
+property: "hobbies",
345
381
+ previousValue: ["golf", "football"],
346
382
+ currentValue: ["golf", "chess"],
347
383
+ status: "updated",
348
384
+ },
349
385
{
350
-
name: "age",
386
+
property: "age",
351
387
previousValue: 66,
352
388
currentValue: 66,
353
389
status: "equal",
@@ -393,29 +429,17 @@ output
393
429
false;
394
430
```
395
431
396
-
More examples are availble in the tests of the source code.
432
+
More examples are available in the tests of the source code.
397
433
398
434
<hr/>
399
435
400
-
### OPTIONS
401
-
402
-
`getObjectDiff()` and `isEqual()` accept a facultative `options` parameter:
403
-
404
-
```ts
405
-
{
406
-
discardArrayOrder?:boolean// false by default
407
-
}
408
-
```
409
-
410
-
If `discardArrayOrder` is set to `true`, `["hello", "world"]` and `["world", "hello"]` will be considered as `equal`, because the two arrays have the same value, just not in the same order.
411
-
412
436
## CREDITS
413
437
414
438
DoneDeal0
415
439
416
440
## SUPPORT
417
441
418
-
If you use Superdiff, please show your support by buying me coffee:
442
+
If you or your company use Superdiff, please show your support by buying me a coffee:
0 commit comments