compare-objects
v0.0.4
Published
Compare Objects
Downloads
4
Readme
compare-objects
Compare Objects
installation
npm install compare-objects --save
usage
var compare = require('compare-objects')
var objA = {
a: 1,
b: 2,
c: {
d: 3
},
g: 6
}
var objB = {
a: 1,
b: 3,
c: {
e: 4
}
f: 5
}
compare(objA, objB, function (key, value, oldValue) {
if (oldValue === undefined) {
console.log('added', key, value)
return
}
if (value !== undefined) {
if (value === oldValue) {
console.log('unchanged', key, value, oldValue)
} else {
console.log('update', key, value, oldValue)
}
return
}
console.log('removed', key, oldValue)
})
/*
Prints:
unchanged, a, 1, 1
update, b, 3, 2
update, c, {e: 4}, {d: 3}
added, f, 5
removed, g, 6
*/
performance
Just some simple performance tests..
MacBook Pro 15" (early 2011 • 2.2 GHz Intel Core i7 • 8 Gt, 1333 MHz DDR3)
shallow compare x 464,421 ops/sec ±1.29% (89 runs sampled)
deep compare x 283,155 ops/sec ±2.06% (89 runs sampled)