Skip to content

Find the minimal patch from an original object to one or more updated version

Notifications You must be signed in to change notification settings

medhajjej11/object-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

object diff

Get the minimal patch to extend objectA with to transform it into objectB

Consider an object retrieved from a server:

{name: 'Peter',age: 26,height: 187,}

Now the user changes stuff using some frontend (e.g. a HTML form) and ends with:

{name: 'Peter',age: 27,height: 186,}

When he hits save, you only want to send off the changed parts to the server, to save bits (because you'r indeed a programmer), but also to avoid any unnecessary "merge conflicts" at the server.

Imagine two users changing the same object; if they did not change the exact same keys of the object, the last user won't erase the first user's changes - in a lot of cases, that's the expected behavior.

Install

npm install object-diff 

Usage

varobjectDiff=require('object-diff');vara={speed: 4,power: 54,height: undefined,level: 1,};varb={speed: 4,// unchangedpower: 22,// changedlevel: undefined,// changedweight: 10,// added};objectDiff(a,b);/*{ power: 22, level: undefined, weight: 10,}*/

License

MIT © src.agency / Thomas Jensen

About

Find the minimal patch from an original object to one or more updated version

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript100.0%