4.0.4 • Published 6 months ago

o2diff v4.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
6 months ago

Features

  • Provides three outputs:
    • diff: { left, right } the object differences.
    • values: { changed, added, deleted }, the changed values.
    • paths: { changed, added, deleted }, the changed paths.
  • Revert function, to revert the destination object to the source object.

Install

$ pnpm i o2diff

Usage

const o2diff = require('o2diff')

const original = {
  firstName: 'John',
  lastName: 'Smith',
  email: 'john@mail.com',
  phones: [
    { type: 'home', value: '+12222' },
    { type: 'mobile', value: '+11111' }
  ]
}
const current = {
  firstName: 'Michael',
  age: 25,
  email: 'michael@mail.com',
  phones: [
    { type: 'work', value: '+13333' },
    { type: 'mobile', value: '+11111' }
  ],
  address: {
    city: 'New York',
    location: {
      latitude: 40.730610,
      longitude: -73.935242
    }
  }
}

o2diff.diff(original, current)       // returns { left, right } with objects diff
o2diff.diffValues(original, current) // returns { changed, added, deleted } with values diff
o2diff.diffPaths(original, current)  // returns { changed, added, deleted } with paths diff

API

diff(original, current)

Returns the differences between original and current.

  • original - the original object.
  • current - the current (actual) object.
  • returns { left, right } object.
diffValues(original, current)

Returns the added, changed and deleted values between original and current.

  • original - the original object.
  • current - the current (actual) object.
  • returns { changed, added, deleted } object.
diffPaths(original, current)

Returns the added, changed and deleted paths between original and current.

  • original - the original object.
  • current - the current (actual) object.
  • returns { changed, added, deleted } object.
revert(dest, src, customizer)

Reverts dest object to src, calls customizer for each dest.path.

  • dest - the destination object.
  • src - the source object.
  • customizer - the function that is called for each dest.path.
getPaths(obj)

Returns all the paths of the object.

  • obj - the object.
omitPaths(obj, excludedPaths)

Returns the object without excludedPaths.

  • obj - the object.
  • excludedPaths - the array of paths to exclude. The path can be with mask: *.name or name.* to exclude only path started or ended with the name.

License

Licensed under the MIT license.

Author

Alexander Mac

4.0.4

6 months ago

4.0.3

7 months ago

4.0.2

7 months ago

4.0.1

12 months ago

4.0.0

12 months ago

3.0.0

2 years ago

1.2.0

4 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago