@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
17 lines (13 loc) • 607 B
JavaScript
;
var object = require('@winglet/common-utils/object');
var applySinglePatch = require('./applySinglePatch.cjs');
const applyPatch = (source, patches, options) => {
const strict = options?.strict ?? false;
const immutable = options?.immutable ?? true;
const protectPrototype = options?.protectPrototype ?? true;
let result = immutable ? object.clone(source) : source;
for (let i = 0, l = patches.length; i < l; i++)
result = applySinglePatch.applySinglePatch(result, patches[i], i, strict, protectPrototype);
return result;
};
exports.applyPatch = applyPatch;