Compares two objects and returns the differences between them if different formats: changed values, changed paths, differences.
Works in Node.js and in the browser.
- 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.
$ pnpm i o2diff
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
Returns the differences between original
and current
.
original
- the original object.current
- the current (actual) object.- returns
{ left, right }
object.
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.
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.
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 eachdest.path
.
Returns all the paths of the object.
obj
- the object.
Returns the object without excludedPaths
.
obj
- the object.excludedPaths
- the array of paths to exclude. The path can be with mask:*.name
orname.*
to exclude only path started or ended with the name.
Licensed under the MIT license.
Alexander Mac