fast-json-patch
Advanced tools
Comparing version 0.3.10 to 0.4.0
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.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(y(a)){if(!y(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=q(c),g=f.length;if(q(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=v.length;c>b;b++)if(v[b].obj===a)return v[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 w(a),v.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||!y(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"}u[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 x(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=v.length;d>c;c++)if(v[c].obj===a.object){b=v[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=q(b),g=q(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,b){for(var c,d=!1,e=0,f=b.length;f>e;){c=b[e],e++;for(var g=c.path.split("/"),h=a,i=1,j=g.length;;)if(y(h)){var k=parseInt(g[i],10);if(i++,i>=j){d=s[c.op].call(c,h,k,a);break}h=h[k]}else{var l=g[i];if(l){if(l&&-1!=l.indexOf("~")&&(l=l.replace(/~1/g,"/").replace(/~0/g,"~")),i++,i>=j){d=r[c.op].call(c,h,l,a);break}}else if(i++,i>=j){d=t[c.op].call(c,h,l,a);break}h=h[l]}}return d}function p(a,b){var c=[];return n(a,b,c,""),c}var q=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),r={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 o(c,[d]),o(c,[{op:"remove",path:this.from}]),o(c,[{op:"add",path:this.path,value:d.value}]),!0},copy:function(a,b,c){var d={op:"_get",path:this.from};return o(c,[d]),o(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]}},s={add:function(a,b){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:r.move,copy:r.copy,test:r.test,_get:r._get},t={add:function(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)&&r.remove.call(this,a,b);return!0},replace:function(a){return o(a,[{op:"remove",path:this.path}]),o(a,[{op:"add",path:this.path,value:this.value}]),!0},move:r.move,copy:r.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:r._get},u={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)}},v=[];a.intervals;var w=function(){function a(a){this.observers=[],this.obj=a}return a}(),x=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=i,a.observe=j,a.generate=m;var y;y=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=o,a.compare=p}(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); | ||
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 |
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.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(d(a)){if(!d(c)||a.length!==c.length)return!1;for(var f=0,g=a.length;g>f;f++)if(!b(a[f],c[f]))return!1;return!0}var h=e(c),i=h.length;if(e(a).length!==i)return!1;for(var f=0;i>f;f++)if(!b(a[f],c[f]))return!1;return!0;default:return!1}}function c(a,b){for(var c,e=!1,i=0,j=b.length;j>i;){c=b[i],i++;for(var k=c.path.split("/"),l=a,m=1,n=k.length;;)if(d(l)){var o=parseInt(k[m],10);if(m++,m>=n){e=g[c.op].call(c,l,o,a);break}l=l[o]}else{var p=k[m];if(p){if(p&&-1!=p.indexOf("~")&&(p=p.replace(/~1/g,"/").replace(/~0/g,"~")),m++,m>=n){e=f[c.op].call(c,l,p,a);break}}else if(m++,m>=n){e=h[c.op].call(c,l,p,a);break}l=l[p]}}return e}var d,e=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),f={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,d){var e={op:"_get",path:this.from};return c(d,[e]),c(d,[{op:"remove",path:this.from}]),c(d,[{op:"add",path:this.path,value:e.value}]),!0},copy:function(a,b,d){var e={op:"_get",path:this.from};return c(d,[e]),c(d,[{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]}},g={add:function(a,b){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:f.move,copy:f.copy,test:f.test,_get:f._get},h={add:function(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)&&f.remove.call(this,a,b);return!0},replace:function(a){return c(a,[{op:"remove",path:this.path}]),c(a,[{op:"add",path:this.path,value:this.value}]),!0},move:f.move,copy:f.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:f._get};d=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=c}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply); | ||
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 |
{ | ||
"name": "fast-json-patch", | ||
"version": "0.3.10", | ||
"version": "0.4.0", | ||
"description": "JSON-Patch allows you to update a JSON document by sending the changes rather than the whole document.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch", |
@@ -109,9 +109,9 @@ JSON-Patch | ||
1. Testing **json-patch.js** | ||
- Load `src/patchtest.html` in your web browser | ||
- Load `test/SpecRunner.html` in your web browser | ||
2. Testing **json-patch-duplex.js** | ||
- Load `src/test-duplex.html` in your web browser | ||
- Load `test/SpecRunnerDuplex.html` in your web browser | ||
Each of the test suite files contains *Jasmine* unit test suite and *JSLitmus* performance test suite. | ||
Each of the test suite files contains *Jasmine* unit test suite and *Benchmark.js* performance test suite. | ||
To run *JSLitmus* performance tests, press "Run Tests" button. | ||
To run *Benchmark.js* performance tests, press "Run Tests" button. | ||
@@ -123,5 +123,5 @@ ### In Node.js | ||
3. Testing **json-patch.js** | ||
- Run command `jasmine-node --matchall --config duplex no src/test.js` | ||
- Run command `jasmine-node --matchall --config duplex no test/spec/coreSpec.js` | ||
4. Testing **json-patch-duplex.js** | ||
- Run command `jasmine-node --matchall --config duplex yes src/test.js src/test-duplex.js` | ||
- Run command `jasmine-node --matchall --config duplex yes test/spec/coreSpec.js test/spec/duplexSpec.js` | ||
@@ -140,3 +140,3 @@ ## API | ||
If there was more then one patch in the array, the result of the last patch is returned. | ||
If there was more than one patch in the array, the result of the last patch is returned. | ||
@@ -179,48 +179,2 @@ #### jsonpatch.observe (`obj` Object, `callback` Function (optional)) : `observer` Object | ||
#### 0.3.10 (Aug 21, 2014) | ||
Bugfix: | ||
- `test` operation failed of test if properties in two were ordered differently ([#39](https://github.com/Starcounter-Jack/JSON-Patch/issues/39)) | ||
- implement `add`, `replace`, `test`, `move`, `copy` operation on object root ([#40](https://github.com/Starcounter-Jack/JSON-Patch/issues/40), [#45](https://github.com/Starcounter-Jack/JSON-Patch/issues/45)) | ||
Upgraded test suite to use Benchmark.js instead of JSLitmus | ||
#### 0.3.9 (Aug 4, 2014) | ||
Feature: | ||
- expose method `jsonpatch.compare` for comparing two object trees | ||
#### 0.3.8 (Jul 18, 2014) | ||
Feature: | ||
- minified build now available in [dist/](https://github.com/Starcounter-Jack/JSON-Patch/tree/master/dist) directory ([#9](https://github.com/Starcounter-Jack/JSON-Patch/issues/9)) | ||
#### 0.3.7 (May 5, 2014) | ||
Feature: | ||
- add a new method `compare` ([#24](https://github.com/Starcounter-Jack/JSON-Patch/issues/24)) | ||
#### 0.3.6 (Nov 14, 2013) | ||
Update: | ||
- use the new record type names that landed in Chrome Canary (http://wiki.ecmascript.org/doku.php?id=harmony:observe - listed at 10/29/2013) | ||
#### 0.3.5 (Oct 28, 2013) | ||
Bugfix: | ||
- issues with calling observe/unobserve method on an object multiple times in Chrome (native Object.observe) ([#20](https://github.com/Starcounter-Jack/JSON-Patch/issues/20)) | ||
#### 0.3.4 (Oct 16, 2013) | ||
Bugfix: | ||
- generate array item `remove` patches in reverse order, so they can be correctly applied in order they were generated ([#16](https://github.com/Starcounter-Jack/JSON-Patch/issues/16)) | ||
#### 0.3.3 (Oct 11, 2013) | ||
Bugfixes: | ||
- properly escape `~` and `/` characters in poiner paths ([#19](https://github.com/Starcounter-Jack/JSON-Patch/pull/19)) | ||
- generated patch contained array `length` (only in native Object.observe version) ([#14](https://github.com/Starcounter-Jack/JSON-Patch/issues/14)) | ||
- `jsonpatch.unobserve` now delivers pending changes immediately (previously last-minute changes could be lost) | ||
- stability fixes for browsers with native `Object.observe` (Chrome) | ||
- code cleanup | ||
- removed sourcemap reference from output js file | ||
To see the list of recent changes, see [Releases](https://github.com/PuppetJs/PuppetJs/releases). |
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -111,2 +111,5 @@ * MIT license | ||
add: function (arr, i) { | ||
if (i > arr.length) { | ||
throw new Error("The specified index MUST NOT be greater than the number of elements in the array."); | ||
} | ||
arr.splice(i, 0, this.value); | ||
@@ -132,2 +135,3 @@ return true; | ||
add: function (obj) { | ||
rootOps.remove.call(this, obj); | ||
for (var key in this.value) { | ||
@@ -497,2 +501,18 @@ if (this.value.hasOwnProperty(key)) { | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str) { | ||
var i = 0; | ||
var len = str.length; | ||
var charCode; | ||
while (i < len) { | ||
charCode = str.charCodeAt(i); | ||
if (charCode >= 48 && charCode <= 57) { | ||
i++; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
/// Apply a json-patch operation on an object tree | ||
@@ -511,5 +531,19 @@ function apply(tree, patches) { | ||
if (patch.value === undefined && (patch.op === "add" || patch.op === "replace" || patch.op === "test")) { | ||
throw new Error("'value' MUST be defined"); | ||
} | ||
if (patch.from === undefined && (patch.op === "copy" || patch.op === "move")) { | ||
throw new Error("'from' MUST be defined"); | ||
} | ||
while (true) { | ||
if (_isArray(obj)) { | ||
var index = parseInt(keys[t], 10); | ||
var index; | ||
if (keys[t] === '-') { | ||
index = obj.length; | ||
} else if (isInteger(keys[t])) { | ||
index = parseInt(keys[t], 10); | ||
} else { | ||
throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index"); | ||
} | ||
t++; | ||
@@ -523,3 +557,3 @@ if (t >= len) { | ||
var key = keys[t]; | ||
if (key) { | ||
if (key !== undefined) { | ||
if (key && key.indexOf('~') != -1) | ||
@@ -526,0 +560,0 @@ key = key.replace(/~1/g, '/').replace(/~0/g, '~'); // escape chars |
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -16,3 +16,3 @@ * MIT license | ||
var _objectKeys = (function() { | ||
var _objectKeys = (function () { | ||
if (Object.keys) | ||
@@ -68,9 +68,9 @@ return Object.keys; | ||
/* We use a Javascript hash to store each | ||
function. Each hash entry (property) uses | ||
the operation identifiers specified in rfc6902. | ||
In this way, we can map each patch operation | ||
to its dedicated function in efficient way. | ||
*/ | ||
/* We use a Javascript hash to store each | ||
function. Each hash entry (property) uses | ||
the operation identifiers specified in rfc6902. | ||
In this way, we can map each patch operation | ||
to its dedicated function in efficient way. | ||
*/ | ||
/* The operations applicable to an object */ | ||
@@ -120,2 +120,5 @@ var objOps = { | ||
add: function (arr, i) { | ||
if (i > arr.length) { | ||
throw new Error("The specified index MUST NOT be greater than the number of elements in the array."); | ||
} | ||
arr.splice(i, 0, this.value); | ||
@@ -141,2 +144,3 @@ return true; | ||
add: function (obj) { | ||
rootOps.remove.call(this, obj); | ||
for (var key in this.value) { | ||
@@ -523,2 +527,18 @@ if (this.value.hasOwnProperty(key)) { | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str:string):boolean { | ||
var i = 0; | ||
var len = str.length; | ||
var charCode; | ||
while (i < len) { | ||
charCode = str.charCodeAt(i); | ||
if (charCode >= 48 && charCode <= 57) { | ||
i++; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
/// Apply a json-patch operation on an object tree | ||
@@ -539,5 +559,21 @@ export function apply(tree:any, patches:any[]):boolean { | ||
if (patch.value === undefined && (patch.op === "add" || patch.op === "replace" || patch.op === "test")) { | ||
throw new Error("'value' MUST be defined"); | ||
} | ||
if (patch.from === undefined && (patch.op === "copy" || patch.op === "move")) { | ||
throw new Error("'from' MUST be defined"); | ||
} | ||
while (true) { | ||
if (_isArray(obj)) { | ||
var index = parseInt(keys[t], 10); | ||
var index; | ||
if (keys[t] === '-') { | ||
index = obj.length; | ||
} | ||
else if (isInteger(keys[t])) { | ||
index = parseInt(keys[t], 10); | ||
} | ||
else { | ||
throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index"); | ||
} | ||
t++; | ||
@@ -552,3 +588,3 @@ if (t >= len) { | ||
var key = keys[t]; | ||
if(key) { | ||
if (key !== undefined) { | ||
if (key && key.indexOf('~') != -1) | ||
@@ -555,0 +591,0 @@ key = key.replace(/~1/g, '/').replace(/~0/g, '~'); // escape chars |
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -60,2 +60,9 @@ * MIT license | ||
/* We use a Javascript hash to store each | ||
function. Each hash entry (property) uses | ||
the operation identifiers specified in rfc6902. | ||
In this way, we can map each patch operation | ||
to its dedicated function in efficient way. | ||
*/ | ||
/* The operations applicable to an object */ | ||
var objOps = { | ||
@@ -101,4 +108,8 @@ add: function (obj, key) { | ||
/* The operations applicable to an array. Many are the same as for the object */ | ||
var arrOps = { | ||
add: function (arr, i) { | ||
if (i > arr.length) { | ||
throw new Error("The specified index MUST NOT be greater than the number of elements in the array."); | ||
} | ||
arr.splice(i, 0, this.value); | ||
@@ -124,2 +135,3 @@ return true; | ||
add: function (obj) { | ||
rootOps.remove.call(this, obj); | ||
for (var key in this.value) { | ||
@@ -166,2 +178,18 @@ if (this.value.hasOwnProperty(key)) { | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str) { | ||
var i = 0; | ||
var len = str.length; | ||
var charCode; | ||
while (i < len) { | ||
charCode = str.charCodeAt(i); | ||
if (charCode >= 48 && charCode <= 57) { | ||
i++; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
/// Apply a json-patch operation on an object tree | ||
@@ -180,5 +208,19 @@ function apply(tree, patches) { | ||
if (patch.value === undefined && (patch.op === "add" || patch.op === "replace" || patch.op === "test")) { | ||
throw new Error("'value' MUST be defined"); | ||
} | ||
if (patch.from === undefined && (patch.op === "copy" || patch.op === "move")) { | ||
throw new Error("'from' MUST be defined"); | ||
} | ||
while (true) { | ||
if (_isArray(obj)) { | ||
var index = parseInt(keys[t], 10); | ||
var index; | ||
if (keys[t] === '-') { | ||
index = obj.length; | ||
} else if (isInteger(keys[t])) { | ||
index = parseInt(keys[t], 10); | ||
} else { | ||
throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index"); | ||
} | ||
t++; | ||
@@ -192,3 +234,3 @@ if (t >= len) { | ||
var key = keys[t]; | ||
if (key) { | ||
if (key !== undefined) { | ||
if (key && key.indexOf('~') != -1) | ||
@@ -195,0 +237,0 @@ key = key.replace(/~1/g, '/').replace(/~0/g, '~'); // escape chars |
/*! | ||
* json-patch-duplex.js 0.3.10 | ||
* json-patch-duplex.js 0.4.0 | ||
* (c) 2013 Joachim Wester | ||
@@ -10,3 +10,3 @@ * MIT license | ||
var _objectKeys = (function() { | ||
var _objectKeys = (function () { | ||
if (Object.keys) | ||
@@ -62,2 +62,10 @@ return Object.keys; | ||
/* We use a Javascript hash to store each | ||
function. Each hash entry (property) uses | ||
the operation identifiers specified in rfc6902. | ||
In this way, we can map each patch operation | ||
to its dedicated function in efficient way. | ||
*/ | ||
/* The operations applicable to an object */ | ||
var objOps = { | ||
@@ -103,4 +111,8 @@ add: function (obj, key) { | ||
/* The operations applicable to an array. Many are the same as for the object */ | ||
var arrOps = { | ||
add: function (arr, i) { | ||
if (i > arr.length) { | ||
throw new Error("The specified index MUST NOT be greater than the number of elements in the array."); | ||
} | ||
arr.splice(i, 0, this.value); | ||
@@ -126,2 +138,3 @@ return true; | ||
add: function (obj) { | ||
rootOps.remove.call(this, obj); | ||
for (var key in this.value) { | ||
@@ -169,2 +182,18 @@ if (this.value.hasOwnProperty(key)) { | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str:string):boolean { | ||
var i = 0; | ||
var len = str.length; | ||
var charCode; | ||
while (i < len) { | ||
charCode = str.charCodeAt(i); | ||
if (charCode >= 48 && charCode <= 57) { | ||
i++; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
/// Apply a json-patch operation on an object tree | ||
@@ -185,5 +214,21 @@ export function apply(tree:any, patches:any[]):boolean { | ||
if (patch.value === undefined && (patch.op === "add" || patch.op === "replace" || patch.op === "test")) { | ||
throw new Error("'value' MUST be defined"); | ||
} | ||
if (patch.from === undefined && (patch.op === "copy" || patch.op === "move")) { | ||
throw new Error("'from' MUST be defined"); | ||
} | ||
while (true) { | ||
if (_isArray(obj)) { | ||
var index = parseInt(keys[t], 10); | ||
var index; | ||
if (keys[t] === '-') { | ||
index = obj.length; | ||
} | ||
else if (isInteger(keys[t])) { | ||
index = parseInt(keys[t], 10); | ||
} | ||
else { | ||
throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index"); | ||
} | ||
t++; | ||
@@ -198,3 +243,3 @@ if (t >= len) { | ||
var key = keys[t]; | ||
if(key) { | ||
if (key !== undefined) { | ||
if (key && key.indexOf('~') != -1) | ||
@@ -227,2 +272,2 @@ key = key.replace(/~1/g, '/').replace(/~0/g, '~'); // escape chars | ||
exports.apply = jsonpatch.apply; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
197254
25
1616
177