@apigames/json
Advanced tools
Comparing version 1.0.23 to 1.0.24
@@ -6,3 +6,3 @@ { | ||
"license": "UNLICENSED", | ||
"version": "1.0.23", | ||
"version": "1.0.24", | ||
"main": "index.js", | ||
@@ -9,0 +9,0 @@ "scripts": { |
@@ -84,5 +84,35 @@ const deepEqual = require("deep-equal"), | ||
function clone(value) { | ||
function RedactUndefinedValues(document) { | ||
if (isArray(document)) { | ||
for (let index = document.length - 1; index >= 0 ; index--) { | ||
if (isDefined(document[index])) { | ||
RedactUndefinedValues(document[index]); | ||
} else { | ||
document = document.splice(index, 1); | ||
} | ||
} | ||
} else { | ||
if (isObject(document)) { | ||
for (let key in document) { | ||
if (document.hasOwnProperty(key)) { | ||
if (isDefined(document[key])) { | ||
RedactUndefinedValues(document[key]); | ||
} else { | ||
delete document[key] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function clone(value, redactUndefinedValues = true) { | ||
if (value) { | ||
return clonedeep(value); | ||
const clonedDocument = clonedeep(value); | ||
if (redactUndefinedValues) { | ||
RedactUndefinedValues(clonedDocument); | ||
} | ||
return clonedDocument; | ||
} | ||
@@ -89,0 +119,0 @@ } |
28169
622