Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-json-patch

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-patch - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

4

dist/json-patch-duplex.min.js
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester
* MIT license
*/
var jsonpatch;if(function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(x(a)){if(!x(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;d<e;d++)if(!b(a[d],c[d]))return!1;return!0}for(var f=y(a),g=y(c),h=0;h<f.length;h++){var i=f[h];if(!b(a[i],c[i]))return!1;var j=g.indexOf(i);j>=0&&g.splice(j,1)}for(var k=0;k<g.length;k++){var l=g[k];if(!b(a[l],c[l]))return!1}return!0;default:return!1}}function c(a){for(var b=0,c=B.length;b<c;b++)if(B[b].obj===a)return B[b]}function d(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function e(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function f(a,b){b.unobserve()}function g(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function h(a,b){var f,h=[],j=c(a);if(j?f=d(j,b):(j=new C(a),B.push(j)),f)return f;if(f={},j.value=g(a),b){f.callback=b,f.next=null;var k=function(){i(f)},l=function(){clearTimeout(f.next),f.next=setTimeout(k)};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mouseup",l),window.addEventListener("keyup",l),window.addEventListener("mousedown",l),window.addEventListener("keydown",l),window.addEventListener("change",l)):(document.documentElement.attachEvent("onmouseup",l),document.documentElement.attachEvent("onkeyup",l),document.documentElement.attachEvent("onmousedown",l),document.documentElement.attachEvent("onkeydown",l),document.documentElement.attachEvent("onchange",l)))}return f.patches=h,f.object=a,f.unobserve=function(){i(f),clearTimeout(f.next),e(j,f),"undefined"!=typeof window&&(window.removeEventListener?(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l),window.removeEventListener("mousedown",l),window.removeEventListener("keydown",l)):(document.documentElement.detachEvent("onmouseup",l),document.documentElement.detachEvent("onkeyup",l),document.documentElement.detachEvent("onmousedown",l),document.documentElement.detachEvent("onkeydown",l)))},j.observers.push(new D(b,f)),f}function i(a){for(var b,c=0,d=B.length;c<d;c++)if(B[c].obj===a.object){b=B[c];break}j(b.value,a.object,a.patches,""),a.patches.length&&p(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function j(a,b,c,d){if(b!==a){"function"==typeof b.toJSON&&(b=b.toJSON());for(var e=y(b),f=y(a),h=!1,i=f.length-1;i>=0;i--){var k=f[i],m=a[k];if(!b.hasOwnProperty(k)||void 0===b[k]&&void 0!==m&&!1===x(b))c.push({op:"remove",path:d+"/"+l(k)}),h=!0;else{var n=b[k];"object"==typeof m&&null!=m&&"object"==typeof n&&null!=n?j(m,n,c,d+"/"+l(k)):m!==n&&(!0,c.push({op:"replace",path:d+"/"+l(k),value:g(n)}))}}if(h||e.length!=f.length)for(var i=0;i<e.length;i++){var k=e[i];a.hasOwnProperty(k)||void 0===b[k]||c.push({op:"add",path:d+"/"+l(k),value:g(b[k])})}}}function k(a){for(var b,c=0,d=a.length;c<d;){b=a.charCodeAt(c);{if(!(b>=48&&b<=57))return!1;c++}}return!0}function l(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function m(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function n(a,b){var c={op:"_get",path:b};return o(a,c),c.value}function o(a,c,d,e){void 0===d&&(d=!1),void 0===e&&(e=!0),d&&("function"==typeof d?d(c,0,a,c.path):u(c,0));var f={newDocument:a};if(""===c.path){if("add"===c.op)return f.newDocument=c.value,f;if("replace"===c.op)return f.newDocument=c.value,f.removed=a,f;if("move"===c.op||"copy"===c.op)return f.newDocument=n(a,c.from),"move"===c.op&&(f.removed=a),f;if("test"===c.op){if(f.test=b(a,c.value),!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f.newDocument=a,f}if("remove"===c.op)return f.removed=a,f.newDocument=null,f;if(d)throw new E("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",0,c,a);return f}e||(a=g(a));var h=c.path||"",i=h.split("/"),j=a,l=1,o=i.length,p=void 0,q=void 0,r=void 0;for(r="function"==typeof d?d:u;;){if(q=i[l],d&&void 0===p&&(void 0===j[q]?p=i.slice(0,l).join("/"):l==o-1&&(p=c.path),void 0!==p&&r(c,0,a,p)),l++,x(j)){if("-"===q)q=j.length;else{if(d&&!k(q))throw new E("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",0,c.path,c);q=~~q}if(l>=o){if(d&&"add"===c.op&&q>j.length)throw new E("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",0,c.path,c);if(f=A[c.op].call(c,j,q,a),!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f}}else if(q&&-1!=q.indexOf("~")&&(q=m(q)),l>=o){if(f=z[c.op].call(c,j,q,a),!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f}j=j[q]}}function p(a,b,c){for(var d=new Array(b.length),e=0,f=b.length;e<f;e++)d[e]=o(a,b[e],c),a=d[e].newDocument;return d.newDocument=a,d}function q(a,b,c){console.warn("jsonpatch.apply is deprecated, please use `applyPatch` for applying patch sequences, or `applyOperation` to apply individual operations.");for(var d=new Array(b.length),e=function(e,f){if(""==b[e].path&&"remove"!=b[e].op&&"test"!=b[e].op){var h;"replace"!=b[e].op&&"move"!=b[e].op||(d[e]=g(a)),"copy"!=b[e].op&&"move"!=b[e].op||(h=n(a,b[e].from)),"replace"!=b[e].op&&"add"!=b[e].op||(h=b[e].value),Object.keys(a).forEach(function(b){return delete a[b]}),Object.keys(h).forEach(function(b){return a[b]=h[b]})}else d[e]=o(a,b[e],c),d[e]=d[e].removed||d[e].test},f=0,h=b.length;f<h;f++)e(f,h);return d}function r(a,b){var c=o(a,b);if(!1===c.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,b,a);return c.newDocument}function s(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)}function t(a){if(void 0===a)return!0;if(a)if(x(a)){for(var b=0,c=a.length;b<c;b++)if(t(a[b]))return!0}else if("object"==typeof a)for(var d=y(a),e=d.length,b=0;b<e;b++)if(t(a[d[b]]))return!0;return!1}function u(a,b,c,d){if("object"!=typeof a||null===a||x(a))throw new E("Operation is not an object","OPERATION_NOT_AN_OBJECT",b,a,c);if(!z[a.op])throw new E("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",b,a,c);if("string"!=typeof a.path)throw new E("Operation `path` property is not a string","OPERATION_PATH_INVALID",b,a,c);if(0!==a.path.indexOf("/")&&a.path.length>0)throw new E('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",b,a,c);if(("move"===a.op||"copy"===a.op)&&"string"!=typeof a.from)throw new E("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&void 0===a.value)throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&t(a.value))throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",b,a,c);if(c)if("add"==a.op){var e=a.path.split("/").length,f=d.split("/").length;if(e!==f+1&&e!==f)throw new E("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",b,a,c)}else if("replace"===a.op||"remove"===a.op||"_get"===a.op){if(a.path!==d)throw new E("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",b,a,c)}else if("move"===a.op||"copy"===a.op){var g={op:"_get",path:a.from,value:void 0},h=v([g],c);if(h&&"OPERATION_PATH_UNRESOLVABLE"===h.name)throw new E("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",b,a,c)}}function v(a,b,c){try{if(!x(a))throw new E("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),p(b,a,c||!0);else{c=c||u;for(var d=0;d<a.length;d++)c(a[d],d,b,void 0)}}catch(a){if(a instanceof E)return a;throw a}}function w(a,b){var c=[];return j(a,b,c,""),c}var x,y=function(a){if(x(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},z={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,c){var d=n(c,this.path);d&&(d=g(d));var e=o(c,{op:"remove",path:this.from}).removed;return o(c,{op:"add",path:this.path,value:e}),{newDocument:c,removed:d}},copy:function(a,b,c){var d=n(c,this.from);return o(c,{op:"add",path:this.path,value:d}),{newDocument:c}},test:function(a,c,d){return{newDocument:d,test:b(a[c],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},A={add:function(a,b,c){return a.splice(b,0,this.value),{newDocument:c,index:b}},remove:function(a,b,c){return{newDocument:c,removed:a.splice(b,1)[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:z.move,copy:z.copy,test:z.test,_get:z._get};x=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length};var B=[],C=function(){function a(a){this.observers=[],this.obj=a}return a}(),D=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=f,a.observe=h,a.generate=i;var x;x=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.escapePathComponent=l,a.unescapePathComponent=m,a.getValueByPointer=n,a.applyOperation=o,a.applyPatch=p,a.apply=q,a.applyReducer=r;var E=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return s(b,a),b}(Error);a.JsonPatchError=E,a.validator=u,a.validate=v,a.compare=w}(jsonpatch||(jsonpatch={})),void 0!==exports)exports.apply=jsonpatch.apply,exports.applyPatch=jsonpatch.applyPatch,exports.applyOperation=jsonpatch.applyOperation,exports.applyReducer=jsonpatch.applyReducer,exports.getValueByPointer=jsonpatch.getValueByPointer,exports.escapePathComponent=jsonpatch.escapePathComponent,exports.unescapePathComponent=jsonpatch.unescapePathComponent,exports.observe=jsonpatch.observe,exports.unobserve=jsonpatch.unobserve,exports.generate=jsonpatch.generate,exports.compare=jsonpatch.compare,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError;else var exports={},isBrowser=!0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=jsonpatch,isBrowser&&(exports=void 0);
var jsonpatch;if(function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(x(a)){if(!x(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;d<e;d++)if(!b(a[d],c[d]))return!1;return!0}for(var f=y(a),g=y(c),h=0;h<f.length;h++){var i=f[h];if(!b(a[i],c[i]))return!1;var j=g.indexOf(i);j>=0&&g.splice(j,1)}for(var k=0;k<g.length;k++){var l=g[k];if(!b(a[l],c[l]))return!1}return!0;default:return!1}}function c(a){for(var b=0,c=B.length;b<c;b++)if(B[b].obj===a)return B[b]}function d(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function e(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function f(a,b){b.unobserve()}function g(a,b){var f,g=[],i=c(a);if(i?f=d(i,b):(i=new C(a),B.push(i)),f)return f;if(f={},i.value=k(a),b){f.callback=b,f.next=null;var j=function(){h(f)},l=function(){clearTimeout(f.next),f.next=setTimeout(j)};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mouseup",l),window.addEventListener("keyup",l),window.addEventListener("mousedown",l),window.addEventListener("keydown",l),window.addEventListener("change",l)):(document.documentElement.attachEvent("onmouseup",l),document.documentElement.attachEvent("onkeyup",l),document.documentElement.attachEvent("onmousedown",l),document.documentElement.attachEvent("onkeydown",l),document.documentElement.attachEvent("onchange",l)))}return f.patches=g,f.object=a,f.unobserve=function(){h(f),clearTimeout(f.next),e(i,f),"undefined"!=typeof window&&(window.removeEventListener?(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l),window.removeEventListener("mousedown",l),window.removeEventListener("keydown",l)):(document.documentElement.detachEvent("onmouseup",l),document.documentElement.detachEvent("onkeyup",l),document.documentElement.detachEvent("onmousedown",l),document.documentElement.detachEvent("onkeydown",l)))},i.observers.push(new D(b,f)),f}function h(a){for(var b,c=0,d=B.length;c<d;c++)if(B[c].obj===a.object){b=B[c];break}i(b.value,a.object,a.patches,""),a.patches.length&&p(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function i(a,b,c,d){if(b!==a){"function"==typeof b.toJSON&&(b=b.toJSON());for(var e=y(b),f=y(a),g=!1,h=f.length-1;h>=0;h--){var j=f[h],m=a[j];if(!b.hasOwnProperty(j)||void 0===b[j]&&void 0!==m&&!1===x(b))c.push({op:"remove",path:d+"/"+l(j)}),g=!0;else{var n=b[j];"object"==typeof m&&null!=m&&"object"==typeof n&&null!=n?i(m,n,c,d+"/"+l(j)):m!==n&&(!0,c.push({op:"replace",path:d+"/"+l(j),value:k(n)}))}}if(g||e.length!=f.length)for(var h=0;h<e.length;h++){var j=e[h];a.hasOwnProperty(j)||void 0===b[j]||c.push({op:"add",path:d+"/"+l(j),value:k(b[j])})}}}function j(a){for(var b,c=0,d=a.length;c<d;){b=a.charCodeAt(c);{if(!(b>=48&&b<=57))return!1;c++}}return!0}function k(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function l(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function m(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function n(a,b){if(""==b)return a;var c={op:"_get",path:b};return o(a,c),c.value}function o(a,c,d,e){if(void 0===d&&(d=!1),void 0===e&&(e=!0),d&&("function"==typeof d?d(c,0,a,c.path):u(c,0)),""===c.path){var f={newDocument:a};if("add"===c.op)return f.newDocument=c.value,f;if("replace"===c.op)return f.newDocument=c.value,f.removed=a,f;if("move"===c.op||"copy"===c.op)return f.newDocument=n(a,c.from),"move"===c.op&&(f.removed=a),f;if("test"===c.op){if(f.test=b(a,c.value),!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f.newDocument=a,f}if("remove"===c.op)return f.removed=a,f.newDocument=null,f;if("_get"===c.op)return c.value=a,f;if(d)throw new E("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",0,c,a);return f}e||(a=k(a));var g=c.path||"",h=g.split("/"),i=a,l=1,o=h.length,p=void 0,q=void 0,r=void 0;for(r="function"==typeof d?d:u;;){if(q=h[l],d&&void 0===p&&(void 0===i[q]?p=h.slice(0,l).join("/"):l==o-1&&(p=c.path),void 0!==p&&r(c,0,a,p)),l++,x(i)){if("-"===q)q=i.length;else{if(d&&!j(q))throw new E("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",0,c.path,c);q=~~q}if(l>=o){if(d&&"add"===c.op&&q>i.length)throw new E("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",0,c.path,c);var f=A[c.op].call(c,i,q,a);if(!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f}}else if(q&&-1!=q.indexOf("~")&&(q=m(q)),l>=o){var f=z[c.op].call(c,i,q,a);if(!1===f.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,c,a);return f}i=i[q]}}function p(a,b,c){for(var d=new Array(b.length),e=0,f=b.length;e<f;e++)d[e]=o(a,b[e],c),a=d[e].newDocument;return d.newDocument=a,d}function q(a,b,c){console.warn("jsonpatch.apply is deprecated, please use `applyPatch` for applying patch sequences, or `applyOperation` to apply individual operations.");for(var d=new Array(b.length),e=function(e,f){if(""==b[e].path&&"remove"!=b[e].op&&"test"!=b[e].op){var g;"replace"!=b[e].op&&"move"!=b[e].op||(d[e]=k(a)),"copy"!=b[e].op&&"move"!=b[e].op||(g=n(a,b[e].from)),"replace"!=b[e].op&&"add"!=b[e].op||(g=b[e].value),Object.keys(a).forEach(function(b){return delete a[b]}),Object.keys(g).forEach(function(b){return a[b]=g[b]})}else d[e]=o(a,b[e],c),d[e]=d[e].removed||d[e].test},f=0,g=b.length;f<g;f++)e(f,g);return d}function r(a,b){var c=o(a,b);if(!1===c.test)throw new E("Test operation failed","TEST_OPERATION_FAILED",0,b,a);return c.newDocument}function s(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)}function t(a){if(void 0===a)return!0;if(a)if(x(a)){for(var b=0,c=a.length;b<c;b++)if(t(a[b]))return!0}else if("object"==typeof a)for(var d=y(a),e=d.length,b=0;b<e;b++)if(t(a[d[b]]))return!0;return!1}function u(a,b,c,d){if("object"!=typeof a||null===a||x(a))throw new E("Operation is not an object","OPERATION_NOT_AN_OBJECT",b,a,c);if(!z[a.op])throw new E("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",b,a,c);if("string"!=typeof a.path)throw new E("Operation `path` property is not a string","OPERATION_PATH_INVALID",b,a,c);if(0!==a.path.indexOf("/")&&a.path.length>0)throw new E('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",b,a,c);if(("move"===a.op||"copy"===a.op)&&"string"!=typeof a.from)throw new E("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&void 0===a.value)throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&t(a.value))throw new E("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",b,a,c);if(c)if("add"==a.op){var e=a.path.split("/").length,f=d.split("/").length;if(e!==f+1&&e!==f)throw new E("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",b,a,c)}else if("replace"===a.op||"remove"===a.op||"_get"===a.op){if(a.path!==d)throw new E("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",b,a,c)}else if("move"===a.op||"copy"===a.op){var g={op:"_get",path:a.from,value:void 0},h=v([g],c);if(h&&"OPERATION_PATH_UNRESOLVABLE"===h.name)throw new E("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",b,a,c)}}function v(a,b,c){try{if(!x(a))throw new E("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)p(k(b),k(a),c||!0);else{c=c||u;for(var d=0;d<a.length;d++)c(a[d],d,b,void 0)}}catch(a){if(a instanceof E)return a;throw a}}function w(a,b){var c=[];return i(a,b,c,""),c}var x,y=function(a){if(x(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},z={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,c){var d=n(c,this.path);d&&(d=k(d));var e=o(c,{op:"remove",path:this.from}).removed;return o(c,{op:"add",path:this.path,value:e}),{newDocument:c,removed:d}},copy:function(a,b,c){var d=n(c,this.from);return o(c,{op:"add",path:this.path,value:k(d)}),{newDocument:c}},test:function(a,c,d){return{newDocument:d,test:b(a[c],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},A={add:function(a,b,c){return a.splice(b,0,this.value),{newDocument:c,index:b}},remove:function(a,b,c){return{newDocument:c,removed:a.splice(b,1)[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:z.move,copy:z.copy,test:z.test,_get:z._get};x=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length};var B=[],C=function(){function a(a){this.observers=[],this.obj=a}return a}(),D=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=f,a.observe=g,a.generate=h;var x;x=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.deepClone=k,a.escapePathComponent=l,a.unescapePathComponent=m,a.getValueByPointer=n,a.applyOperation=o,a.applyPatch=p,a.apply=q,a.applyReducer=r;var E=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return s(b,a),b}(Error);a.JsonPatchError=E,a.validator=u,a.validate=v,a.compare=w}(jsonpatch||(jsonpatch={})),void 0!==exports)exports.apply=jsonpatch.apply,exports.applyPatch=jsonpatch.applyPatch,exports.applyOperation=jsonpatch.applyOperation,exports.applyReducer=jsonpatch.applyReducer,exports.getValueByPointer=jsonpatch.getValueByPointer,exports.deepClone=jsonpatch.deepClone,exports.escapePathComponent=jsonpatch.escapePathComponent,exports.unescapePathComponent=jsonpatch.unescapePathComponent,exports.observe=jsonpatch.observe,exports.unobserve=jsonpatch.unobserve,exports.generate=jsonpatch.generate,exports.compare=jsonpatch.compare,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError;else var exports={},isBrowser=!0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=jsonpatch,isBrowser&&(exports=void 0);
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester
* MIT license
*/
var jsonpatch;if(function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(p(a)){if(!p(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;d<e;d++)if(!b(a[d],c[d]))return!1;return!0}for(var f=q(a),g=q(c),h=0;h<f.length;h++){var i=f[h];if(!b(a[i],c[i]))return!1;var j=g.indexOf(i);j>=0&&g.splice(j,1)}for(var k=0;k<g.length;k++){var l=g[k];if(!b(a[l],c[l]))return!1}return!0;default:return!1}}function c(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function d(a){for(var b,c=0,d=a.length;c<d;){b=a.charCodeAt(c);{if(!(b>=48&&b<=57))return!1;c++}}return!0}function e(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function f(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function g(a,b){var c={op:"_get",path:b};return h(a,c),c.value}function h(a,e,h,i){if(void 0===h&&(h=!1),void 0===i&&(i=!0),h&&("function"==typeof h?h(e,0,a,e.path):n(e,0)),""===e.path){var j={newDocument:a};if("add"===e.op)return j.newDocument=e.value,j;if("replace"===e.op)return j.newDocument=e.value,j.removed=a,j;if("move"===e.op||"copy"===e.op)return j.newDocument=g(a,e.from),"move"===e.op&&(j.removed=a),j;if("test"===e.op){if(j.test=b(a,e.value),!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j.newDocument=a,j}if("remove"===e.op)return j.removed=a,j.newDocument=null,j;if(h)throw new t("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",0,e,a);return j}i||(a=c(a));var k=e.path||"",l=k.split("/"),m=a,o=1,q=l.length,u=void 0,v=void 0,w=void 0;for(w="function"==typeof h?h:n;;){if(v=l[o],h&&void 0===u&&(void 0===m[v]?u=l.slice(0,o).join("/"):o==q-1&&(u=e.path),void 0!==u&&w(e,0,a,u)),o++,p(m)){if("-"===v)v=m.length;else{if(h&&!d(v))throw new t("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",0,e.path,e);v=~~v}if(o>=q){if(h&&"add"===e.op&&v>m.length)throw new t("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",0,e.path,e);var j=s[e.op].call(e,m,v,a);if(!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j}}else if(v&&-1!=v.indexOf("~")&&(v=f(v)),o>=q){var j=r[e.op].call(e,m,v,a);if(!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j}m=m[v]}}function i(a,b,c){for(var d=new Array(b.length),e=0,f=b.length;e<f;e++)d[e]=h(a,b[e],c),a=d[e].newDocument;return d.newDocument=a,d}function j(a,b,d){console.warn("jsonpatch.apply is deprecated, please use `applyPatch` for applying patch sequences, or `applyOperation` to apply individual operations.");for(var e=new Array(b.length),f=function(f,i){if(""==b[f].path&&"remove"!=b[f].op&&"test"!=b[f].op){var j;"replace"!=b[f].op&&"move"!=b[f].op||(e[f]=c(a)),"copy"!=b[f].op&&"move"!=b[f].op||(j=g(a,b[f].from)),"replace"!=b[f].op&&"add"!=b[f].op||(j=b[f].value),Object.keys(a).forEach(function(b){return delete a[b]}),Object.keys(j).forEach(function(b){return a[b]=j[b]})}else e[f]=h(a,b[f],d),e[f]=e[f].removed||e[f].test},i=0,j=b.length;i<j;i++)f(i,j);return e}function k(a,b){var c=h(a,b);if(!1===c.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,b,a);return c.newDocument}function l(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)}function m(a){if(void 0===a)return!0;if(a)if(p(a)){for(var b=0,c=a.length;b<c;b++)if(m(a[b]))return!0}else if("object"==typeof a)for(var d=q(a),e=d.length,b=0;b<e;b++)if(m(a[d[b]]))return!0;return!1}function n(a,b,c,d){if("object"!=typeof a||null===a||p(a))throw new t("Operation is not an object","OPERATION_NOT_AN_OBJECT",b,a,c);if(!r[a.op])throw new t("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",b,a,c);if("string"!=typeof a.path)throw new t("Operation `path` property is not a string","OPERATION_PATH_INVALID",b,a,c);if(0!==a.path.indexOf("/")&&a.path.length>0)throw new t('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",b,a,c);if(("move"===a.op||"copy"===a.op)&&"string"!=typeof a.from)throw new t("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&void 0===a.value)throw new t("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&m(a.value))throw new t("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",b,a,c);if(c)if("add"==a.op){var e=a.path.split("/").length,f=d.split("/").length;if(e!==f+1&&e!==f)throw new t("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",b,a,c)}else if("replace"===a.op||"remove"===a.op||"_get"===a.op){if(a.path!==d)throw new t("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",b,a,c)}else if("move"===a.op||"copy"===a.op){var g={op:"_get",path:a.from,value:void 0},h=o([g],c);if(h&&"OPERATION_PATH_UNRESOLVABLE"===h.name)throw new t("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",b,a,c)}}function o(a,b,c){try{if(!p(a))throw new t("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),i(b,a,c||!0);else{c=c||n;for(var d=0;d<a.length;d++)c(a[d],d,b,void 0)}}catch(a){if(a instanceof t)return a;throw a}}var p,q=function(a){if(p(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},r={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,d){var e=g(d,this.path);e&&(e=c(e));var f=h(d,{op:"remove",path:this.from}).removed;return h(d,{op:"add",path:this.path,value:f}),{newDocument:d,removed:e}},copy:function(a,b,c){var d=g(c,this.from);return h(c,{op:"add",path:this.path,value:d}),{newDocument:c}},test:function(a,c,d){return{newDocument:d,test:b(a[c],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},s={add:function(a,b,c){return a.splice(b,0,this.value),{newDocument:c,index:b}},remove:function(a,b,c){return{newDocument:c,removed:a.splice(b,1)[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:r.move,copy:r.copy,test:r.test,_get:r._get};p=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.escapePathComponent=e,a.unescapePathComponent=f,a.getValueByPointer=g,a.applyOperation=h,a.applyPatch=i,a.apply=j,a.applyReducer=k;var t=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return l(b,a),b}(Error);a.JsonPatchError=t,a.validator=n,a.validate=o}(jsonpatch||(jsonpatch={})),void 0!==exports)exports.apply=jsonpatch.apply,exports.applyPatch=jsonpatch.applyPatch,exports.applyOperation=jsonpatch.applyOperation,exports.applyReducer=jsonpatch.applyReducer,exports.getValueByPointer=jsonpatch.getValueByPointer,exports.escapePathComponent=jsonpatch.escapePathComponent,exports.unescapePathComponent=jsonpatch.unescapePathComponent,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError;else var exports={},isBrowser=!0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=jsonpatch,isBrowser&&(exports=void 0);
var jsonpatch;if(function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(p(a)){if(!p(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;d<e;d++)if(!b(a[d],c[d]))return!1;return!0}for(var f=q(a),g=q(c),h=0;h<f.length;h++){var i=f[h];if(!b(a[i],c[i]))return!1;var j=g.indexOf(i);j>=0&&g.splice(j,1)}for(var k=0;k<g.length;k++){var l=g[k];if(!b(a[l],c[l]))return!1}return!0;default:return!1}}function c(a){for(var b,c=0,d=a.length;c<d;){b=a.charCodeAt(c);{if(!(b>=48&&b<=57))return!1;c++}}return!0}function d(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function e(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function f(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function g(a,b){if(""==b)return a;var c={op:"_get",path:b};return h(a,c),c.value}function h(a,e,h,i){if(void 0===h&&(h=!1),void 0===i&&(i=!0),h&&("function"==typeof h?h(e,0,a,e.path):n(e,0)),""===e.path){var j={newDocument:a};if("add"===e.op)return j.newDocument=e.value,j;if("replace"===e.op)return j.newDocument=e.value,j.removed=a,j;if("move"===e.op||"copy"===e.op)return j.newDocument=g(a,e.from),"move"===e.op&&(j.removed=a),j;if("test"===e.op){if(j.test=b(a,e.value),!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j.newDocument=a,j}if("remove"===e.op)return j.removed=a,j.newDocument=null,j;if("_get"===e.op)return e.value=a,j;if(h)throw new t("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",0,e,a);return j}i||(a=d(a));var k=e.path||"",l=k.split("/"),m=a,o=1,q=l.length,u=void 0,v=void 0,w=void 0;for(w="function"==typeof h?h:n;;){if(v=l[o],h&&void 0===u&&(void 0===m[v]?u=l.slice(0,o).join("/"):o==q-1&&(u=e.path),void 0!==u&&w(e,0,a,u)),o++,p(m)){if("-"===v)v=m.length;else{if(h&&!c(v))throw new t("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",0,e.path,e);v=~~v}if(o>=q){if(h&&"add"===e.op&&v>m.length)throw new t("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",0,e.path,e);var j=s[e.op].call(e,m,v,a);if(!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j}}else if(v&&-1!=v.indexOf("~")&&(v=f(v)),o>=q){var j=r[e.op].call(e,m,v,a);if(!1===j.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,e,a);return j}m=m[v]}}function i(a,b,c){for(var d=new Array(b.length),e=0,f=b.length;e<f;e++)d[e]=h(a,b[e],c),a=d[e].newDocument;return d.newDocument=a,d}function j(a,b,c){console.warn("jsonpatch.apply is deprecated, please use `applyPatch` for applying patch sequences, or `applyOperation` to apply individual operations.");for(var e=new Array(b.length),f=function(f,i){if(""==b[f].path&&"remove"!=b[f].op&&"test"!=b[f].op){var j;"replace"!=b[f].op&&"move"!=b[f].op||(e[f]=d(a)),"copy"!=b[f].op&&"move"!=b[f].op||(j=g(a,b[f].from)),"replace"!=b[f].op&&"add"!=b[f].op||(j=b[f].value),Object.keys(a).forEach(function(b){return delete a[b]}),Object.keys(j).forEach(function(b){return a[b]=j[b]})}else e[f]=h(a,b[f],c),e[f]=e[f].removed||e[f].test},i=0,j=b.length;i<j;i++)f(i,j);return e}function k(a,b){var c=h(a,b);if(!1===c.test)throw new t("Test operation failed","TEST_OPERATION_FAILED",0,b,a);return c.newDocument}function l(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)}function m(a){if(void 0===a)return!0;if(a)if(p(a)){for(var b=0,c=a.length;b<c;b++)if(m(a[b]))return!0}else if("object"==typeof a)for(var d=q(a),e=d.length,b=0;b<e;b++)if(m(a[d[b]]))return!0;return!1}function n(a,b,c,d){if("object"!=typeof a||null===a||p(a))throw new t("Operation is not an object","OPERATION_NOT_AN_OBJECT",b,a,c);if(!r[a.op])throw new t("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",b,a,c);if("string"!=typeof a.path)throw new t("Operation `path` property is not a string","OPERATION_PATH_INVALID",b,a,c);if(0!==a.path.indexOf("/")&&a.path.length>0)throw new t('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",b,a,c);if(("move"===a.op||"copy"===a.op)&&"string"!=typeof a.from)throw new t("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&void 0===a.value)throw new t("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",b,a,c);if(("add"===a.op||"replace"===a.op||"test"===a.op)&&m(a.value))throw new t("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",b,a,c);if(c)if("add"==a.op){var e=a.path.split("/").length,f=d.split("/").length;if(e!==f+1&&e!==f)throw new t("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",b,a,c)}else if("replace"===a.op||"remove"===a.op||"_get"===a.op){if(a.path!==d)throw new t("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",b,a,c)}else if("move"===a.op||"copy"===a.op){var g={op:"_get",path:a.from,value:void 0},h=o([g],c);if(h&&"OPERATION_PATH_UNRESOLVABLE"===h.name)throw new t("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",b,a,c)}}function o(a,b,c){try{if(!p(a))throw new t("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)i(d(b),d(a),c||!0);else{c=c||n;for(var e=0;e<a.length;e++)c(a[e],e,b,void 0)}}catch(a){if(a instanceof t)return a;throw a}}var p,q=function(a){if(p(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},r={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,c){var e=g(c,this.path);e&&(e=d(e));var f=h(c,{op:"remove",path:this.from}).removed;return h(c,{op:"add",path:this.path,value:f}),{newDocument:c,removed:e}},copy:function(a,b,c){var e=g(c,this.from);return h(c,{op:"add",path:this.path,value:d(e)}),{newDocument:c}},test:function(a,c,d){return{newDocument:d,test:b(a[c],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},s={add:function(a,b,c){return a.splice(b,0,this.value),{newDocument:c,index:b}},remove:function(a,b,c){return{newDocument:c,removed:a.splice(b,1)[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:r.move,copy:r.copy,test:r.test,_get:r._get};p=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.deepClone=d,a.escapePathComponent=e,a.unescapePathComponent=f,a.getValueByPointer=g,a.applyOperation=h,a.applyPatch=i,a.apply=j,a.applyReducer=k;var t=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return l(b,a),b}(Error);a.JsonPatchError=t,a.validator=n,a.validate=o}(jsonpatch||(jsonpatch={})),void 0!==exports)exports.apply=jsonpatch.apply,exports.applyPatch=jsonpatch.applyPatch,exports.applyOperation=jsonpatch.applyOperation,exports.applyReducer=jsonpatch.applyReducer,exports.getValueByPointer=jsonpatch.getValueByPointer,exports.deepClone=jsonpatch.deepClone,exports.escapePathComponent=jsonpatch.escapePathComponent,exports.unescapePathComponent=jsonpatch.unescapePathComponent,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError;else var exports={},isBrowser=!0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=jsonpatch,isBrowser&&(exports=void 0);
{
"name": "fast-json-patch",
"version": "1.2.0",
"version": "1.2.1",
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch",

@@ -181,2 +181,5 @@ JSON-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.deepClone(patch))`.
Returns an array of [`OperationResult`](#operationresult-type) objects - one item for each item in `patches`, each item is an object `{newDocument: any, test?: boolean, removed?: any}`.

@@ -203,2 +206,5 @@

It modifies the `document` object and `operation` - it gets the values by reference.
If you would like to avoid touching your values, clone them: `jsonpatch.applyOperation(document, jsonpatch.deepClone(operation))`.
Returns an [`OperationResult`](#operationresult-type) object `{newDocument: any, test?: boolean, removed?: any}`.

@@ -220,2 +226,8 @@

#### `jsonpatch.deepClone(value: any): any`
Available in *json-patch.js* and *json-patch-duplex.js*
Returns deeply cloned value.
#### `jsonpatch.escapePathComponent(path: string): string`

@@ -222,0 +234,0 @@

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester

@@ -84,2 +84,8 @@ * MIT license

/**
* Deeply clone the object.
* @param {any} obj value to clone
* @return {any} cloned obj
*/
function deepClone<T>(obj: T): T;
/**
* Escapes a json pointer path

@@ -108,2 +114,5 @@ * @param path The raw pointer

* Returns the {newDocument, result} of the operation.
* 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.applyOperation(document, jsonpatch.deepClone(operation))`.
*

@@ -120,2 +129,5 @@ * @param document The document to patch

* 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.deepClone(patch))`.
*

@@ -133,3 +145,3 @@ * @param document The document to patch

* the removed object (operations that remove things)
* or just be undefined
* or just be undefined.
* @deprecated

@@ -136,0 +148,0 @@ */

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester

@@ -109,3 +109,4 @@ * MIT license

var valueToCopy = getValueByPointer(document, this.from);
applyOperation(document, { op: "add", path: this.path, value: valueToCopy });
// enforce copy by value so further operations don't affect source (see issue #177)
applyOperation(document, { op: "add", path: this.path, value: deepClone(valueToCopy) });
return { newDocument: document };

@@ -222,12 +223,2 @@ },

jsonpatch.unobserve = unobserve;
function deepClone(obj) {
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
}
/**

@@ -398,2 +389,18 @@ * Observes changes made to an object, which can then be retieved using generate

/**
* Deeply clone the object.
* @param {any} obj value to clone
* @return {any} cloned obj
*/
function deepClone(obj) {
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
}
jsonpatch.deepClone = deepClone;
/**
* Escapes a json pointer path

@@ -427,2 +434,5 @@ * @param path The raw pointer

function getValueByPointer(document, pointer) {
if (pointer == '') {
return document;
}
var getOriginalDestination = { op: "_get", path: pointer };

@@ -436,2 +446,5 @@ applyOperation(document, getOriginalDestination);

* Returns the {newDocument, result} of the operation.
* 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.applyOperation(document, jsonpatch.deepClone(operation))`.
*

@@ -455,5 +468,5 @@ * @param document The document to patch

}
var returnValue = { newDocument: document };
/* ROOT OPERATIONS */
if (operation.path === "") {
var returnValue = { newDocument: document };
if (operation.op === 'add') {

@@ -488,2 +501,6 @@ returnValue.newDocument = operation.value;

}
else if (operation.op === '_get') {
operation.value = document;
return returnValue;
}
else {

@@ -546,3 +563,3 @@ if (validateOperation) {

}
returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
if (returnValue.test === false) {

@@ -559,3 +576,3 @@ throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document);

if (t >= len) {
returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
if (returnValue.test === false) {

@@ -575,2 +592,5 @@ throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, 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.deepClone(patch))`.
*

@@ -597,3 +617,3 @@ * @param document The document to patch

* the removed object (operations that remove things)
* or just be undefined
* or just be undefined.
* @deprecated

@@ -764,4 +784,4 @@ */

if (document) {
document = JSON.parse(JSON.stringify(document)); //clone document so that we can safely try applying operations
applyPatch(document, sequence, externalValidator || true);
//clone document and sequence so that we can safely try applying operations
applyPatch(deepClone(document), deepClone(sequence), externalValidator || true);
}

@@ -801,2 +821,3 @@ else {

exports.getValueByPointer = jsonpatch.getValueByPointer;
exports.deepClone = jsonpatch.deepClone;
exports.escapePathComponent = jsonpatch.escapePathComponent;

@@ -803,0 +824,0 @@ exports.unescapePathComponent = jsonpatch.unescapePathComponent;

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester

@@ -66,2 +66,9 @@ * MIT license

/**
* Deeply clone the object.
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
* @param {any} obj value to clone
* @return {any} cloned obj
*/
function deepClone<T>(obj: T): T;
/**
* Escapes a json pointer path

@@ -90,2 +97,5 @@ * @param path The raw pointer

* Returns the {newDocument, result} of the operation.
* It modifies the `document` object and `operation` - it gets the values by reference.
* If you would like to avoid touching your values, clone them:
* `jsonpatch.applyOperation(document, jsonpatch.deepClone(operation))`.
*

@@ -102,2 +112,5 @@ * @param document The document to patch

* 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.deepClone(patch))`.
*

@@ -104,0 +117,0 @@ * @param document The document to patch

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 1.2.0
* json-patch-duplex.js version: 1.2.1
* (c) 2013 Joachim Wester

@@ -73,12 +73,2 @@ * MIT license

}
function deepClone(obj) {
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
}
/* We use a Javascript hash to store each

@@ -120,3 +110,4 @@ function. Each hash entry (property) uses

var valueToCopy = getValueByPointer(document, this.from);
applyOperation(document, { op: "add", path: this.path, value: valueToCopy });
// enforce copy by value so further operations don't affect source (see issue #177)
applyOperation(document, { op: "add", path: this.path, value: deepClone(valueToCopy) });
return { newDocument: document };

@@ -178,2 +169,19 @@ },

/**
* Deeply clone the object.
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
* @param {any} obj value to clone
* @return {any} cloned obj
*/
function deepClone(obj) {
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
}
jsonpatch.deepClone = deepClone;
/**
* Escapes a json pointer path

@@ -207,2 +215,5 @@ * @param path The raw pointer

function getValueByPointer(document, pointer) {
if (pointer == '') {
return document;
}
var getOriginalDestination = { op: "_get", path: pointer };

@@ -216,2 +227,5 @@ applyOperation(document, getOriginalDestination);

* Returns the {newDocument, result} of the operation.
* It modifies the `document` object and `operation` - it gets the values by reference.
* If you would like to avoid touching your values, clone them:
* `jsonpatch.applyOperation(document, jsonpatch.deepClone(operation))`.
*

@@ -267,2 +281,6 @@ * @param document The document to patch

}
else if (operation.op === '_get') {
operation.value = document;
return returnValue;
}
else {

@@ -352,2 +370,5 @@ if (validateOperation) {

* 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.deepClone(patch))`.
*

@@ -540,4 +561,4 @@ * @param document The document to patch

if (document) {
document = JSON.parse(JSON.stringify(document)); //clone document so that we can safely try applying operations
applyPatch(document, sequence, externalValidator || true);
//clone document so that we can safely try applying operations
applyPatch(deepClone(document), deepClone(sequence), externalValidator || true);
}

@@ -568,2 +589,3 @@ else {

exports.getValueByPointer = jsonpatch.getValueByPointer;
exports.deepClone = jsonpatch.deepClone;
exports.escapePathComponent = jsonpatch.escapePathComponent;

@@ -570,0 +592,0 @@ exports.unescapePathComponent = jsonpatch.unescapePathComponent;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc