fast-json-patch
Advanced tools
Comparing version 0.4.0 to 0.5.0
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.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=r(c),g=f.length;if(r(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,b){var e;for(var f in a)if(a.hasOwnProperty(f)){if(a[f]===b)return c(f)+"/";if("object"==typeof a[f]&&(e=d(a[f],b),""!=e))return c(f)+"/"+e}return""}function e(a,b){if(a===b)return"/";var c=d(a,b);if(""===c)throw new Error("Object not found in root");return"/"+c}function f(a){for(var b=0,c=w.length;c>b;b++)if(w[b].obj===a)return w[b]}function g(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 h(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 i(a,b){m(b),Object.observe?l(b,a):clearTimeout(b.next);var c=f(a);h(c,b)}function j(a,b){var c,d=[],h=a,i=f(a);if(i?c=g(i,b):(i=new x(a),w.push(i)),c)return c;if(Object.observe)c=function(f){l(c,a),k(c,a);for(var g=0,i=f.length;i>g;){if(("length"!==f[g].name||!z(f[g].object))&&"__Jasmine_been_here_before__"!==f[g].name){var j=f[g].type;switch(j){case"new":j="add";break;case"deleted":j="delete";break;case"updated":j="update"}v[j].call(f[g],d,e(h,f[g].object))}g++}d&&b&&b(d),c.patches=d,d=[]};else if(c={},i.value=JSON.parse(JSON.stringify(a)),b){c.callback=b,c.next=null;var j=this.intervals||[100,1e3,1e4,6e4];if(void 0===j.push)throw new Error("jsonpatch.intervals must be an array");var n=0,o=function(){m(c)},p=function(){clearTimeout(c.next),c.next=setTimeout(function(){o(),n=0,c.next=setTimeout(q,j[n++])},0)},q=function(){o(),n==j.length&&(n=j.length-1),c.next=setTimeout(q,j[n++])};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mousedown",p),window.addEventListener("mouseup",p),window.addEventListener("keydown",p)):(window.attachEvent("onmousedown",p),window.attachEvent("onmouseup",p),window.attachEvent("onkeydown",p))),c.next=setTimeout(q,j[n++])}return c.patches=d,c.object=a,i.observers.push(new y(b,c)),k(c,a)}function k(a,b){if(Object.observe){Object.observe(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&k(a,d)}}return a}function l(a,b){if(Object.observe){Object.unobserve(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&l(a,d)}}return a}function m(a){if(Object.observe)Object.deliverChangeRecords(a);else{for(var b,c=0,d=w.length;d>c;c++)if(w[c].obj===a.object){b=w[c];break}n(b.value,a.object,a.patches,"")}var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function n(a,b,d,e){for(var f=r(b),g=r(a),h=!1,i=!1,j=g.length-1;j>=0;j--){var k=g[j],l=a[k];if(b.hasOwnProperty(k)){var m=b[k];l instanceof Object?n(l,m,d,e+"/"+c(k)):l!=m&&(h=!0,d.push({op:"replace",path:e+"/"+c(k),value:m}),a[k]=m)}else d.push({op:"remove",path:e+"/"+c(k)}),delete a[k],i=!0}if(i||f.length!=g.length)for(var j=0;j<f.length;j++){var k=f[j];a.hasOwnProperty(k)||(d.push({op:"add",path:e+"/"+c(k),value:b[k]}),a[k]=JSON.parse(JSON.stringify(b[k])))}}function o(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 p(a,b){for(var c,d=!1,e=0,f=b.length;f>e;){c=b[e],e++;var g=c.path.split("/"),h=a,i=1,j=g.length;if(void 0===c.value&&("add"===c.op||"replace"===c.op||"test"===c.op))throw new Error("'value' MUST be defined");if(void 0===c.from&&("copy"===c.op||"move"===c.op))throw new Error("'from' MUST be defined");for(;;)if(z(h)){var k;if("-"===g[i])k=h.length;else{if(!o(g[i]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");k=parseInt(g[i],10)}if(i++,i>=j){d=t[c.op].call(c,h,k,a);break}h=h[k]}else{var l=g[i];if(void 0!==l){if(l&&-1!=l.indexOf("~")&&(l=l.replace(/~1/g,"/").replace(/~0/g,"~")),i++,i>=j){d=s[c.op].call(c,h,l,a);break}}else if(i++,i>=j){d=u[c.op].call(c,h,l,a);break}h=h[l]}}return d}function q(a,b){var c=[];return n(a,b,c,""),c}var r=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),s={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var d={op:"_get",path:this.from};return p(c,[d]),p(c,[{op:"remove",path:this.from}]),p(c,[{op:"add",path:this.path,value:d.value}]),!0},copy:function(a,b,c){var d={op:"_get",path:this.from};return p(c,[d]),p(c,[{op:"add",path:this.path,value:d.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},t={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},move:s.move,copy:s.copy,test:s.test,_get:s._get},u={add:function(a){u.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&s.remove.call(this,a,b);return!0},replace:function(a){return p(a,[{op:"remove",path:this.path}]),p(a,[{op:"add",path:this.path,value:this.value}]),!0},move:s.move,copy:s.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:s._get},v={add:function(a,b){var d={op:"add",path:b+c(this.name),value:this.object[this.name]};a.push(d)},"delete":function(a,b){var d={op:"remove",path:b+c(this.name)};a.push(d)},update:function(a,b){var d={op:"replace",path:b+c(this.name),value:this.object[this.name]};a.push(d)}},w=[];a.intervals;var 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=i,a.observe=j,a.generate=m;var z;z=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=p,a.compare=q}(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); | ||
//# sourceMappingURL=json-patch-duplex.min.js.map | ||
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(A(a)){if(!A(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,b){var e;for(var f in a)if(a.hasOwnProperty(f)){if(a[f]===b)return c(f)+"/";if("object"==typeof a[f]&&(e=d(a[f],b),""!=e))return c(f)+"/"+e}return""}function e(a,b){if(a===b)return"/";var c=d(a,b);if(""===c)throw new Error("Object not found in root");return"/"+c}function f(a){for(var b=0,c=x.length;c>b;b++)if(x[b].obj===a)return x[b]}function g(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 h(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 i(a,b){n(b),Object.observe?m(b,a):clearTimeout(b.next);var c=f(a);h(c,b)}function j(a){return"object"==typeof a?JSON.parse(JSON.stringify(a)):a}function k(a,b){var c,d=[],h=a,i=f(a);if(i?c=g(i,b):(i=new y(a),x.push(i)),c)return c;if(Object.observe)c=function(f){m(c,a),l(c,a);for(var g=0,i=f.length;i>g;){if(("length"!==f[g].name||!A(f[g].object))&&"__Jasmine_been_here_before__"!==f[g].name){var j=f[g].type;switch(j){case"new":j="add";break;case"deleted":j="delete";break;case"updated":j="update"}w[j].call(f[g],d,e(h,f[g].object))}g++}d&&b&&b(d),c.patches=d,d=[]};else if(c={},i.value=j(a),b){c.callback=b,c.next=null;var k=this.intervals||[100,1e3,1e4,6e4];if(void 0===k.push)throw new Error("jsonpatch.intervals must be an array");var o=0,p=function(){n(c)},q=function(){clearTimeout(c.next),c.next=setTimeout(function(){p(),o=0,c.next=setTimeout(r,k[o++])},0)},r=function(){p(),o==k.length&&(o=k.length-1),c.next=setTimeout(r,k[o++])};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mousedown",q),window.addEventListener("mouseup",q),window.addEventListener("keydown",q)):(window.attachEvent("onmousedown",q),window.attachEvent("onmouseup",q),window.attachEvent("onkeydown",q))),c.next=setTimeout(r,k[o++])}return c.patches=d,c.object=a,i.observers.push(new z(b,c)),l(c,a)}function l(a,b){if(Object.observe){Object.observe(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&l(a,d)}}return a}function m(a,b){if(Object.observe){Object.unobserve(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&m(a,d)}}return a}function n(a){if(Object.observe)Object.deliverChangeRecords(a);else{for(var b,c=0,d=x.length;d>c;c++)if(x[c].obj===a.object){b=x[c];break}o(b.value,a.object,a.patches,""),a.patches.length&&q(b.value,a.patches)}var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function o(a,b,d,e){for(var f=s(b),g=s(a),h=!1,i=!1,k=g.length-1;k>=0;k--){var l=g[k],m=a[l];if(b.hasOwnProperty(l)){var n=b[l];m instanceof Object?o(m,n,d,e+"/"+c(l)):m!=n&&(h=!0,d.push({op:"replace",path:e+"/"+c(l),value:j(n)}))}else d.push({op:"remove",path:e+"/"+c(l)}),i=!0}if(i||f.length!=g.length)for(var k=0;k<f.length;k++){var l=f[k];a.hasOwnProperty(l)||d.push({op:"add",path:e+"/"+c(l),value:j(b[l])})}}function p(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 q(a,b){for(var c,d=!1,e=0,f=b.length;f>e;){c=b[e],e++;var g=c.path.split("/"),h=a,i=1,j=g.length;if(void 0===c.value&&("add"===c.op||"replace"===c.op||"test"===c.op))throw new Error("'value' MUST be defined");if(void 0===c.from&&("copy"===c.op||"move"===c.op))throw new Error("'from' MUST be defined");for(;;)if(A(h)){var k;if("-"===g[i])k=h.length;else{if(!p(g[i]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");k=parseInt(g[i],10)}if(i++,i>=j){d=u[c.op].call(c,h,k,a);break}h=h[k]}else{var l=g[i];if(void 0!==l){if(l&&-1!=l.indexOf("~")&&(l=l.replace(/~1/g,"/").replace(/~0/g,"~")),i++,i>=j){d=t[c.op].call(c,h,l,a);break}}else if(i++,i>=j){d=v[c.op].call(c,h,l,a);break}h=h[l]}}return d}function r(a,b){var c=[];return o(a,b,c,""),c}if(!a.observe){var s=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),t={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var d={op:"_get",path:this.from};return q(c,[d]),q(c,[{op:"remove",path:this.from}]),q(c,[{op:"add",path:this.path,value:d.value}]),!0},copy:function(a,b,c){var d={op:"_get",path:this.from};return q(c,[d]),q(c,[{op:"add",path:this.path,value:d.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},u={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},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]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&t.remove.call(this,a,b);return!0},replace:function(a){return q(a,[{op:"remove",path:this.path}]),q(a,[{op:"add",path:this.path,value:this.value}]),!0},move:t.move,copy:t.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:t._get},w={add:function(a,b){var d={op:"add",path:b+c(this.name),value:this.object[this.name]};a.push(d)},"delete":function(a,b){var d={op:"remove",path:b+c(this.name)};a.push(d)},update:function(a,b){var d={op:"replace",path:b+c(this.name),value:this.object[this.name]};a.push(d)}},x=[];a.intervals;var y=function(){function a(a){this.observers=[],this.obj=a}return a}(),z=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=i,a.observe=k,a.generate=n;var A;A=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=q,a.compare=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); |
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.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(e(a)){if(!e(c)||a.length!==c.length)return!1;for(var d=0,g=a.length;g>d;d++)if(!b(a[d],c[d]))return!1;return!0}var h=f(c),i=h.length;if(f(a).length!==i)return!1;for(var d=0;i>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){for(var d,f=!1,j=0,k=b.length;k>j;){d=b[j],j++;var l=d.path.split("/"),m=a,n=1,o=l.length;if(void 0===d.value&&("add"===d.op||"replace"===d.op||"test"===d.op))throw new Error("'value' MUST be defined");if(void 0===d.from&&("copy"===d.op||"move"===d.op))throw new Error("'from' MUST be defined");for(;;)if(e(m)){var p;if("-"===l[n])p=m.length;else{if(!c(l[n]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");p=parseInt(l[n],10)}if(n++,n>=o){f=h[d.op].call(d,m,p,a);break}m=m[p]}else{var q=l[n];if(void 0!==q){if(q&&-1!=q.indexOf("~")&&(q=q.replace(/~1/g,"/").replace(/~0/g,"~")),n++,n>=o){f=g[d.op].call(d,m,q,a);break}}else if(n++,n>=o){f=i[d.op].call(d,m,q,a);break}m=m[q]}}return f}var e,f=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),g={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},copy:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},h={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},move:g.move,copy:g.copy,test:g.test,_get:g._get},i={add:function(a){i.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&g.remove.call(this,a,b);return!0},replace:function(a){return d(a,[{op:"remove",path:this.path}]),d(a,[{op:"add",path:this.path,value:this.value}]),!0},move:g.move,copy:g.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:g._get};e=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply); | ||
//# sourceMappingURL=json-patch.min.js.map | ||
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(e(a)){if(!e(c)||a.length!==c.length)return!1;for(var d=0,g=a.length;g>d;d++)if(!b(a[d],c[d]))return!1;return!0}var h=f(c),i=h.length;if(f(a).length!==i)return!1;for(var d=0;i>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){for(var d,f=!1,j=0,k=b.length;k>j;){d=b[j],j++;var l=d.path.split("/"),m=a,n=1,o=l.length;if(void 0===d.value&&("add"===d.op||"replace"===d.op||"test"===d.op))throw new Error("'value' MUST be defined");if(void 0===d.from&&("copy"===d.op||"move"===d.op))throw new Error("'from' MUST be defined");for(;;)if(e(m)){var p;if("-"===l[n])p=m.length;else{if(!c(l[n]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");p=parseInt(l[n],10)}if(n++,n>=o){f=h[d.op].call(d,m,p,a);break}m=m[p]}else{var q=l[n];if(void 0!==q){if(q&&-1!=q.indexOf("~")&&(q=q.replace(/~1/g,"/").replace(/~0/g,"~")),n++,n>=o){f=g[d.op].call(d,m,q,a);break}}else if(n++,n>=o){f=i[d.op].call(d,m,q,a);break}m=m[q]}}return f}if(!a.apply){var e,f=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),g={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},copy:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},h={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},move:g.move,copy:g.copy,test:g.test,_get:g._get},i={add:function(a){i.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&g.remove.call(this,a,b);return!0},replace:function(a){return d(a,[{op:"remove",path:this.path}]),d(a,[{op:"add",path:this.path,value:this.value}]),!0},move:g.move,copy:g.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:g._get};e=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d}}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply); |
{ | ||
"name": "fast-json-patch", | ||
"version": "0.4.0", | ||
"description": "JSON-Patch allows you to update a JSON document by sending the changes rather than the whole document.", | ||
"homepage": "https://github.com/Starcounter-Jack/JSON-Patch", | ||
"version": "0.5.0", | ||
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities", | ||
"homepage": "https://github.com/Starcounter-Jack/Fast-JSON-Patch", | ||
"keywords": [ | ||
@@ -14,6 +14,6 @@ "json", | ||
"type": "git", | ||
"url": "git://github.com/Starcounter-Jack/JSON-Patch.git" | ||
"url": "git://github.com/Starcounter-Jack/Fast-JSON-Patch.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Starcounter-Jack/JSON-Patch/issues" | ||
"url": "https://github.com/Starcounter-Jack/Fast-JSON-Patch/issues" | ||
}, | ||
@@ -20,0 +20,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
JSON-Patch | ||
Fast-JSON-Patch | ||
=============== | ||
@@ -25,3 +25,3 @@ | ||
* Allows you to freely manipulate object trees and then generate patches for outgoing traffic. | ||
* ES6/7 Object.observe() is used when available. | ||
* ES7 Object.observe() is used when available. | ||
* Tested in IE 8-10, Firefox, Chrome and Node.js | ||
@@ -28,0 +28,0 @@ |
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -9,2 +10,11 @@ * MIT license | ||
(function (jsonpatch) { | ||
/* Do nothing if module is already defined. | ||
Doesn't look nice, as we cannot simply put | ||
`!jsonpatch &&` before this immediate function call | ||
in TypeScript. | ||
*/ | ||
if (jsonpatch.observe) { | ||
return; | ||
} | ||
var _objectKeys = (function () { | ||
@@ -285,2 +295,10 @@ if (Object.keys) | ||
function deepClone(obj) { | ||
if (typeof obj === "object") { | ||
return JSON.parse(JSON.stringify(obj)); | ||
} else { | ||
return obj; | ||
} | ||
} | ||
function observe(obj, callback) { | ||
@@ -344,3 +362,3 @@ var patches = []; | ||
mirror.value = JSON.parse(JSON.stringify(obj)); // Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 | ||
mirror.value = deepClone(obj); | ||
@@ -440,2 +458,5 @@ if (callback) { | ||
_generate(mirror.value, observer.object, observer.patches, ""); | ||
if (observer.patches.length) { | ||
apply(mirror.value, observer.patches); | ||
} | ||
} | ||
@@ -470,4 +491,3 @@ var temp = observer.patches; | ||
changed = true; | ||
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: newVal }); | ||
mirror[key] = newVal; | ||
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal) }); | ||
} | ||
@@ -477,3 +497,2 @@ } | ||
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) }); | ||
delete mirror[key]; | ||
deleted = true; // property has been deleted | ||
@@ -490,4 +509,3 @@ } | ||
if (!mirror.hasOwnProperty(key)) { | ||
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: obj[key] }); | ||
mirror[key] = JSON.parse(JSON.stringify(obj[key])); | ||
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key]) }); | ||
} | ||
@@ -598,2 +616,1 @@ } | ||
} | ||
//# sourceMappingURL=json-patch-duplex.js.map |
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -14,2 +15,10 @@ * MIT license | ||
module jsonpatch { | ||
/* Do nothing if module is already defined. | ||
Doesn't look nice, as we cannot simply put | ||
`!jsonpatch &&` before this immediate function call | ||
in TypeScript. | ||
*/ | ||
if (jsonpatch.observe) { | ||
return; | ||
} | ||
@@ -296,2 +305,11 @@ | ||
function deepClone(obj:any) { | ||
if (typeof obj === "object") { | ||
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 | ||
} | ||
else { | ||
return obj; //no need to clone primitives | ||
} | ||
} | ||
export function observe(obj:any, callback):any { | ||
@@ -363,3 +381,3 @@ var patches = []; | ||
mirror.value = JSON.parse(JSON.stringify(obj)); // Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 | ||
mirror.value = deepClone(obj); | ||
@@ -460,2 +478,5 @@ if (callback) { | ||
_generate(mirror.value, observer.object, observer.patches, ""); | ||
if(observer.patches.length) { | ||
apply(mirror.value, observer.patches); | ||
} | ||
} | ||
@@ -492,4 +513,3 @@ var temp = observer.patches; | ||
changed = true; | ||
patches.push({op: "replace", path: path + "/" + escapePathComponent(key), value: newVal}); | ||
mirror[key] = newVal; | ||
patches.push({op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal)}); | ||
} | ||
@@ -500,3 +520,2 @@ } | ||
patches.push({op: "remove", path: path + "/" + escapePathComponent(key)}); | ||
delete mirror[key]; | ||
deleted = true; // property has been deleted | ||
@@ -513,4 +532,3 @@ } | ||
if (!mirror.hasOwnProperty(key)) { | ||
patches.push({op: "add", path: path + "/" + escapePathComponent(key), value: obj[key]}); | ||
mirror[key] = JSON.parse(JSON.stringify(obj[key])); | ||
patches.push({op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key])}); | ||
} | ||
@@ -517,0 +535,0 @@ } |
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -8,2 +9,11 @@ * MIT license | ||
(function (jsonpatch) { | ||
/* Do nothing if module is already defined. | ||
Doesn't look nice, as we cannot simply put | ||
`!jsonpatch &&` before this immediate function call | ||
in TypeScript. | ||
*/ | ||
if (jsonpatch.apply) { | ||
return; | ||
} | ||
var _objectKeys = (function () { | ||
@@ -10,0 +20,0 @@ if (Object.keys) |
/*! | ||
* json-patch-duplex.js 0.4.0 | ||
* https://github.com/Starcounter-Jack/Fast-JSON-Patch | ||
* json-patch-duplex.js 0.5.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -8,2 +9,10 @@ * MIT license | ||
module jsonpatch { | ||
/* Do nothing if module is already defined. | ||
Doesn't look nice, as we cannot simply put | ||
`!jsonpatch &&` before this immediate function call | ||
in TypeScript. | ||
*/ | ||
if (jsonpatch.apply) { | ||
return; | ||
} | ||
@@ -10,0 +19,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1632
0
69028
9