UNPKG

json8-patch

Version:
36 lines (28 loc) 755 B
"use strict"; module.exports = function valid(patch) { if (!Array.isArray(patch)) return false; for (let i = 0, l = patch.length; i < l; i++) { const op = patch[i]; if (typeof op !== "object" || op === null || Array.isArray(op)) return false; if (typeof op.path !== "string") return false; const operation = op.op; if (typeof op.op !== "string") return false; switch (operation) { case "add": case "replace": case "test": if (op.value === undefined) return false; break; case "move": case "copy": if (typeof op.from !== "string") return false; break; case "remove": break; default: return false; } } return true; };