Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️

License

NotificationsYou must be signed in to change notification settings

mattphillips/deep-object-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

❄️

Deep diff two JavaScript Objects


Build StatusCode coverageversiondownloadsMIT LicensePRs Welcome

A small library that can deep diff two JavaScript Objects, including nested structures of arrays and objects.

Installation

yarn add deep-object-diff

npm i --save deep-object-diff

Functions available:

Importing

import{diff,addedDiff,deletedDiff,updatedDiff,detailedDiff}from'deep-object-diff';

Usage:

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'}*/

addedDiff:

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!'    }  }}*/

deletedDiff:

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    }  }}*/

updatedDiff:

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'}*/

detailedDiff:

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'  }}*/

License

MIT

About

Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp