You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Can diff any two [JSON](https://www.ecma-international.org/publications-and-standards/standards/ecma-404/) compliant objects - returns differences as [JSON Patch](http://jsonpatch.com/).
13
13
- Elegant array diffing by providing an `objectHash` to match array elements
14
14
- Ignore specific keys by providing a `propertyFilter`
15
+
- LCS-based move detection (or disable moves with `array.ignoreMove`)
16
+
- Limit traversal with `maxDepth` to collapse deep trees into a single replace
15
17
-:paw_prints:***Is it small?*** Zero dependencies - it's ~**3 KB** (minified).
18
+
- Ships ESM + CJS builds with types
16
19
-:crystal_ball:***Is it fast?*** I haven't done any performance comparison yet.
17
-
-:hatched_chick:***Is it stable?*** Test coverage is high, but it's still in its early days - bugs are expected.
18
20
- The interface is inspired by [jsondiffpatch](https://github.com/benjamine/jsondiffpatch)
Both config functions (`objectHash`, `propertyFilter`) receive a context as the second parameter to drive fine-grained decisions:
116
236
237
+
-`side`: `'left' | 'right'` indicating the value being inspected
238
+
-`path`: JSON Pointer-style path to the current value
239
+
-`index`: only on `objectHash`, giving the array index being processed
117
240
241
+
See the `objectHash` example above for how `pathInfo` can be combined with the context to scope hashing logic.
242
+
243
+
### How moves are found (Longest Common Subsequence)
244
+
245
+
When `ignoreMove` is `false`, array reorders emit move operations instead of delete/add pairs. We minimize moves by:
246
+
247
+
1. Hashing array elements with `objectHash` to get stable identifiers.
248
+
2. Computing the **[Longest Common Subsequence (LCS)](https://en.wikipedia.org/wiki/Longest_common_subsequence)** between the current order and the target order. The LCS represents items that stay in place.
249
+
3. Walking the target order and moving only the out-of-place items, keeping LCS items anchored. This yields the smallest set of `{ op: 'move', from, path }` operations needed to reach the target sequence.
250
+
251
+
This is implemented in `move-operations.ts` (`longestCommonSequence` + `moveOperations`) and is exercised in the tests in `src/move-operations.spec.ts`.
252
+
253
+
> For more examples, check out the [tests](./src/index.spec.ts)
0 commit comments