diff --git a/README.md b/README.md index 86bd840..81df297 100644 --- a/README.md +++ b/README.md @@ -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 and 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 = { ```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: ```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 = { **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 = { **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. **Options** +You can add a third `options` parameter to `isEqual`. + ```ts { ignoreArrayOrder?: boolean // false by default, @@ -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.