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

Function applyPatch

module/core.mjs:263–282  ·  view source on GitHub ↗
(document, patch, validateOperation, mutateDocument, banPrototypeModifications)

Source from the content-addressed store, hash-verified

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

Callers 3

generateFunction · 0.90
generateFunction · 0.90
validateFunction · 0.70

Calls 2

_deepCloneFunction · 0.90
applyOperationFunction · 0.70

Tested by

no test coverage detected