MCPcopy Create free account
hub / github.com/Starcounter-Jack/JSON-Patch / applyPatch

Function applyPatch

commonjs/core.js:266–285  ·  view source on GitHub ↗

* Apply a full JSON Patch array on a JSON document. * Returns the {newDocument, result} of the patch. * It modifies the `document` object and `patch` - it gets the values by reference. * If you would like to avoid touching your values, clone them: * `jsonpatch.applyPatch(document, jsonpatch._dee

(document, patch, validateOperation, mutateDocument, banPrototypeModifications)

Source from the content-addressed store, hash-verified

264 * @return An array of `{newDocument, result}` after the patch
265 */
266function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
267 if (mutateDocument === void 0) { mutateDocument = true; }
268 if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
269 if (validateOperation) {
270 if (!Array.isArray(patch)) {
271 throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
272 }
273 }
274 if (!mutateDocument) {
275 document = helpers_js_1._deepClone(document);
276 }
277 var results = new Array(patch.length);
278 for (var i = 0, length_1 = patch.length; i < length_1; i++) {
279 // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
280 results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
281 document = results[i].newDocument; // in case root was replaced
282 }
283 results.newDocument = document;
284 return results;
285}
286exports.applyPatch = applyPatch;
287/**
288 * Apply a single JSON Patch Operation on a JSON document.

Callers 1

validateFunction · 0.70

Calls 1

applyOperationFunction · 0.70

Tested by

no test coverage detected