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

fast-json-patch

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-patch - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

4

dist/json-patch-duplex.min.js
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js 0.5.1
* json-patch-duplex.js version: 0.5.2
* (c) 2013 Joachim Wester
* MIT license
*/
var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},OriginalError=Error,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(C(a)){if(!C(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=u(c),g=f.length;if(u(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 OriginalError("Object not found in root");return"/"+c}function f(a){for(var b=0,c=z.length;c>b;b++)if(z[b].obj===a)return z[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 A(a),z.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||!C(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"}y[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 OriginalError("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)):(document.documentElement.attachEvent("onmousedown",q),document.documentElement.attachEvent("onmouseup",q),document.documentElement.attachEvent("onkeydown",q))),c.next=setTimeout(r,k[o++])}return c.patches=d,c.object=a,i.observers.push(new B(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=z.length;d>c;c++)if(z[c].obj===a.object){b=z[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=u(b),g=u(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];"object"==typeof m&&null!=m&&"object"==typeof n&&null!=n?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,c){for(var d,e,f=!1,g=0,h=b.length;h>g;){d=b[g],g++;for(var i=d.path.split("/"),j=a,k=1,l=i.length,m=void 0;;){if(e=i[k],c&&void 0==m&&(void 0==j[e]?m=i.slice(0,k).join("/"):k==l-1&&(m=d.path),void 0!=m&&this.validator(d,g-1,a,m)),k++,void 0===e&&k>=l){f=x[d.op].call(d,j,e,a);break}if(C(j)){if("-"===e)e=j.length;else{if(c&&!p(e))throw new D("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(k>=l){if(c&&"add"===d.op&&e>j.length)throw new D("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=w[d.op].call(d,j,e,a);break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),k>=l){f=v[d.op].call(d,j,e,a);break}j=j[e]}}return f}function r(a,b){var c=[];return o(a,b,c,""),c}function s(b,c,d,e){if("object"!=typeof b||null===b||C(b))throw new D("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!v[b.op])throw new D("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 D("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new D("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 D("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",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 D("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 D("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 D("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function t(a,b){try{if(!C(a))throw new D("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),q.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(d){if(d instanceof D)return d;throw d}}if(!a.observe){var u=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),v={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]}},w={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:v.move,copy:v.copy,test:v.test,_get:v._get},x={add:function(a){x.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)&&v.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:v.move,copy:v.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},y={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)}},z=[];a.intervals;var A=function(){function a(a){this.observers=[],this.obj=a}return a}(),B=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=i,a.observe=k,a.generate=n;var C;C=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=q,a.compare=r;var D=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 __extends(b,a),b}(OriginalError);a.JsonPatchError=D,a.Error=D,a.validator=s,a.validate=t}}(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,exports.Error=jsonpatch.Error);
var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},OriginalError=Error,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(C(a)){if(!C(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=u(c),g=f.length;if(u(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 OriginalError("Object not found in root");return"/"+c}function f(a){for(var b=0,c=z.length;c>b;b++)if(z[b].obj===a)return z[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 A(a),z.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||!C(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"}y[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 OriginalError("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)):(document.documentElement.attachEvent("onmousedown",q),document.documentElement.attachEvent("onmouseup",q),document.documentElement.attachEvent("onkeydown",q))),c.next=setTimeout(r,k[o++])}return c.patches=d,c.object=a,i.observers.push(new B(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=z.length;d>c;c++)if(z[c].obj===a.object){b=z[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=u(b),g=u(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];"object"==typeof m&&null!=m&&"object"==typeof n&&null!=n?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,c){for(var d,e,f=!1,g=0,h=b.length;h>g;){d=b[g],g++;for(var i=d.path.split("/"),j=a,k=1,l=i.length,m=void 0;;){if(e=i[k],c&&void 0===m&&(void 0===j[e]?m=i.slice(0,k).join("/"):k==l-1&&(m=d.path),void 0!==m&&this.validator(d,g-1,a,m)),k++,void 0===e&&k>=l){f=x[d.op].call(d,j,e,a);break}if(C(j)){if("-"===e)e=j.length;else{if(c&&!p(e))throw new D("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(k>=l){if(c&&"add"===d.op&&e>j.length)throw new D("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=w[d.op].call(d,j,e,a);break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),k>=l){f=v[d.op].call(d,j,e,a);break}j=j[e]}}return f}function r(a,b){var c=[];return o(a,b,c,""),c}function s(b,c,d,e){if("object"!=typeof b||null===b||C(b))throw new D("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!v[b.op])throw new D("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 D("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new D("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 D("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",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 D("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 D("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 D("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function t(a,b){try{if(!C(a))throw new D("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),q.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(d){if(d instanceof D)return d;throw d}}if(!a.observe){var u=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),v={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]}},w={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:v.move,copy:v.copy,test:v.test,_get:v._get},x={add:function(a){x.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)&&v.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:v.move,copy:v.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},y={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)}},z=[];a.intervals;var A=function(){function a(a){this.observers=[],this.obj=a}return a}(),B=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=i,a.observe=k,a.generate=n;var C;C=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=q,a.compare=r;var D=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 __extends(b,a),b}(OriginalError);a.JsonPatchError=D,a.Error=D,a.validator=s,a.validate=t}}(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,exports.Error=jsonpatch.Error);
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js 0.5.1
* json-patch-duplex.js version: 0.5.2
* (c) 2013 Joachim Wester
* MIT license
*/
var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},OriginalError=Error,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(g(a)){if(!g(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=h(c),i=f.length;if(h(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,d){for(var e,f,h=!1,m=0,n=b.length;n>m;){e=b[m],m++;for(var o=e.path.split("/"),p=a,q=1,r=o.length,s=void 0;;){if(f=o[q],d&&void 0==s&&(void 0==p[f]?s=o.slice(0,q).join("/"):q==r-1&&(s=e.path),void 0!=s&&this.validator(e,m-1,a,s)),q++,void 0===f&&q>=r){h=k[e.op].call(e,p,f,a);break}if(g(p)){if("-"===f)f=p.length;else{if(d&&!c(f))throw new l("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",m-1,e.path,e);f=parseInt(f,10)}if(q>=r){if(d&&"add"===e.op&&f>p.length)throw new l("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",m-1,e.path,e);h=j[e.op].call(e,p,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),q>=r){h=i[e.op].call(e,p,f,a);break}p=p[f]}}return h}function e(b,c,d,e){if("object"!=typeof b||null===b||g(b))throw new l("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!i[b.op])throw new l("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 l("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new l("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 l("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,h=e.split("/").length;if(f!==h+1&&f!==h)throw new l("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 l("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},k=a.validate([j],d);if(k&&"OPERATION_PATH_UNRESOLVABLE"===k.name)throw new l("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function f(a,b){try{if(!g(a))throw new l("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(e){if(e instanceof l)return e;throw e}}if(!a.apply){var g,h=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),i={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]}},j={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:i.move,copy:i.copy,test:i.test,_get:i._get},k={add:function(a){k.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)&&i.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:i.move,copy:i.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};g=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var l=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 __extends(b,a),b}(OriginalError);a.JsonPatchError=l,a.Error=l,a.validator=e,a.validate=f}}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},OriginalError=Error,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(g(a)){if(!g(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=h(c),i=f.length;if(h(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,d){for(var e,f,h=!1,m=0,n=b.length;n>m;){e=b[m],m++;for(var o=e.path.split("/"),p=a,q=1,r=o.length,s=void 0;;){if(f=o[q],d&&void 0===s&&(void 0===p[f]?s=o.slice(0,q).join("/"):q==r-1&&(s=e.path),void 0!==s&&this.validator(e,m-1,a,s)),q++,void 0===f&&q>=r){h=k[e.op].call(e,p,f,a);break}if(g(p)){if("-"===f)f=p.length;else{if(d&&!c(f))throw new l("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",m-1,e.path,e);f=parseInt(f,10)}if(q>=r){if(d&&"add"===e.op&&f>p.length)throw new l("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",m-1,e.path,e);h=j[e.op].call(e,p,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),q>=r){h=i[e.op].call(e,p,f,a);break}p=p[f]}}return h}function e(b,c,d,e){if("object"!=typeof b||null===b||g(b))throw new l("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!i[b.op])throw new l("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 l("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new l("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 l("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,h=e.split("/").length;if(f!==h+1&&f!==h)throw new l("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 l("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},k=a.validate([j],d);if(k&&"OPERATION_PATH_UNRESOLVABLE"===k.name)throw new l("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function f(a,b){try{if(!g(a))throw new l("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(e){if(e instanceof l)return e;throw e}}if(!a.apply){var g,h=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),i={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]}},j={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:i.move,copy:i.copy,test:i.test,_get:i._get},k={add:function(a){k.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)&&i.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:i.move,copy:i.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};g=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var l=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 __extends(b,a),b}(OriginalError);a.JsonPatchError=l,a.Error=l,a.validator=e,a.validate=f}}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
(The MIT License)
Copyright (c) 2013, 2014 Joachim Wester <joachimwester@me.com>
Copyright (c) 2013, 2014 Joachim Wester

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining

{
"name": "fast-json-patch",
"version": "0.5.1",
"version": "0.5.2",
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",

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

"devDependencies": {
"grunt": "~0.4.5",
"grunt": "^0.4.5",
"grunt-bump": "^0.3.0",
"grunt-contrib-uglify": "~0.5.0"
}
}

@@ -0,0 +0,0 @@ JSON-Patch

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

@@ -558,4 +558,4 @@ * MIT license

if (validate) {
if (existingPathFragment == undefined) {
if (obj[key] == undefined) {
if (existingPathFragment === undefined) {
if (obj[key] === undefined) {
existingPathFragment = keys.slice(0, t).join('/');

@@ -565,3 +565,3 @@ } else if (t == len - 1) {

}
if (existingPathFragment != undefined) {
if (existingPathFragment !== undefined) {
this.validator(patch, p - 1, tree, existingPathFragment);

@@ -568,0 +568,0 @@ }

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

@@ -580,4 +580,4 @@ * MIT license

if (validate) {
if (existingPathFragment == undefined) {
if (obj[key] == undefined) {
if (existingPathFragment === undefined) {
if (obj[key] === undefined) {
existingPathFragment = keys.slice(0, t).join('/');

@@ -588,3 +588,3 @@ }

}
if (existingPathFragment != undefined) {
if (existingPathFragment !== undefined) {
this.validator(patch, p - 1, tree, existingPathFragment);

@@ -591,0 +591,0 @@ }

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

@@ -226,4 +226,4 @@ * MIT license

if (validate) {
if (existingPathFragment == undefined) {
if (obj[key] == undefined) {
if (existingPathFragment === undefined) {
if (obj[key] === undefined) {
existingPathFragment = keys.slice(0, t).join('/');

@@ -233,3 +233,3 @@ } else if (t == len - 1) {

}
if (existingPathFragment != undefined) {
if (existingPathFragment !== undefined) {
this.validator(patch, p - 1, tree, existingPathFragment);

@@ -236,0 +236,0 @@ }

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

@@ -225,4 +225,4 @@ * MIT license

if (validate) {
if (existingPathFragment == undefined) {
if (obj[key] == undefined) {
if (existingPathFragment === undefined) {
if (obj[key] === undefined) {
existingPathFragment = keys.slice(0, t).join('/');

@@ -233,3 +233,3 @@ }

}
if (existingPathFragment != undefined) {
if (existingPathFragment !== undefined) {
this.validator(patch, p - 1, tree, existingPathFragment);

@@ -236,0 +236,0 @@ }

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc