fast-json-patch
Advanced tools
Comparing version 1.0.1 to 1.1.0
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
* MIT license | ||
*/ | ||
var jsonpatch;!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(z(a)){if(!z(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=s(c),g=f.length;if(s(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function d(a){for(var b=0,c=w.length;c>b;b++)if(w[b].obj===a)return w[b]}function e(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function f(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function g(a,b){b.unobserve()}function h(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function i(a,b){var c,g=[],i=d(a);if(i?c=e(i,b):(i=new x(a),w.push(i)),c)return c;if(c={},i.value=h(a),b){c.callback=b,c.next=null;var k=function(){j(c)},l=function(){clearTimeout(c.next),c.next=setTimeout(k)};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mouseup",l),window.addEventListener("keyup",l)):(document.documentElement.attachEvent("onmouseup",l),document.documentElement.attachEvent("onkeyup",l)))}return c.patches=g,c.object=a,c.unobserve=function(){j(c),clearTimeout(c.next),f(i,c),"undefined"!=typeof window&&(window.removeEventListener?(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l)):(document.documentElement.detachEvent("onmouseup",l),document.documentElement.detachEvent("onkeyup",l)))},i.observers.push(new y(b,c)),c}function j(a){for(var b,c=0,d=w.length;d>c;c++)if(w[c].obj===a.object){b=w[c];break}k(b.value,a.object,a.patches,""),a.patches.length&&m(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function k(a,b,d,e){for(var f=s(b),g=s(a),i=!1,j=!1,l=g.length-1;l>=0;l--){var m=g[l],n=a[m];if(!b.hasOwnProperty(m)||void 0===b[m]&&z(b)===!1)d.push({op:"remove",path:e+"/"+c(m)}),j=!0;else{var o=b[m];"object"==typeof n&&null!=n&&"object"==typeof o&&null!=o?k(n,o,d,e+"/"+c(m)):n!=o&&(i=!0,d.push({op:"replace",path:e+"/"+c(m),value:h(o)}))}}if(j||f.length!=g.length)for(var l=0;l<f.length;l++){var m=f[l];a.hasOwnProperty(m)||void 0===b[m]||d.push({op:"add",path:e+"/"+c(m),value:h(b[m])})}}function l(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function m(a,b,c){for(var d,e,f=[],g=0,h=b.length;h>g;){d=b[g],g++;for(var i=d.path||"",j=i.split("/"),k=a,m=1,n=j.length,o=void 0;;){if(e=j[m],c&&void 0===o&&(void 0===k[e]?o=j.slice(0,m).join("/"):m==n-1&&(o=d.path),void 0!==o&&this.validator(d,g-1,a,o)),m++,void 0===e&&m>=n){f.push(v[d.op].call(d,k,e,a));break}if(z(k)){if("-"===e)e=k.length;else{if(c&&!l(e))throw new A("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",g-1,d.path,d);e=parseInt(e,10)}if(m>=n){if(c&&"add"===d.op&&e>k.length)throw new A("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",g-1,d.path,d);f.push(u[d.op].call(d,k,e,a));break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),m>=n){f.push(t[d.op].call(d,k,e,a));break}k=k[e]}}return f}function n(a,b){var c=[];return k(a,b,c,""),c}function o(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 p(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(p(a[b]))return!0;return!1}function q(b,c,d,e){if("object"!=typeof b||null===b||z(b))throw new A("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!t[b.op])throw new A("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new A("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new A("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new A("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&p(b.value))throw new A("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,g=e.split("/").length;if(f!==g+1&&f!==g)throw new A("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new A("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var h={op:"_get",path:b.from,value:void 0},i=a.validate([h],d);if(i&&"OPERATION_PATH_UNRESOLVABLE"===i.name)throw new A("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function r(a,b){try{if(!z(a))throw new A("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),m.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(d){if(d instanceof A)return d;throw d}}var s=function(a){if(z(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},t={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var d={op:"_get",path:this.path};m(c,[d]);var e=void 0===d.value?void 0:JSON.parse(JSON.stringify(d.value)),f={op:"_get",path:this.from};return m(c,[f]),m(c,[{op:"remove",path:this.from}]),m(c,[{op:"add",path:this.path,value:f.value}]),e},copy:function(a,b,c){var d={op:"_get",path:this.from};m(c,[d]),m(c,[{op:"add",path:this.path,value:d.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},u={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:t.move,copy:t.copy,test:t.test,_get:t._get},v={add:function(a){v.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],t.remove.call(this,a,c));return b},replace:function(a){var b=m(a,[{op:"remove",path:this.path}]);return m(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:t.move,copy:t.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},w=[],x=function(){function a(a){this.observers=[],this.obj=a}return a}(),y=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=g,a.observe=i,a.generate=j;var z;z=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=m,a.compare=n;var A=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 o(b,a),b}(Error);a.JsonPatchError=A,a.validator=q,a.validate=r}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,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); | ||
var jsonpatch;!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(z(a)){if(!z(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}var f=s(c),g=f.length;if(s(a).length!==g)return!1;for(var d=0;d<g;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){return a.indexOf("/")===-1&&a.indexOf("~")===-1?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function d(a){for(var b=0,c=w.length;b<c;b++)if(w[b].obj===a)return w[b]}function e(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 f(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 g(a,b){b.unobserve()}function h(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function i(a,b){var c,g=[],i=d(a);if(i?c=e(i,b):(i=new x(a),w.push(i)),c)return c;if(c={},i.value=h(a),b){c.callback=b,c.next=null;var k=function(){j(c)},l=function(){clearTimeout(c.next),c.next=setTimeout(k)};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mouseup",l),window.addEventListener("keyup",l),window.addEventListener("mousedown",l),window.addEventListener("keydown",l)):(document.documentElement.attachEvent("onmouseup",l),document.documentElement.attachEvent("onkeyup",l),document.documentElement.attachEvent("onmousedown",l),document.documentElement.attachEvent("onkeydown",l)))}return c.patches=g,c.object=a,c.unobserve=function(){j(c),clearTimeout(c.next),f(i,c),"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 y(b,c)),c}function j(a){for(var b,c=0,d=w.length;c<d;c++)if(w[c].obj===a.object){b=w[c];break}k(b.value,a.object,a.patches,""),a.patches.length&&m(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function k(a,b,d,e){for(var f=s(b),g=s(a),i=!1,j=!1,l=g.length-1;l>=0;l--){var m=g[l],n=a[m];if(!b.hasOwnProperty(m)||void 0===b[m]&&z(b)===!1)d.push({op:"remove",path:e+"/"+c(m)}),j=!0;else{var o=b[m];"object"==typeof n&&null!=n&&"object"==typeof o&&null!=o?k(n,o,d,e+"/"+c(m)):n!=o&&(i=!0,d.push({op:"replace",path:e+"/"+c(m),value:h(o)}))}}if(j||f.length!=g.length)for(var l=0;l<f.length;l++){var m=f[l];a.hasOwnProperty(m)||void 0===b[m]||d.push({op:"add",path:e+"/"+c(m),value:h(b[m])})}}function l(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 m(a,b,c){for(var d,e,f=[],g=0,h=b.length;g<h;){d=b[g],g++;for(var i=d.path||"",j=i.split("/"),k=a,m=1,n=j.length,o=void 0;;){if(e=j[m],c&&void 0===o&&(void 0===k[e]?o=j.slice(0,m).join("/"):m==n-1&&(o=d.path),void 0!==o&&this.validator(d,g-1,a,o)),m++,void 0===e&&m>=n){f.push(v[d.op].call(d,k,e,a));break}if(z(k)){if("-"===e)e=k.length;else{if(c&&!l(e))throw new A("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",g-1,d.path,d);e=parseInt(e,10)}if(m>=n){if(c&&"add"===d.op&&e>k.length)throw new A("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",g-1,d.path,d);f.push(u[d.op].call(d,k,e,a));break}}else if(e&&e.indexOf("~")!=-1&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),m>=n){f.push(t[d.op].call(d,k,e,a));break}k=k[e]}}return f}function n(a,b){var c=[];return k(a,b,c,""),c}function o(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 p(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(p(a[b]))return!0;return!1}function q(b,c,d,e){if("object"!=typeof b||null===b||z(b))throw new A("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!t[b.op])throw new A("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new A("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new A("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new A("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&p(b.value))throw new A("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,g=e.split("/").length;if(f!==g+1&&f!==g)throw new A("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new A("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var h={op:"_get",path:b.from,value:void 0},i=a.validate([h],d);if(i&&"OPERATION_PATH_UNRESOLVABLE"===i.name)throw new A("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function r(a,b){try{if(!z(a))throw new A("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),m.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(a){if(a instanceof A)return a;throw a}}var s=function(a){if(z(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},t={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var d={op:"_get",path:this.path};m(c,[d]);var e=void 0===d.value?void 0:JSON.parse(JSON.stringify(d.value)),f={op:"_get",path:this.from};return m(c,[f]),m(c,[{op:"remove",path:this.from}]),m(c,[{op:"add",path:this.path,value:f.value}]),e},copy:function(a,b,c){var d={op:"_get",path:this.from};m(c,[d]),m(c,[{op:"add",path:this.path,value:d.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},u={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:t.move,copy:t.copy,test:t.test,_get:t._get},v={add:function(a){v.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],t.remove.call(this,a,c));return b},replace:function(a){var b=m(a,[{op:"remove",path:this.path}]);return m(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:t.move,copy:t.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},w=[],x=function(){function a(a){this.observers=[],this.obj=a}return a}(),y=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=g,a.observe=i,a.generate=j;var z;z=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=m,a.compare=n;var A=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 o(b,a),b}(Error);a.JsonPatchError=A,a.validator=q,a.validate=r}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,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); |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
* MIT license | ||
*/ | ||
var jsonpatch;!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(i(a)){if(!i(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=j(c),g=f.length;if(j(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function d(a,b,d){for(var e,f,g=new Array(b.length),h=0,j=b.length;j>h;){e=b[h],h++;for(var o=e.path||"",p=o.split("/"),q=a,r=1,s=p.length,t=void 0;;){if(f=p[r],d&&void 0===t&&(void 0===q[f]?t=p.slice(0,r).join("/"):r==s-1&&(t=e.path),void 0!==t&&this.validator(e,h-1,a,t)),r++,void 0===f&&r>=s){g[h-1]=m[e.op].call(e,q,f,a);break}if(i(q)){if("-"===f)f=q.length;else{if(d&&!c(f))throw new n("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",h-1,e.path,e);f=parseInt(f,10)}if(r>=s){if(d&&"add"===e.op&&f>q.length)throw new n("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",h-1,e.path,e);g[h-1]=l[e.op].call(e,q,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),r>=s){g[h-1]=k[e.op].call(e,q,f,a);break}q=q[f]}}return g}function e(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 f(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(f(a[b]))return!0;return!1}function g(b,c,d,e){if("object"!=typeof b||null===b||i(b))throw new n("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!k[b.op])throw new n("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new n("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new n("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new n("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&f(b.value))throw new n("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var g=b.path.split("/").length,h=e.split("/").length;if(g!==h+1&&g!==h)throw new n("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new n("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var j={op:"_get",path:b.from,value:void 0},l=a.validate([j],d);if(l&&"OPERATION_PATH_UNRESOLVABLE"===l.name)throw new n("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function h(a,b){try{if(!i(a))throw new n("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(e){if(e instanceof n)return e;throw e}}var i,j=function(a){if(i(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},k={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var e={op:"_get",path:this.path};d(c,[e]);var f=void 0===e.value?void 0:JSON.parse(JSON.stringify(e.value)),g={op:"_get",path:this.from};return d(c,[g]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:g.value}]),f},copy:function(a,b,c){var e={op:"_get",path:this.from};d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},l={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:k.move,copy:k.copy,test:k.test,_get:k._get},m={add:function(a){m.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],k.remove.call(this,a,c));return b},replace:function(a){var b=d(a,[{op:"remove",path:this.path}]);return d(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:k.move,copy:k.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};i=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var n=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 e(b,a),b}(Error);a.JsonPatchError=n,a.validator=g,a.validate=h}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError); | ||
var jsonpatch;!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(i(a)){if(!i(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}var f=j(c),g=f.length;if(j(a).length!==g)return!1;for(var d=0;d<g;d++)if(!b(a[d],c[d]))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,b,d){for(var e,f,g=new Array(b.length),h=0,j=b.length;h<j;){e=b[h],h++;for(var o=e.path||"",p=o.split("/"),q=a,r=1,s=p.length,t=void 0;;){if(f=p[r],d&&void 0===t&&(void 0===q[f]?t=p.slice(0,r).join("/"):r==s-1&&(t=e.path),void 0!==t&&this.validator(e,h-1,a,t)),r++,void 0===f&&r>=s){g[h-1]=m[e.op].call(e,q,f,a);break}if(i(q)){if("-"===f)f=q.length;else{if(d&&!c(f))throw new n("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",h-1,e.path,e);f=parseInt(f,10)}if(r>=s){if(d&&"add"===e.op&&f>q.length)throw new n("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",h-1,e.path,e);g[h-1]=l[e.op].call(e,q,f,a);break}}else if(f&&f.indexOf("~")!=-1&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),r>=s){g[h-1]=k[e.op].call(e,q,f,a);break}q=q[f]}}return g}function e(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 f(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(f(a[b]))return!0;return!1}function g(b,c,d,e){if("object"!=typeof b||null===b||i(b))throw new n("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!k[b.op])throw new n("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new n("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new n("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new n("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&f(b.value))throw new n("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var g=b.path.split("/").length,h=e.split("/").length;if(g!==h+1&&g!==h)throw new n("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new n("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var j={op:"_get",path:b.from,value:void 0},l=a.validate([j],d);if(l&&"OPERATION_PATH_UNRESOLVABLE"===l.name)throw new n("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function h(a,b){try{if(!i(a))throw new n("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(a){if(a instanceof n)return a;throw a}}var i,j=function(a){if(i(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},k={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var e={op:"_get",path:this.path};d(c,[e]);var f=void 0===e.value?void 0:JSON.parse(JSON.stringify(e.value)),g={op:"_get",path:this.from};return d(c,[g]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:g.value}]),f},copy:function(a,b,c){var e={op:"_get",path:this.from};d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},l={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:k.move,copy:k.copy,test:k.test,_get:k._get},m={add:function(a){m.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],k.remove.call(this,a,c));return b},replace:function(a){var b=d(a,[{op:"remove",path:this.path}]);return d(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:k.move,copy:k.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};i=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var n=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 e(b,a),b}(Error);a.JsonPatchError=n,a.validator=g,a.validate=h}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError); |
{ | ||
"name": "fast-json-patch", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"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", |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -282,2 +282,4 @@ * MIT license | ||
window.addEventListener('keyup', fastCheck); | ||
window.addEventListener('mousedown', fastCheck); | ||
window.addEventListener('keydown', fastCheck); | ||
} | ||
@@ -287,2 +289,4 @@ else { | ||
document.documentElement.attachEvent('onkeyup', fastCheck); | ||
document.documentElement.attachEvent('onmousedown', fastCheck); | ||
document.documentElement.attachEvent('onkeydown', fastCheck); | ||
} | ||
@@ -301,2 +305,4 @@ } | ||
window.removeEventListener('keyup', fastCheck); | ||
window.removeEventListener('mousedown', fastCheck); | ||
window.removeEventListener('keydown', fastCheck); | ||
} | ||
@@ -306,2 +312,4 @@ else { | ||
document.documentElement.detachEvent('onkeyup', fastCheck); | ||
document.documentElement.detachEvent('onmousedown', fastCheck); | ||
document.documentElement.detachEvent('onkeydown', fastCheck); | ||
} | ||
@@ -308,0 +316,0 @@ } |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -324,2 +324,4 @@ * MIT license | ||
window.addEventListener('keyup', fastCheck); | ||
window.addEventListener('mousedown', fastCheck); | ||
window.addEventListener('keydown', fastCheck); | ||
} | ||
@@ -329,2 +331,4 @@ else { //IE8 | ||
document.documentElement.attachEvent('onkeyup', fastCheck); | ||
document.documentElement.attachEvent('onmousedown', fastCheck); | ||
document.documentElement.attachEvent('onkeydown', fastCheck); | ||
} | ||
@@ -345,2 +349,4 @@ } | ||
window.removeEventListener('keyup', fastCheck); | ||
window.removeEventListener('mousedown', fastCheck); | ||
window.removeEventListener('keydown', fastCheck); | ||
} | ||
@@ -350,2 +356,4 @@ else { | ||
document.documentElement.detachEvent('onkeyup', fastCheck); | ||
document.documentElement.detachEvent('onmousedown', fastCheck); | ||
document.documentElement.detachEvent('onkeydown', fastCheck); | ||
} | ||
@@ -352,0 +360,0 @@ } |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -5,0 +5,0 @@ * MIT license |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.0.1 | ||
* json-patch-duplex.js version: 1.1.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -5,0 +5,0 @@ * MIT license |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102784
1983