Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork96
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
License
mattphillips/deep-object-diff
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A small library that can deep diff two JavaScript Objects, including nested structures of arrays and objects.
yarn add deep-object-diff
npm i --save deep-object-diff
diff(originalObj, updatedObj)
returns the difference of the original and updated objectsaddedDiff(original, updatedObj)
returns only the values added to the updated objectdeletedDiff(original, updatedObj)
returns only the values deleted in the updated objectupdatedDiff(original, updatedObj)
returns only the values that have been changed in the updated objectdetailedDiff(original, updatedObj)
returns an object with the added, deleted and updated differences
import{diff,addedDiff,deletedDiff,updatedDiff,detailedDiff}from'deep-object-diff';
constlhs={foo:{bar:{a:['a','b'],b:2,c:['x','y'],e:100// deleted}},buzz:'world'};constrhs={foo:{bar:{a:['a'],// index 1 ('b') deletedb:2,// unchangedc:['x','y','z'],// 'z' addedd:'Hello, world!'// added}},buzz:'fizz'// updated};console.log(diff(lhs,rhs));// =>/*{ foo: { bar: { a: { '1': undefined }, c: { '2': 'z' }, d: 'Hello, world!', e: undefined } }, buzz: 'fizz'}*/
constlhs={foo:{bar:{a:['a','b'],b:2,c:['x','y'],e:100// deleted}},buzz:'world'};constrhs={foo:{bar:{a:['a'],// index 1 ('b') deletedb:2,// unchangedc:['x','y','z'],// 'z' addedd:'Hello, world!'// added}},buzz:'fizz'// updated};console.log(addedDiff(lhs,rhs));/*{ foo: { bar: { c: { '2': 'z' }, d: 'Hello, world!' } }}*/
constlhs={foo:{bar:{a:['a','b'],b:2,c:['x','y'],e:100// deleted}},buzz:'world'};constrhs={foo:{bar:{a:['a'],// index 1 ('b') deletedb:2,// unchangedc:['x','y','z'],// 'z' addedd:'Hello, world!'// added}},buzz:'fizz'// updated};console.log(deletedDiff(lhs,rhs));/*{ foo: { bar: { a: { '1': undefined }, e: undefined } }}*/
constlhs={foo:{bar:{a:['a','b'],b:2,c:['x','y'],e:100// deleted}},buzz:'world'};constrhs={foo:{bar:{a:['a'],// index 1 ('b') deletedb:2,// unchangedc:['x','y','z'],// 'z' addedd:'Hello, world!'// added}},buzz:'fizz'// updated};console.log(updatedDiff(lhs,rhs));/*{ buzz: 'fizz'}*/
constlhs={foo:{bar:{a:['a','b'],b:2,c:['x','y'],e:100// deleted}},buzz:'world'};constrhs={foo:{bar:{a:['a'],// index 1 ('b') deletedb:2,// unchangedc:['x','y','z'],// 'z' addedd:'Hello, world!'// added}},buzz:'fizz'// updated};console.log(detailedDiff(lhs,rhs));/*{ added: { foo: { bar: { c: { '2': 'z' }, d: 'Hello, world!' } } }, deleted: { foo: { bar: { a: { '1': undefined }, e: undefined } } }, updated: { buzz: 'fizz' }}*/
MIT
About
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.