@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
15 lines (12 loc) • 559 B
JavaScript
import { clone } from '@winglet/common-utils/object';
import { applySinglePatch } from './applySinglePatch.mjs';
const applyPatch = (source, patches, options) => {
const strict = options?.strict ?? false;
const immutable = options?.immutable ?? true;
const protectPrototype = options?.protectPrototype ?? true;
let result = immutable ? clone(source) : source;
for (let i = 0, l = patches.length; i < l; i++)
result = applySinglePatch(result, patches[i], i, strict, protectPrototype);
return result;
};
export { applyPatch };