@winglet/json
Version:
TypeScript library for safe and efficient JSON data manipulation with RFC 6901 (JSON Pointer) and RFC 6902 (JSON Patch) compliance, featuring prototype pollution protection and immutable operations
21 lines (17 loc) • 521 B
JavaScript
;
var filter = require('@winglet/common-utils/filter');
const mergePatchRecursive = (source = {}, patch) => {
if (patch === undefined)
return source;
if (!filter.isPlainObject(patch))
return patch;
for (const key in patch) {
const value = patch[key];
if (value === null)
delete source[key];
else
source[key] = mergePatchRecursive(source[key], value);
}
return source;
};
exports.mergePatchRecursive = mergePatchRecursive;