Skip to content

Commit 9a1ca68

Browse files
committed
update readme
1 parent 1606a01 commit 9a1ca68

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

README.md

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ This library compares two arrays or objects and return a complete diff of their
66

77
## WHY YOU SHOULD USE THIS LIB
88

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. 👎
1010

1111
**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. 👍
1212

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-
2213
## DIFF FORMAT COMPARISON
2314

2415
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
@@ -51,20 +42,19 @@ const objectB = {
5142

5243
```js
5344
[
54-
DiffEdit {
55-
kind: 'E',
56-
path: [ 'user', 'member' ],
57-
lhs: true,
58-
rhs: false
59-
},
60-
DiffEdit {
61-
kind: 'E',
62-
path: [ 'user', 'hobbies', 1 ],
63-
lhs: 'football',
64-
rhs: 'chess'
65-
}
66-
]
67-
45+
{
46+
kind: "E",
47+
path: ["user", "member"],
48+
lhs: true,
49+
rhs: false,
50+
},
51+
{
52+
kind: "E",
53+
path: ["user", "hobbies", 1],
54+
lhs: "football",
55+
rhs: "chess",
56+
},
57+
];
6858
```
6959

7060
**SuperDiff** output:
@@ -148,18 +138,18 @@ format:
148138
```ts
149139
type ObjectDiff = {
150140
type: "object";
151-
status: "added" | "deleted" | "equal" | "moved" | "updated";
141+
status: "added" | "deleted" | "equal" | "updated";
152142
diff: {
153143
property: string;
154144
previousValue: any;
155145
currentValue: any;
156-
status: "added" | "deleted" | "equal" | "moved" | "updated";
146+
status: "added" | "deleted" | "equal" | "updated";
157147
// only appears if some subproperties have been added/deleted/updated
158148
subPropertiesDiff?: {
159149
property: string;
160150
previousValue: any;
161151
currentValue: any;
162-
status: "added" | "deleted" | "equal" | "moved" | "updated";
152+
status: "added" | "deleted" | "equal" | "updated";
163153
// subDiff is a recursive diff in case of nested subproperties
164154
subDiff?: SubProperties[];
165155
}[];
@@ -169,23 +159,25 @@ type ObjectDiff = {
169159

170160
**Options**
171161

162+
You can add a third `options` parameter to `getObjectDiff`.
163+
172164
```ts
173165
{
174166
ignoreArrayOrder?: boolean // false by default,
175167
showOnly?: {
176168
statuses: ("added" | "deleted" | "updated" | "equal")[], // [] by default
177-
granularity?: "basic" | "deep" // basic by default
169+
granularity?: "basic" | "deep" // "basic" by default
178170
}
179171
}
180172
```
181173

182174
- `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.
183-
- `showOnly`: gives you the option to only return the values whose status interest you. It has two parameters:
175+
- `showOnly`: only returns the values whose status interest you. It has two parameters:
184176

185177
- `statuses`: status you want to see in the output (ex: `["added", "equal"]`)
186178
- `granularity`:
187-
- `basic` only returns the main properties whose status match your request, without taking into account their eventual subproperties.
188-
- `deep` return main properties whose status match your request but also their relevant subproperties.
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.
189181

190182
### getListDiff()
191183

@@ -219,6 +211,8 @@ type ListDiff = {
219211

220212
**Options**
221213

214+
You can add a third `options` parameter to `getListDiff`.
215+
222216
```ts
223217
{
224218
showOnly?: ("added" | "deleted" | "moved" | "updated" | "equal")[], // [] by default
@@ -237,6 +231,8 @@ Checks if two values are equal.
237231

238232
**Options**
239233

234+
You can add a third `options` parameter to `isEqual`.
235+
240236
```ts
241237
{
242238
ignoreArrayOrder?: boolean // false by default,
@@ -433,7 +429,7 @@ output
433429
false;
434430
```
435431

436-
More examples are availble in the tests of the source code.
432+
More examples are available in the tests of the source code.
437433

438434
<hr/>
439435

@@ -443,7 +439,7 @@ DoneDeal0
443439

444440
## SUPPORT
445441

446-
If you or your company 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:
447443
https://www.buymeacoffee.com/donedeal0
448444

449445
<br/>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@donedeal0/superdiff",
3-
"version": "1.0.9",
3+
"version": "1.0.8",
44
"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",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

0 commit comments

Comments
 (0)