Browse Source

fix: readme

pull/6/head
DoneDeal0 2 years ago
parent
commit
75e2da62fa
  1. 65
      README.md
  2. 10
      package.json

65
README.md

@ -6,7 +6,7 @@ This library compares two arrays or objects and return a complete diff of their
## WHY YOU SHOULD USE THIS LIB ## WHY YOU SHOULD USE THIS LIB
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. 👎 All other existing solutions return a weird diff format which often require an additionnal 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. Import. Enjoy. 👍 **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. 👍
@ -38,8 +38,6 @@ const objectB = {
} }
``` ```
**Deep-Diff**
**Deep-Diff** output: **Deep-Diff** output:
```js ```js
@ -58,7 +56,7 @@ const objectB = {
} }
] ]
```` ```
**SuperDiff** output: **SuperDiff** output:
@ -125,10 +123,14 @@ const objectB = {
### getObjectDiff() ### getObjectDiff()
compare two objects and return a diff for each value and their potential subvalues: ```js
import { getObjectDiff } from "superdiff";
```
Compares two objects and return a diff for each value and their potential subvalues:
- property name - property name
- status: added, deleted, equal, updated - status: `added`, `deleted`, `equal`, `updated`
- previous value, current value - previous value, current value
- supports deeply nested objects with any kind of values - supports deeply nested objects with any kind of values
@ -137,57 +139,69 @@ format:
```ts ```ts
type ObjectDiff = { type ObjectDiff = {
type: "object"; type: "object";
status: "added" | "deleted" | "equal" | "moved" | "updated"; status: "added" | "deleted" | "equal" | "moved" | "updated";
diff: { diff: {
property: string; property: string;
previousValue: any; previousValue: any;
currentValue: any; currentValue: any;
status: "added" | "deleted" | "equal" | "moved" | "updated"; status: "added" | "deleted" | "equal" | "moved" | "updated";
subPropertiesDiff?: { subPropertiesDiff?: {
name: string; name: string;
previousValue: any; previousValue: any;
currentValue: any; currentValue: any;
status: "added" | "deleted" | "equal" | "moved" | "updated"; status: "added" | "deleted" | "equal" | "moved" | "updated";
// subDiff is a recursive diff in case of nested subproperties // subDiff is a recursive diff in case of nested subproperties
subDiff?: Subproperties[]; subDiff?: Subproperties[];
}[]; }[];
}[]; }[];
} };
``` ```
### getListDiff() ### getListDiff()
compare two arrays and return a diff for each value: ```js
import { getListDiff } from "superdiff";
```
- index change: previous index, current index, index difference Compares two arrays and return a diff for each value:
- status: added, deleted, equal, moved, updated
- previous value, current value - index change: `prevIndex`, `newIndex`, `indexDiff`
- status: `added`, `deleted`, `equal`, `moved`, `updated`
- value
- supports array of primitive values and objects - supports array of primitive values and objects
- ⚠ doesn't support yet duplicated values comparison (but will soon) - ⚠ doesn't support duplicated values comparison yet (but will soon)
format: format:
```ts ```ts
type ListDiff = { type ListDiff = {
type: "list"; type: "list";
status: "added" | "deleted" | "equal" | "moved" | "updated"; status: "added" | "deleted" | "equal" | "moved" | "updated";
diff: { diff: {
value: any; value: any;
prevIndex: number | null; prevIndex: number | null;
newIndex: number | null; newIndex: number | null;
indexDiff: number | null; indexDiff: number | null;
status: "added" | "deleted" | "equal" | "moved" | "updated"; status: "added" | "deleted" | "equal" | "moved" | "updated";
}[]; }[];
}; };
``` ```
### isEqual() ### isEqual()
check if two values are equal. ```js
import { isEqual } from "superdiff";
```
Checks if two values are equal.
### isObject() ### isObject()
check if a value is an object. ```js
import { isObject } from "superdiff";
```
Checks if a value is an object.
## EXAMPLES ## EXAMPLES
@ -376,4 +390,5 @@ More examples are availble in the tests of the source code.
DoneDeal0 DoneDeal0
## CONTRIBUTING ## CONTRIBUTING
Pull requests are welcome! Pull requests are welcome!

10
package.json

@ -16,11 +16,17 @@
"url": "git+https://github.com/DoneDeal0/superdiff" "url": "git+https://github.com/DoneDeal0/superdiff"
}, },
"keywords": [ "keywords": [
"deep-diff",
"data diff", "data diff",
"comparison",
"comparison-tool",
"object-comparison",
"array-comparison",
"object-diff",
"objectdifference",
"object-difference",
"object", "object",
"diff", "diff",
"deep diff", "deep-diff",
"comparison", "comparison",
"compare" "compare"
], ],

Loading…
Cancel
Save