Skip to content

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

License

Notifications You must be signed in to change notification settings

mattphillips/deep-object-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deep Object Diff

A small library that will deep diff two JavaScript Objects, including nested structures of arrays and objects, and return the difference.

Useage:

const lhs = {
  foo: {
    bar: {
      a: [1, 2],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: [1], // updated (value deleted)
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // updated (value added)
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(diff(lhs, rhs));

/* logs:
{
  foo: {
    bar: {
      a: {
        '1': undefined
      },
      c: {
        '2': 'z'
      },
      d: 'Hello, world!',
      e: undefined
    }
  },
  buzz: 'fizz'
}
*/

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

Contributors 8