* 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)
| 264 | * @return An array of `{newDocument, result}` after the patch |
| 265 | */ |
| 266 | function 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 | } |
| 286 | exports.applyPatch = applyPatch; |
| 287 | /** |
| 288 | * Apply a single JSON Patch Operation on a JSON document. |
no test coverage detected