fast-json-patch
Advanced tools
Comparing version 1.1.3 to 1.1.4
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (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;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),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 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]&&void 0!==n&&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(0!==b.path.indexOf("/")&&b.path.length>0)throw new A('Operation `path` property must start with "/"',"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); | ||
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(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),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 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]&&void 0!==n&&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(0!==b.path.indexOf("/")&&b.path.length>0)throw new A('Operation `path` property must start with "/"',"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;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.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (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;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(0!==b.path.indexOf("/")&&b.path.length>0)throw new n('Operation `path` property must start with "/"',"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); | ||
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(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(0!==b.path.indexOf("/")&&b.path.length>0)throw new n('Operation `path` property must start with "/"',"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;else var exports={},isBrowser=!0;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=jsonpatch,isBrowser&&(exports=void 0); |
{ | ||
"name": "fast-json-patch", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities", | ||
@@ -37,6 +37,8 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch", | ||
"jsdom": "^9.5.0", | ||
"jsonfile": "^2.3.1" | ||
"jsonfile": "^2.3.1", | ||
"underscore": "^1.8.3" | ||
}, | ||
"scripts": { | ||
"tsc": "tsc src/json-patch-duplex.ts --noEmitHelpers && tsc src/json-patch.ts --noEmitHelpers", | ||
"tsc": "tsc", | ||
"tsc-watch": "tsc -w", | ||
"test": "npm run test-core && npm run test-duplex", | ||
@@ -43,0 +45,0 @@ "test-duplex": "jasmine DUPLEX=yes JASMINE_CONFIG_PATH=test/jasmine.json", |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (c) 2013 Joachim Wester | ||
@@ -207,3 +207,3 @@ * MIT license | ||
return Mirror; | ||
})(); | ||
}()); | ||
var ObserverInfo = (function () { | ||
@@ -215,3 +215,3 @@ function ObserverInfo(callback, observer) { | ||
return ObserverInfo; | ||
})(); | ||
}()); | ||
function getMirror(obj) { | ||
@@ -503,3 +503,3 @@ for (var i = 0, ilen = beforeDict.length; i < ilen; i++) { | ||
return JsonPatchError; | ||
})(Error); | ||
}(Error)); | ||
jsonpatch.JsonPatchError = JsonPatchError; | ||
@@ -618,1 +618,16 @@ /** | ||
} | ||
else { | ||
var exports = {}; | ||
var isBrowser = true; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = jsonpatch; | ||
/* | ||
When in browser, setting `exports = {}` | ||
fools other modules into thinking they're | ||
running in a node environment, which breaks | ||
some of them. Here is super light wieght fix. | ||
*/ | ||
if (isBrowser) { | ||
exports = undefined; | ||
} |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (c) 2013 Joachim Wester | ||
@@ -9,7 +9,6 @@ * MIT license | ||
interface HTMLElement { | ||
attachEvent : Function; | ||
detachEvent : Function; | ||
attachEvent: Function; | ||
detachEvent: Function; | ||
} | ||
module jsonpatch { | ||
@@ -99,16 +98,16 @@ var _objectKeys = function (obj) { | ||
move: function (obj, key, tree) { | ||
var getOriginalDestination : any = {op: "_get", path: this.path}; | ||
var getOriginalDestination: any = { op: "_get", path: this.path }; | ||
apply(tree, [getOriginalDestination]); | ||
// In case value is moved up and overwrites its ancestor | ||
var original = getOriginalDestination.value === undefined ? | ||
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value)); | ||
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value)); | ||
var temp:any = {op: "_get", path: this.from}; | ||
var temp: any = { op: "_get", path: this.from }; | ||
apply(tree, [temp]); | ||
apply(tree, [ | ||
{op: "remove", path: this.from} | ||
{ op: "remove", path: this.from } | ||
]); | ||
apply(tree, [ | ||
{op: "add", path: this.path, value: temp.value} | ||
{ op: "add", path: this.path, value: temp.value } | ||
]); | ||
@@ -118,6 +117,6 @@ return original; | ||
copy: function (obj, key, tree) { | ||
var temp:any = {op: "_get", path: this.from}; | ||
var temp: any = { op: "_get", path: this.from }; | ||
apply(tree, [temp]); | ||
apply(tree, [ | ||
{op: "add", path: this.path, value: temp.value} | ||
{ op: "add", path: this.path, value: temp.value } | ||
]); | ||
@@ -177,6 +176,6 @@ }, | ||
var removed = apply(obj, [ | ||
{op: "remove", path: this.path} | ||
{ op: "remove", path: this.path } | ||
]); | ||
apply(obj, [ | ||
{op: "add", path: this.path, value: this.value} | ||
{ op: "add", path: this.path, value: this.value } | ||
]); | ||
@@ -195,3 +194,3 @@ return removed[0]; | ||
function escapePathComponent (str) { | ||
function escapePathComponent(str) { | ||
if (str.indexOf('/') === -1 && str.indexOf('~') === -1) return str; | ||
@@ -201,3 +200,3 @@ return str.replace(/~/g, '~0').replace(/\//g, '~1'); | ||
function _getPathRecursive(root:Object, obj:Object):string { | ||
function _getPathRecursive(root: Object, obj: Object): string { | ||
var found; | ||
@@ -220,3 +219,3 @@ for (var key in root) { | ||
function getPath(root:Object, obj:Object):string { | ||
function getPath(root: Object, obj: Object): string { | ||
if (root === obj) { | ||
@@ -238,3 +237,3 @@ return '/'; | ||
constructor(obj:any){ | ||
constructor(obj: any) { | ||
this.obj = obj; | ||
@@ -248,3 +247,3 @@ } | ||
constructor(callback, observer){ | ||
constructor(callback, observer) { | ||
this.callback = callback; | ||
@@ -255,3 +254,3 @@ this.observer = observer; | ||
function getMirror(obj:any):any { | ||
function getMirror(obj: any): any { | ||
for (var i = 0, ilen = beforeDict.length; i < ilen; i++) { | ||
@@ -264,3 +263,3 @@ if (beforeDict[i].obj === obj) { | ||
function getObserverFromMirror(mirror:any, callback):any { | ||
function getObserverFromMirror(mirror: any, callback): any { | ||
for (var j = 0, jlen = mirror.observers.length; j < jlen; j++) { | ||
@@ -273,3 +272,3 @@ if (mirror.observers[j].callback === callback) { | ||
function removeObserverFromMirror(mirror:any, observer):any { | ||
function removeObserverFromMirror(mirror: any, observer): any { | ||
for (var j = 0, jlen = mirror.observers.length; j < jlen; j++) { | ||
@@ -287,3 +286,3 @@ if (mirror.observers[j].observer === observer) { | ||
function deepClone(obj:any) { | ||
function deepClone(obj: any) { | ||
switch (typeof obj) { | ||
@@ -301,3 +300,3 @@ case "object": | ||
export function observe(obj:any, callback):any { | ||
export function observe(obj: any, callback): any { | ||
var patches = []; | ||
@@ -315,3 +314,3 @@ var root = obj; | ||
if(observer){ | ||
if (observer) { | ||
return observer; | ||
@@ -329,7 +328,7 @@ } | ||
var dirtyCheck = () => { | ||
generate(observer); | ||
generate(observer); | ||
}; | ||
var fastCheck = () => { | ||
clearTimeout(observer.next); | ||
observer.next = setTimeout(dirtyCheck); | ||
clearTimeout(observer.next); | ||
observer.next = setTimeout(dirtyCheck); | ||
}; | ||
@@ -345,7 +344,7 @@ if (typeof window !== 'undefined') { //not Node | ||
else { //IE8 | ||
document.documentElement.attachEvent('onmouseup', fastCheck); | ||
document.documentElement.attachEvent('onkeyup', fastCheck); | ||
document.documentElement.attachEvent('onmousedown', fastCheck); | ||
document.documentElement.attachEvent('onkeydown', fastCheck); | ||
document.documentElement.attachEvent('onchange', fastCheck); | ||
(<any>document.documentElement).attachEvent('onmouseup', fastCheck); | ||
(<any>document.documentElement).attachEvent('onkeyup', fastCheck); | ||
(<any>document.documentElement).attachEvent('onmousedown', fastCheck); | ||
(<any>document.documentElement).attachEvent('onkeydown', fastCheck); | ||
(<any>document.documentElement).attachEvent('onchange', fastCheck); | ||
} | ||
@@ -358,20 +357,20 @@ } | ||
observer.unobserve = () => { | ||
generate(observer); | ||
clearTimeout(observer.next); | ||
removeObserverFromMirror(mirror, observer); | ||
generate(observer); | ||
clearTimeout(observer.next); | ||
removeObserverFromMirror(mirror, observer); | ||
if (typeof window !== 'undefined') { | ||
if (window.removeEventListener) { | ||
window.removeEventListener('mouseup', fastCheck); | ||
window.removeEventListener('keyup', fastCheck); | ||
window.removeEventListener('mousedown', fastCheck); | ||
window.removeEventListener('keydown', fastCheck); | ||
} | ||
else { | ||
document.documentElement.detachEvent('onmouseup', fastCheck); | ||
document.documentElement.detachEvent('onkeyup', fastCheck); | ||
document.documentElement.detachEvent('onmousedown', fastCheck); | ||
document.documentElement.detachEvent('onkeydown', fastCheck); | ||
} | ||
if (typeof window !== 'undefined') { | ||
if (window.removeEventListener) { | ||
window.removeEventListener('mouseup', fastCheck); | ||
window.removeEventListener('keyup', fastCheck); | ||
window.removeEventListener('mousedown', fastCheck); | ||
window.removeEventListener('keydown', fastCheck); | ||
} | ||
else { | ||
(<any>document.documentElement).detachEvent('onmouseup', fastCheck); | ||
(<any>document.documentElement).detachEvent('onkeyup', fastCheck); | ||
(<any>document.documentElement).detachEvent('onmousedown', fastCheck); | ||
(<any>document.documentElement).detachEvent('onkeydown', fastCheck); | ||
} | ||
} | ||
}; | ||
@@ -393,9 +392,9 @@ | ||
_generate(mirror.value, observer.object, observer.patches, ""); | ||
if(observer.patches.length) { | ||
if (observer.patches.length) { | ||
apply(mirror.value, observer.patches); | ||
} | ||
var temp = observer.patches; | ||
if(temp.length > 0) { | ||
if (temp.length > 0) { | ||
observer.patches = []; | ||
if(observer.callback) { | ||
if (observer.callback) { | ||
observer.callback(temp); | ||
@@ -427,3 +426,3 @@ } | ||
changed = true; | ||
patches.push({op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal)}); | ||
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal) }); | ||
} | ||
@@ -433,3 +432,3 @@ } | ||
else { | ||
patches.push({op: "remove", path: path + "/" + escapePathComponent(key)}); | ||
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) }); | ||
deleted = true; // property has been deleted | ||
@@ -446,3 +445,3 @@ } | ||
if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { | ||
patches.push({op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key])}); | ||
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key]) }); | ||
} | ||
@@ -457,3 +456,3 @@ } | ||
else { //IE8 shim | ||
_isArray = function (obj:any) { | ||
_isArray = function (obj: any) { | ||
return obj.push && typeof obj.length === 'number'; | ||
@@ -464,3 +463,3 @@ } | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str:string):boolean { | ||
function isInteger(str: string): boolean { | ||
var i = 0; | ||
@@ -487,8 +486,8 @@ var len = str.length; | ||
*/ | ||
export function apply(tree:any, patches:any[], validate?:boolean):Array<any> { | ||
export function apply(tree: any, patches: any[], validate?: boolean): Array<any> { | ||
var results = [] | ||
, p = 0 | ||
, plen = patches.length | ||
, patch | ||
, key; | ||
, p = 0 | ||
, plen = patches.length | ||
, patch | ||
, key; | ||
while (p < plen) { | ||
@@ -523,3 +522,3 @@ patch = patches[p]; | ||
t++; | ||
if(key === undefined) { //is root | ||
if (key === undefined) { //is root | ||
if (t >= len) { | ||
@@ -562,3 +561,3 @@ results.push(rootOps[patch.op].call(patch, obj, key, tree)); // Apply patch | ||
export function compare(tree1:any, tree2:any):any[] { | ||
export function compare(tree1: any, tree2: any): any[] { | ||
var patches = []; | ||
@@ -578,3 +577,3 @@ _generate(tree1, tree2, patches, ''); | ||
constructor(public message: string, public name:string, public index?:number, public operation?:any, public tree?:any) { | ||
constructor(public message: string, public name: string, public index?: number, public operation?: any, public tree?: any) { | ||
super(message); | ||
@@ -584,20 +583,20 @@ } | ||
/** | ||
* Recursively checks whether an object has any undefined values inside. | ||
*/ | ||
function hasUndefined(obj:any): boolean { | ||
if (obj === undefined) { | ||
return true; | ||
} | ||
/** | ||
* Recursively checks whether an object has any undefined values inside. | ||
*/ | ||
function hasUndefined(obj: any): boolean { | ||
if (obj === undefined) { | ||
return true; | ||
} | ||
if (typeof obj == "array" || typeof obj == "object") { | ||
for (var i in obj) { | ||
if (hasUndefined(obj[i])) { | ||
return true; | ||
} | ||
} | ||
if (typeof obj == "array" || typeof obj == "object") { | ||
for (var i in obj) { | ||
if (hasUndefined(obj[i])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
@@ -611,3 +610,3 @@ /** | ||
*/ | ||
export function validator(operation:any, index:number, tree?:any, existingPathFragment?:string) { | ||
export function validator(operation: any, index: number, tree?: any, existingPathFragment?: string) { | ||
if (typeof operation !== 'object' || operation === null || _isArray(operation)) { | ||
@@ -650,3 +649,3 @@ throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, tree); | ||
} | ||
else if(operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') { | ||
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') { | ||
if (operation.path !== existingPathFragment) { | ||
@@ -657,3 +656,3 @@ throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, tree); | ||
else if (operation.op === 'move' || operation.op === 'copy') { | ||
var existingValue = {op: "_get", path: operation.from, value: undefined}; | ||
var existingValue = { op: "_get", path: operation.from, value: undefined }; | ||
var error = jsonpatch.validate([existingValue], tree); | ||
@@ -674,3 +673,3 @@ if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') { | ||
*/ | ||
export function validate(sequence:any[], tree?:any):JsonPatchError { | ||
export function validate(sequence: any[], tree?: any): JsonPatchError { | ||
try { | ||
@@ -701,5 +700,4 @@ if (!_isArray(sequence)) { | ||
} | ||
declare var exports; | ||
declare var exports:any; | ||
if (typeof exports !== "undefined") { | ||
@@ -715,1 +713,18 @@ exports.apply = jsonpatch.apply; | ||
} | ||
else | ||
{ | ||
var exports:any = {}; | ||
var isBrowser = true; | ||
} | ||
export default jsonpatch; | ||
/* | ||
When in browser, setting `exports = {}` | ||
fools other modules into thinking they're | ||
running in a node environment, which breaks | ||
some of them. Here is super light wieght fix. | ||
*/ | ||
if(isBrowser) | ||
{ | ||
exports = undefined | ||
} |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (c) 2013 Joachim Wester | ||
@@ -284,3 +284,3 @@ * MIT license | ||
return JsonPatchError; | ||
})(Error); | ||
}(Error)); | ||
jsonpatch.JsonPatchError = JsonPatchError; | ||
@@ -395,1 +395,16 @@ /** | ||
} | ||
else { | ||
var exports = {}; | ||
var isBrowser = true; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = jsonpatch; | ||
/* | ||
When in browser, setting `exports = {}` | ||
fools other modules into thinking they're | ||
running in a node environment, which breaks | ||
some of them. Here is super light wieght fix. | ||
*/ | ||
if (isBrowser) { | ||
exports = undefined; | ||
} |
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* json-patch-duplex.js version: 1.1.3 | ||
* json-patch-duplex.js version: 1.1.4 | ||
* (c) 2013 Joachim Wester | ||
@@ -8,3 +8,2 @@ * MIT license | ||
module jsonpatch { | ||
@@ -94,16 +93,16 @@ var _objectKeys = function (obj) { | ||
move: function (obj, key, tree) { | ||
var getOriginalDestination : any = {op: "_get", path: this.path}; | ||
var getOriginalDestination: any = { op: "_get", path: this.path }; | ||
apply(tree, [getOriginalDestination]); | ||
// In case value is moved up and overwrites its ancestor | ||
var original = getOriginalDestination.value === undefined ? | ||
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value)); | ||
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value)); | ||
var temp:any = {op: "_get", path: this.from}; | ||
var temp: any = { op: "_get", path: this.from }; | ||
apply(tree, [temp]); | ||
apply(tree, [ | ||
{op: "remove", path: this.from} | ||
{ op: "remove", path: this.from } | ||
]); | ||
apply(tree, [ | ||
{op: "add", path: this.path, value: temp.value} | ||
{ op: "add", path: this.path, value: temp.value } | ||
]); | ||
@@ -113,6 +112,6 @@ return original; | ||
copy: function (obj, key, tree) { | ||
var temp:any = {op: "_get", path: this.from}; | ||
var temp: any = { op: "_get", path: this.from }; | ||
apply(tree, [temp]); | ||
apply(tree, [ | ||
{op: "add", path: this.path, value: temp.value} | ||
{ op: "add", path: this.path, value: temp.value } | ||
]); | ||
@@ -172,6 +171,6 @@ }, | ||
var removed = apply(obj, [ | ||
{op: "remove", path: this.path} | ||
{ op: "remove", path: this.path } | ||
]); | ||
apply(obj, [ | ||
{op: "add", path: this.path, value: this.value} | ||
{ op: "add", path: this.path, value: this.value } | ||
]); | ||
@@ -195,3 +194,3 @@ return removed[0]; | ||
else { //IE8 shim | ||
_isArray = function (obj:any) { | ||
_isArray = function (obj: any) { | ||
return obj.push && typeof obj.length === 'number'; | ||
@@ -202,3 +201,3 @@ } | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str:string):boolean { | ||
function isInteger(str: string): boolean { | ||
var i = 0; | ||
@@ -225,3 +224,3 @@ var len = str.length; | ||
*/ | ||
export function apply(tree:any, patches:any[], validate?:boolean):Array<any> { | ||
export function apply(tree: any, patches: any[], validate?: boolean): Array<any> { | ||
var results = new Array(patches.length) | ||
@@ -261,3 +260,3 @@ , p = 0 | ||
t++; | ||
if(key === undefined) { //is root | ||
if (key === undefined) { //is root | ||
if (t >= len) { | ||
@@ -308,3 +307,3 @@ results[p - 1] = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch | ||
constructor(public message: string, public name:string, public index?:number, public operation?:any, public tree?:any) { | ||
constructor(public message: string, public name: string, public index?: number, public operation?: any, public tree?: any) { | ||
super(message); | ||
@@ -314,20 +313,20 @@ } | ||
/** | ||
* Recursively checks whether an object has any undefined values inside. | ||
*/ | ||
function hasUndefined(obj:any): boolean { | ||
if (obj === undefined) { | ||
return true; | ||
} | ||
/** | ||
* Recursively checks whether an object has any undefined values inside. | ||
*/ | ||
function hasUndefined(obj: any): boolean { | ||
if (obj === undefined) { | ||
return true; | ||
} | ||
if (typeof obj == "array" || typeof obj == "object") { | ||
for (var i in obj) { | ||
if (hasUndefined(obj[i])) { | ||
return true; | ||
} | ||
} | ||
if (typeof obj == "array" || typeof obj == "object") { | ||
for (var i in obj) { | ||
if (hasUndefined(obj[i])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
@@ -341,3 +340,3 @@ /** | ||
*/ | ||
export function validator(operation:any, index:number, tree?:any, existingPathFragment?:string) { | ||
export function validator(operation: any, index: number, tree?: any, existingPathFragment?: string) { | ||
if (typeof operation !== 'object' || operation === null || _isArray(operation)) { | ||
@@ -380,3 +379,3 @@ throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, tree); | ||
} | ||
else if(operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') { | ||
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') { | ||
if (operation.path !== existingPathFragment) { | ||
@@ -387,3 +386,3 @@ throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, tree); | ||
else if (operation.op === 'move' || operation.op === 'copy') { | ||
var existingValue = {op: "_get", path: operation.from, value: undefined}; | ||
var existingValue = { op: "_get", path: operation.from, value: undefined }; | ||
var error = jsonpatch.validate([existingValue], tree); | ||
@@ -404,3 +403,3 @@ if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') { | ||
*/ | ||
export function validate(sequence:any[], tree?:any):JsonPatchError { | ||
export function validate(sequence: any[], tree?: any): JsonPatchError { | ||
try { | ||
@@ -432,4 +431,2 @@ if (!_isArray(sequence)) { | ||
declare var exports:any; | ||
if (typeof exports !== "undefined") { | ||
@@ -441,1 +438,18 @@ exports.apply = jsonpatch.apply; | ||
} | ||
else | ||
{ | ||
var exports:any = {}; | ||
var isBrowser = true; | ||
} | ||
export default jsonpatch; | ||
/* | ||
When in browser, setting `exports = {}` | ||
fools other modules into thinking they're | ||
running in a node environment, which breaks | ||
some of them. Here is super light wieght fix. | ||
*/ | ||
if(isBrowser) | ||
{ | ||
exports = undefined | ||
} |
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
106964
11
2074
9