@broofa/jsondiff
Advanced tools
Comparing version 1.1.1 to 1.1.2
21
index.js
@@ -55,3 +55,3 @@ // Reserved values | ||
function _patch(before, _diff, isMask = false) { | ||
function _patch(before, _diff, diffOnly = false) { | ||
if (_diff === DROP) return undefined; | ||
@@ -86,10 +86,15 @@ if (_diff === KEEP) _diff = before; | ||
let isEqual = true; | ||
const values = isMask ? {} : {...before}; | ||
const values = diffOnly ? {} : {...before}; | ||
for (const k in _diff) { | ||
if (_diff[k] === DROP && k in values) { | ||
delete values[k]; | ||
isEqual = false; | ||
if (_diff[k] === undefined || _diff[k] === DROP) { | ||
if (k in values) { | ||
delete values[k]; | ||
isEqual = false; | ||
} | ||
} else { | ||
values[k] = _patch(before[k], _diff[k], isMask); | ||
if (values[k] !== before[k]) isEqual = false; | ||
const val = _patch(before[k], _diff[k], diffOnly); | ||
if (val !== before[k]) { | ||
values[k] = val; | ||
isEqual = false; | ||
} | ||
} | ||
@@ -106,3 +111,3 @@ } | ||
for (let i = 0, l = _diff.length; i < l; i++) { | ||
const val = _patch(before[i], _diff[i], isMask); | ||
const val = _patch(before[i], _diff[i], diffOnly); | ||
@@ -109,0 +114,0 @@ if (val !== before[i]) isEqual = false; |
{ | ||
"name": "@broofa/jsondiff", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Pragmatic, intuitive diffing and patching of JSON objects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,2 @@ var assert = require('assert'); | ||
describe(__filename, async () => { | ||
/* | ||
it('Undefined', async () => { | ||
@@ -46,3 +45,2 @@ assert.equal(123, patch(undefined, 123)); | ||
}); | ||
*/ | ||
@@ -54,11 +52,8 @@ it('Object', async () => { | ||
/* | ||
assert.equal(a, patch(a, b)); | ||
assert.notEqual(c, patch(a, c)); // Has entries from both, so is new object | ||
assert.deepEqual(c, patch(a, c)); | ||
*/ | ||
assert.deepEqual({a: 1}, patch({a: 1, b: 2}, {a: 1, b: DROP})); | ||
}); | ||
/* | ||
it('Compound', async () => { | ||
@@ -98,6 +93,6 @@ const a = {bar: 111, a: {x: 111}, b: [1, {x:222}, {x: 222}]}; | ||
bar: 111, | ||
a: {x: 111}, | ||
// a: {x: 111}, | ||
b: [1, {x:222}, {x: 222}], | ||
c: 333, | ||
f: [1,2,5,6], | ||
// c: 333, | ||
// f: [1,2,5,6], | ||
ff: [1,2,6], | ||
@@ -128,3 +123,2 @@ }; | ||
}); | ||
*/ | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18872
333