Browse Source

update readme

pull/10/head
DoneDeal0 2 years ago
parent
commit
9a1ca68084
  1. 62
      README.md
  2. 2
      package.json

62
README.md

@ -6,19 +6,10 @@ This library compares two arrays or objects and return a complete diff of their @@ -6,19 +6,10 @@ This library compares two arrays or objects and return a complete diff of their
## WHY YOU SHOULD USE THIS LIB
All other existing solutions return a weird diff format which often require an additional parsing. They are also slow and limited to object comparison. 👎
All other existing solutions return a weird diff format which often require an additional parsing. They are also limited to object comparison. 👎
**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. 👍
**Benchmark**:
| Objects | Deep-diff 🐢 | Superdiff ⚡ |
| --------- | ------------ | ------------ |
| 1.000 | 10.47ms | 5.73ms |
| 10.000 | 43.05ms | 18.60ms |
| 100.000 | 289.71ms | 50.96ms |
| 1.000.000 | 2786.70ms | 389.78ms |
## DIFF FORMAT COMPARISON
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
@ -51,20 +42,19 @@ const objectB = { @@ -51,20 +42,19 @@ const objectB = {
```js
[
DiffEdit {
kind: 'E',
path: [ 'user', 'member' ],
lhs: true,
rhs: false
},
DiffEdit {
kind: 'E',
path: [ 'user', 'hobbies', 1 ],
lhs: 'football',
rhs: 'chess'
}
]
{
kind: "E",
path: ["user", "member"],
lhs: true,
rhs: false,
},
{
kind: "E",
path: ["user", "hobbies", 1],
lhs: "football",
rhs: "chess",
},
];
```
**SuperDiff** output:
@ -148,18 +138,18 @@ format: @@ -148,18 +138,18 @@ format:
```ts
type ObjectDiff = {
type: "object";
status: "added" | "deleted" | "equal" | "moved" | "updated";
status: "added" | "deleted" | "equal" | "updated";
diff: {
property: string;
previousValue: any;
currentValue: any;
status: "added" | "deleted" | "equal" | "moved" | "updated";
status: "added" | "deleted" | "equal" | "updated";
// only appears if some subproperties have been added/deleted/updated
subPropertiesDiff?: {
property: string;
previousValue: any;
currentValue: any;
status: "added" | "deleted" | "equal" | "moved" | "updated";
status: "added" | "deleted" | "equal" | "updated";
// subDiff is a recursive diff in case of nested subproperties
subDiff?: SubProperties[];
}[];
@ -169,23 +159,25 @@ type ObjectDiff = { @@ -169,23 +159,25 @@ type ObjectDiff = {
**Options**
You can add a third `options` parameter to `getObjectDiff`.
```ts
{
ignoreArrayOrder?: boolean // false by default,
showOnly?: {
statuses: ("added" | "deleted" | "updated" | "equal")[], // [] by default
granularity?: "basic" | "deep" // basic by default
granularity?: "basic" | "deep" // "basic" by default
}
}
```
- `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.
- `showOnly`: gives you the option to only return the values whose status interest you. It has two parameters:
- `showOnly`: only returns the values whose status interest you. It has two parameters:
- `statuses`: status you want to see in the output (ex: `["added", "equal"]`)
- `granularity`:
- `basic` only returns the main properties whose status match your request, without taking into account their eventual subproperties.
- `deep` return main properties whose status match your request but also their relevant subproperties.
- `basic` only returns the main properties whose status match your request.
- `deep` can return main properties if some of their subproperties' status match your request. The subproperties will be filtered accordingly.
### getListDiff()
@ -219,6 +211,8 @@ type ListDiff = { @@ -219,6 +211,8 @@ type ListDiff = {
**Options**
You can add a third `options` parameter to `getListDiff`.
```ts
{
showOnly?: ("added" | "deleted" | "moved" | "updated" | "equal")[], // [] by default
@ -237,6 +231,8 @@ Checks if two values are equal. @@ -237,6 +231,8 @@ Checks if two values are equal.
**Options**
You can add a third `options` parameter to `isEqual`.
```ts
{
ignoreArrayOrder?: boolean // false by default,
@ -433,7 +429,7 @@ output @@ -433,7 +429,7 @@ output
false;
```
More examples are availble in the tests of the source code.
More examples are available in the tests of the source code.
<hr/>
@ -443,7 +439,7 @@ DoneDeal0 @@ -443,7 +439,7 @@ DoneDeal0
## SUPPORT
If you or your company use Superdiff, please show your support by buying me coffee:
If you or your company use Superdiff, please show your support by buying me a coffee:
https://www.buymeacoffee.com/donedeal0
<br/>

2
package.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "@donedeal0/superdiff",
"version": "1.0.9",
"version": "1.0.8",
"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",
"main": "dist/index.js",
"module": "dist/index.js",

Loading…
Cancel
Save