@f/changed-paths
v1.0.0
Published
Compute the deep paths that have changed between two, presumed immutable, objects
Downloads
4
Readme
changed-paths
Compute the deep paths that have changed between two, presumed immutable, objects
Installation
$ npm install @f/changed-paths
Usage
var changedPaths = require('@f/changed-paths')
changedPaths({a: {b: 1}}, {a: {b: 2, c: 3}}) // -> ['a', 'a.b', 'a.c']
changedPaths({a: [1, 2, 3]}, {a: [1, 3, 4]}) // -> ['a', 'a.1', 'a.2']
Note that this library assumes that your objects are immutable. That is, it will not descend into a subtree if they are reference equal to each other. This makes this diff asymptotically more performant than other, similar deep diffs.
API
changedPaths(next, prev)
next
- The new valueprev
- The old value
Returns: An array containing the unique list of paths that are different between the two.
License
MIT