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

Function validate

module/core.mjs:358–382  ·  view source on GitHub ↗
(sequence, document, externalValidator)

Source from the content-addressed store, hash-verified

356 * @returns {JsonPatchError|undefined}
357 */
358export function validate(sequence, document, externalValidator) {
359 try {
360 if (!Array.isArray(sequence)) {
361 throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
362 }
363 if (document) {
364 //clone document and sequence so that we can safely try applying operations
365 applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
366 }
367 else {
368 externalValidator = externalValidator || validator;
369 for (var i = 0; i < sequence.length; i++) {
370 externalValidator(sequence[i], i, document, undefined);
371 }
372 }
373 }
374 catch (e) {
375 if (e instanceof JsonPatchError) {
376 return e;
377 }
378 else {
379 throw e;
380 }
381 }
382}
383// based on https://github.com/epoberezkin/fast-deep-equal
384// MIT License
385// Copyright (c) 2017 Evgeny Poberezkin

Callers 1

validatorFunction · 0.70

Calls 2

_deepCloneFunction · 0.90
applyPatchFunction · 0.70

Tested by

no test coverage detected