This library compares two arrays or objects and return a complete diff of their differences.
This library compares two arrays or objects and return a complete diff of their differences.
## Object exemple:
## WHY YOU SHOULD USE THIS LIB
`getObjectDiff()` checks base properties but also provides a complete diff of nested properties.
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. 👎
Input
**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. 👍
## DIFF FORMAT COMPARISON
Let's compare the diff format of **Superdiff** and **Deep-diff**, the most popular diff lib on npm:
input:
```diff
```diff
getObjectDiff(
const objectA = {
{
id: 54,
id: 54,
user: {
user: {
name: "joe",
name: "joe",
- member: true,
- member: true,
- hobbies: ["golf", "football"],
- hobbies: ["golf", "football"],
age: 66,
age: 66,
},
},
}
},
{
constobjectB = {
id: 54,
id: 54,
user: {
user: {
name: "joe",
name: "joe",
+ member: false,
+ member: false,
+ hobbies: ["golf", "chess"],
+ hobbies: ["golf", "chess"],
age: 66,
age: 66,
},
},
}
}
);
```
```
Output
**Deep-Diff**
````js
**Deep-Diff** output:
```js
[
DiffEdit {
kind: 'E',
path: [ 'user', 'member' ],
lhs: true,
rhs: false
},
DiffEdit {
kind: 'E',
path: [ 'user', 'hobbies', 1 ],
lhs: 'football',
rhs: 'chess'
}
]
````
**SuperDiff** output:
```diff
```diff
{
{
@ -90,12 +118,81 @@ Output
}
}
```
```
## List exemple:
## FEATURES
**Superdiff** exports 4 functions:
### getObjectDiff()
compare two objects and return a diff for each value and their potential subvalues:
- property name
- status: added, deleted, equal, updated
- previous value, current value
- supports deeply nested objects with any kind of values