| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Compares two objects and returns the differences between them in different formats: changed values, changed paths, differences.
Works in Node.js and in the browser.
$ pnpm i o2diffimport { diff, diffPaths, diffValues } from '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
}
}
}
// objects diff
diff(original, current)
/*
{
left: {
firstName: 'John',
lastName: 'Smith',
email: 'john@mail.com',
phones: [{ type: 'home', value: '+12222' }]
},
right: {
firstName: 'Michael',
age: 25,
email: 'michael@mail.com',
phones: [{ type: 'work', value: '+13333' }],
address: {
city: 'New York',
location: { latitude: 40.730610, longitude: -73.935242 }
}
}
}
*/
// values diff
diffValues(original, current)
/*
{
changed: {
firstName: 'Michael',
email: 'michael@mail.com',
phones: [{ type: 'home', value: '+12222' }]
},
added: {
age: 25,
address: {
city: 'New York',
location: { latitude: 40.730610, longitude: -73.935242 }
}
},
deleted: {
lastName: 'Smith'
}
}
*/
// paths diff
diffPaths(original, current)
/*
{
changed: [
'firstName',
'email',
'phones[0].type',
'phones[0].value'
],
added: [
'age',
'address.city',
'address.location.latitude',
'address.location.longitude'
],
deleted: [
'lastName'
]
}
*/Returns the difference between original and current.
Returns added, changed and deleted values between original and current.
Returns added, changed and deleted paths between original and current.
Reverts dest object to src, calls customizer for each dest.path.
Returns all paths of the object.
Returns the object without excludedPaths.
Licensed under the MIT license.
Alexander Mac
| Back | FazBrowse Home | New Git URL |