deep-object-diff
❄️
Deep diff two JavaScript Objects
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
ES6 / Babel:
import { diff, addedDiff, deletedDiff, updatedDiff, detailedDiff } from 'deep-object-diff';
ES5:
const { diff, addedDiff, deletedDiff, detailedDiff, updatedDiff } = require("deep-object-diff");
const diff = require("deep-object-diff").diff;
const addedDiff = require("deep-object-diff").addedDiff;
const deletedDiff = require("deep-object-diff").deletedDiff;
const detailedDiff = require("deep-object-diff").detailedDiff;
const updatedDiff = require("deep-object-diff").updatedDiff;
Usage:
diff
:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'],
b: 2,
c: ['x', 'y', 'z'],
d: 'Hello, world!'
}
},
buzz: 'fizz'
};
console.log(diff(lhs, rhs));
addedDiff
:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'],
b: 2,
c: ['x', 'y', 'z'],
d: 'Hello, world!'
}
},
buzz: 'fizz'
};
console.log(addedDiff(lhs, rhs));
deletedDiff
:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'],
b: 2,
c: ['x', 'y', 'z'],
d: 'Hello, world!'
}
},
buzz: 'fizz'
};
console.log(deletedDiff(lhs, rhs));
updatedDiff
:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'],
b: 2,
c: ['x', 'y', 'z'],
d: 'Hello, world!'
}
},
buzz: 'fizz'
};
console.log(updatedDiff(lhs, rhs));
detailedDiff
:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'],
b: 2,
c: ['x', 'y', 'z'],
d: 'Hello, world!'
}
},
buzz: 'fizz'
};
console.log(detailedDiff(lhs, rhs));
License
MIT