1.0.0 • Published 8 years ago

@f/changed-paths v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

changed-paths

Build status Git tag NPM version Code style

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 value
  • prev - The old value

Returns: An array containing the unique list of paths that are different between the two.

License

MIT