immutable-json-patch
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -19,3 +19,5 @@ "use strict"; | ||
function isJSONObject(value) { | ||
return value !== null && typeof value === 'object' && value.constructor === Object // do not match on classes or Array | ||
return value !== null && typeof value === 'object' && (value.constructor === undefined || | ||
// for example Object.create(null) | ||
value.constructor.name === 'Object') // do not match on classes or Array | ||
; | ||
@@ -22,0 +24,0 @@ } |
@@ -5,3 +5,5 @@ export function isJSONArray(value) { | ||
export function isJSONObject(value) { | ||
return value !== null && typeof value === 'object' && value.constructor === Object // do not match on classes or Array | ||
return value !== null && typeof value === 'object' && (value.constructor === undefined || | ||
// for example Object.create(null) | ||
value.constructor.name === 'Object') // do not match on classes or Array | ||
; | ||
@@ -8,0 +10,0 @@ } |
@@ -11,3 +11,5 @@ (function (global, factory) { | ||
function isJSONObject(value) { | ||
return value !== null && typeof value === 'object' && value.constructor === Object // do not match on classes or Array | ||
return value !== null && typeof value === 'object' && (value.constructor === undefined || | ||
// for example Object.create(null) | ||
value.constructor.name === 'Object') // do not match on classes or Array | ||
; | ||
@@ -14,0 +16,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).immutableJSONPatch={})}(this,function(e){"use strict";function p(e){return Array.isArray(e)}function s(e){return null!==e&&"object"==typeof e&&e.constructor===Object}function c(e,t){return e===t}function r(e){return e.slice(0,e.length-1)}function o(e){return"object"==typeof e&&null!==e}function l(t){if(p(t)){const r=t.slice();return Object.getOwnPropertySymbols(t).forEach(e=>{r[e]=t[e]}),r}if(s(t)){const n={...t};return Object.getOwnPropertySymbols(t).forEach(e=>{n[e]=t[e]}),n}return t}function i(e,t,r){return e[t]===r?e:((e=l(e))[t]=r,e)}function h(e,t){let r=e,n=0;for(;n<t.length;)r=s(r)?r[t[n]]:p(r)?r[parseInt(t[n])]:void 0,n++;return r}function d(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(0===t.length)return r;var o=t[0],t=d(e?e[o]:void 0,t.slice(1),r,n);if(s(e)||p(e))return i(e,o,t);if(n)return(r=f.test(o)?[]:{})[o]=t,r;throw new Error("Path does not exist")}const f=/^\d+$/;function a(e,t,r){if(0===t.length)return r(e);var n;if(o(e))return i(e,n=t[0],a(e[n],t.slice(1),r));throw new Error("Path doesn't exist")}function g(e,t){if(0===t.length)return e;if(!o(e))throw new Error("Path does not exist");if(1===t.length){const r=t[0];return r in e?(p(n=l(e))&&n.splice(parseInt(r),1),s(n)&&delete n[r],n):e}const r=t[0];var n=g(e[r],t.slice(1));return i(e,r,n)}function v(e,t,r){const n=t.slice(0,t.length-1),o=t[t.length-1];return a(e,n,e=>{if(Array.isArray(e))return(e=l(e)).splice(parseInt(o),0,r),e;throw new TypeError("Array expected at path "+JSON.stringify(n))})}function y(e,t){return void 0!==e&&(0===t.length||null!==e&&y(e[t[0]],t.slice(1)))}function n(e){e=e.split("/");return e.shift(),e.map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~"))}function m(e){return e.map(u).join("")}function u(e){return"/"+String(e).replace(/~/g,"~0").replace(/\//g,"~1")}function O(e,r,n){let o=e;for(let t=0;t<r.length;t++){i=void 0;var i=r[t];if(!["add","remove","replace","copy","move","test"].includes(i.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(i.op));if("string"!=typeof i.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(i));if(("copy"===i.op||"move"===i.op)&&"string"!=typeof i.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(i));let e=r[t];if(n&&n.before){i=n.before(o,e);if(void 0!==i){if(void 0!==i.document&&(o=i.document),void 0!==i.json)throw new Error('Deprecation warning: returned object property ".json" has been renamed to ".document"');void 0!==i.operation&&(e=i.operation)}}var i=o,f=S(o,e.path);if("add"===e.op)o=(p=o,s=f,l=e.value,(w(p,s)?v:d)(p,s,l));else if("remove"===e.op)o=g(o,f);else if("replace"===e.op)o=(p=o,s=e.value,d(p,f,s));else if("copy"===e.op)o=function(e,t,r){const n=h(e,r);{if(w(e,t))return v(e,t,n);{const n=h(e,r);return d(e,t,n)}}}(o,f,b(e.from));else if("move"===e.op)o=(l=o,c=f,a=b(e.from),u=void 0,u=h(l,a),(w(l=g(l,a),c)?v:d)(l,c,u));else{if("test"!==e.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(e));u=c=a=void 0;a=o,c=f,u=e.value;if(void 0===u)throw new Error(`Test failed: no value provided (path: "${m(c)}")`);if(!y(a,c))throw new Error(`Test failed: path not found (path: "${m(c)}")`);if(!function(e,t){return JSON.stringify(e)===JSON.stringify(t)}(a=h(a,c),u))throw new Error(`Test failed, value differs (path: "${m(c)}")`)}n&&n.after&&void 0!==(f=n.after(o,e,i))&&(o=f)}var c,a,u,p,s,l;return o}function w(e,t){if(0!==t.length)return e=h(e,r(t)),Array.isArray(e)}function S(e,t){return e=e,"-"!==(t=n(t))[t.length-1]?t:(t=h(e,e=r(t)),e.concat(t.length))}function b(e){return n(e)}function J(e,t){return[{op:"replace",path:m(t),value:h(e,t)}]}function N(e,t){return[{op:"add",path:m(t),value:h(e,t)}]}function P(e,t){return w(e,t)||!y(e,t)?[{op:"remove",path:m(t)}]:J(e,t)}e.appendToJSONPointer=function(e,t){return e+u(t)},e.compileJSONPointer=m,e.compileJSONPointerProp=u,e.deleteIn=g,e.existsIn=y,e.getIn=h,e.immutableJSONPatch=O,e.insertAt=v,e.isJSONArray=p,e.isJSONObject=s,e.isJSONPatchAdd=function(e){return!(!e||"object"!=typeof e)&&"add"===e.op},e.isJSONPatchCopy=function(e){return!(!e||"object"!=typeof e)&&"copy"===e.op},e.isJSONPatchMove=function(e){return!(!e||"object"!=typeof e)&&"move"===e.op},e.isJSONPatchOperation=function(e){return!(!e||"object"!=typeof e)&&"string"==typeof e.op},e.isJSONPatchRemove=function(e){return!(!e||"object"!=typeof e)&&"remove"===e.op},e.isJSONPatchReplace=function(e){return!(!e||"object"!=typeof e)&&"replace"===e.op},e.isJSONPatchTest=function(e){return!(!e||"object"!=typeof e)&&"test"===e.op},e.parseFrom=b,e.parseJSONPointer=n,e.parsePath=S,e.revertJSONPatch=function(e,t,i){let f=[];return O(e,t,{before:(e,t)=>{let r;var n=S(e,t.path);if("add"===t.op)r=P(e,n);else if("remove"===t.op)r=N(e,n);else if("replace"===t.op)r=J(e,n);else if("copy"===t.op)r=P(e,n);else if("move"===t.op)r=function(e,t,r){if(t.length<r.length&&function(t,r,e){var n=2<arguments.length&&void 0!==e?e:c;if(!(t.length<r.length)){for(let e=0;e<r.length;e++)if(!n(t[e],r[e]))return;return 1}}(r,t))return[{op:"replace",path:m(t),value:e}];r={op:"move",from:m(t),path:m(r)};return!w(e,t)&&y(e,t)?[r,...N(e,t)]:[r]}(e,n,b(t.from));else{if("test"!==t.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(t));r=[]}let o;if(i&&i.before){n=i.before(e,t,r);if(n&&n.revertOperations&&(r=n.revertOperations),n&&n.document&&(o=n.document),n&&n.json)throw new Error('Deprecation warning: returned object property ".json" has been renamed to ".document"')}if(f=r.concat(f),void 0!==o)return{document:o}}}),f},e.setIn=d,e.startsWithJSONPointer=function(e,t){return e.startsWith(t)&&(e.length===t.length||"/"===e[t.length])},e.transform=function r(e,n){var t,o,i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],f=n(e,i);if(p(f)){let t;for(let e=0;e<f.length;e++){var c=f[e],a=r(c,n,i.concat(e+""));a!==c&&((t=t||l(f))[e]=a)}return t||f}if(s(f)){let e;for(const u in f)Object.hasOwnProperty.call(f,u)&&(o=r(t=f[u],n,i.concat(u)))!==t&&((e=e||l(f))[u]=o);return e||f}return f},e.updateIn=a}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).immutableJSONPatch={})}(this,function(e){"use strict";function p(e){return Array.isArray(e)}function s(e){return null!==e&&"object"==typeof e&&(void 0===e.constructor||"Object"===e.constructor.name)}function c(e,t){return e===t}function r(e){return e.slice(0,e.length-1)}function o(e){return"object"==typeof e&&null!==e}function l(t){if(p(t)){const r=t.slice();return Object.getOwnPropertySymbols(t).forEach(e=>{r[e]=t[e]}),r}if(s(t)){const n={...t};return Object.getOwnPropertySymbols(t).forEach(e=>{n[e]=t[e]}),n}return t}function i(e,t,r){return e[t]===r?e:((e=l(e))[t]=r,e)}function h(e,t){let r=e,n=0;for(;n<t.length;)r=s(r)?r[t[n]]:p(r)?r[parseInt(t[n])]:void 0,n++;return r}function d(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(0===t.length)return r;var o=t[0],t=d(e?e[o]:void 0,t.slice(1),r,n);if(s(e)||p(e))return i(e,o,t);if(n)return(r=f.test(o)?[]:{})[o]=t,r;throw new Error("Path does not exist")}const f=/^\d+$/;function a(e,t,r){if(0===t.length)return r(e);var n;if(o(e))return i(e,n=t[0],a(e[n],t.slice(1),r));throw new Error("Path doesn't exist")}function v(e,t){if(0===t.length)return e;if(!o(e))throw new Error("Path does not exist");if(1===t.length){const r=t[0];return r in e?(p(n=l(e))&&n.splice(parseInt(r),1),s(n)&&delete n[r],n):e}const r=t[0];var n=v(e[r],t.slice(1));return i(e,r,n)}function g(e,t,r){const n=t.slice(0,t.length-1),o=t[t.length-1];return a(e,n,e=>{if(Array.isArray(e))return(e=l(e)).splice(parseInt(o),0,r),e;throw new TypeError("Array expected at path "+JSON.stringify(n))})}function y(e,t){return void 0!==e&&(0===t.length||null!==e&&y(e[t[0]],t.slice(1)))}function n(e){e=e.split("/");return e.shift(),e.map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~"))}function m(e){return e.map(u).join("")}function u(e){return"/"+String(e).replace(/~/g,"~0").replace(/\//g,"~1")}function O(e,r,n){let o=e;for(let t=0;t<r.length;t++){i=void 0;var i=r[t];if(!["add","remove","replace","copy","move","test"].includes(i.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(i.op));if("string"!=typeof i.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(i));if(("copy"===i.op||"move"===i.op)&&"string"!=typeof i.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(i));let e=r[t];if(n&&n.before){i=n.before(o,e);if(void 0!==i){if(void 0!==i.document&&(o=i.document),void 0!==i.json)throw new Error('Deprecation warning: returned object property ".json" has been renamed to ".document"');void 0!==i.operation&&(e=i.operation)}}var i=o,f=S(o,e.path);if("add"===e.op)o=(p=o,s=f,l=e.value,(w(p,s)?g:d)(p,s,l));else if("remove"===e.op)o=v(o,f);else if("replace"===e.op)o=(p=o,s=e.value,d(p,f,s));else if("copy"===e.op)o=function(e,t,r){const n=h(e,r);{if(w(e,t))return g(e,t,n);{const n=h(e,r);return d(e,t,n)}}}(o,f,b(e.from));else if("move"===e.op)o=(l=o,c=f,a=b(e.from),u=void 0,u=h(l,a),(w(l=v(l,a),c)?g:d)(l,c,u));else{if("test"!==e.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(e));u=c=a=void 0;a=o,c=f,u=e.value;if(void 0===u)throw new Error(`Test failed: no value provided (path: "${m(c)}")`);if(!y(a,c))throw new Error(`Test failed: path not found (path: "${m(c)}")`);if(!function(e,t){return JSON.stringify(e)===JSON.stringify(t)}(a=h(a,c),u))throw new Error(`Test failed, value differs (path: "${m(c)}")`)}n&&n.after&&void 0!==(f=n.after(o,e,i))&&(o=f)}var c,a,u,p,s,l;return o}function w(e,t){if(0!==t.length)return e=h(e,r(t)),Array.isArray(e)}function S(e,t){return e=e,"-"!==(t=n(t))[t.length-1]?t:(t=h(e,e=r(t)),e.concat(t.length))}function b(e){return n(e)}function J(e,t){return[{op:"replace",path:m(t),value:h(e,t)}]}function N(e,t){return[{op:"add",path:m(t),value:h(e,t)}]}function P(e,t){return w(e,t)||!y(e,t)?[{op:"remove",path:m(t)}]:J(e,t)}e.appendToJSONPointer=function(e,t){return e+u(t)},e.compileJSONPointer=m,e.compileJSONPointerProp=u,e.deleteIn=v,e.existsIn=y,e.getIn=h,e.immutableJSONPatch=O,e.insertAt=g,e.isJSONArray=p,e.isJSONObject=s,e.isJSONPatchAdd=function(e){return!(!e||"object"!=typeof e)&&"add"===e.op},e.isJSONPatchCopy=function(e){return!(!e||"object"!=typeof e)&&"copy"===e.op},e.isJSONPatchMove=function(e){return!(!e||"object"!=typeof e)&&"move"===e.op},e.isJSONPatchOperation=function(e){return!(!e||"object"!=typeof e)&&"string"==typeof e.op},e.isJSONPatchRemove=function(e){return!(!e||"object"!=typeof e)&&"remove"===e.op},e.isJSONPatchReplace=function(e){return!(!e||"object"!=typeof e)&&"replace"===e.op},e.isJSONPatchTest=function(e){return!(!e||"object"!=typeof e)&&"test"===e.op},e.parseFrom=b,e.parseJSONPointer=n,e.parsePath=S,e.revertJSONPatch=function(e,t,i){let f=[];return O(e,t,{before:(e,t)=>{let r;var n=S(e,t.path);if("add"===t.op)r=P(e,n);else if("remove"===t.op)r=N(e,n);else if("replace"===t.op)r=J(e,n);else if("copy"===t.op)r=P(e,n);else if("move"===t.op)r=function(e,t,r){if(t.length<r.length&&function(t,r,e){var n=2<arguments.length&&void 0!==e?e:c;if(!(t.length<r.length)){for(let e=0;e<r.length;e++)if(!n(t[e],r[e]))return;return 1}}(r,t))return[{op:"replace",path:m(t),value:e}];r={op:"move",from:m(t),path:m(r)};return!w(e,t)&&y(e,t)?[r,...N(e,t)]:[r]}(e,n,b(t.from));else{if("test"!==t.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(t));r=[]}let o;if(i&&i.before){n=i.before(e,t,r);if(n&&n.revertOperations&&(r=n.revertOperations),n&&n.document&&(o=n.document),n&&n.json)throw new Error('Deprecation warning: returned object property ".json" has been renamed to ".document"')}if(f=r.concat(f),void 0!==o)return{document:o}}}),f},e.setIn=d,e.startsWithJSONPointer=function(e,t){return e.startsWith(t)&&(e.length===t.length||"/"===e[t.length])},e.transform=function r(e,n){var t,o,i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],f=n(e,i);if(p(f)){let t;for(let e=0;e<f.length;e++){var c=f[e],a=r(c,n,i.concat(e+""));a!==c&&((t=t||l(f))[e]=a)}return t||f}if(s(f)){let e;for(const u in f)Object.hasOwnProperty.call(f,u)&&(o=r(t=f[u],n,i.concat(u)))!==t&&((e=e||l(f))[u]=o);return e||f}return f},e.updateIn=a}); |
The ISC License | ||
Copyright (c) 2020-2023 by Jos de Jong | ||
Copyright (c) 2020-2024 by Jos de Jong | ||
@@ -5,0 +5,0 @@ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. |
{ | ||
"name": "immutable-json-patch", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "Immutable JSON patch with support for reverting operations", | ||
@@ -54,16 +54,16 @@ "repository": { | ||
"@babel/cli": "7.23.4", | ||
"@babel/core": "7.23.6", | ||
"@babel/core": "7.23.7", | ||
"@babel/plugin-transform-typescript": "7.23.6", | ||
"@babel/preset-env": "7.23.6", | ||
"@babel/preset-env": "7.23.8", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@types/mocha": "10.0.6", | ||
"@types/node": "20.10.4", | ||
"@typescript-eslint/eslint-plugin": "6.14.0", | ||
"@typescript-eslint/parser": "6.14.0", | ||
"@types/node": "20.11.5", | ||
"@typescript-eslint/eslint-plugin": "6.19.0", | ||
"@typescript-eslint/parser": "6.19.0", | ||
"cpy-cli": "5.0.0", | ||
"del-cli": "5.1.0", | ||
"eslint": "8.55.0", | ||
"eslint": "8.56.0", | ||
"eslint-config-standard": "17.1.0", | ||
"eslint-plugin-import": "2.29.0", | ||
"eslint-plugin-n": "16.4.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-n": "16.6.2", | ||
"eslint-plugin-node": "11.1.0", | ||
@@ -74,3 +74,3 @@ "eslint-plugin-promise": "6.1.1", | ||
"npm-run-all": "4.1.5", | ||
"rollup": "4.9.0", | ||
"rollup": "4.9.5", | ||
"ts-node": "10.9.2", | ||
@@ -77,0 +77,0 @@ "typescript": "5.3.3", |
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
258831
2459