immutable-json-patch
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -18,3 +18,3 @@ "use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
@@ -21,0 +21,0 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
@@ -193,6 +193,9 @@ "use strict"; | ||
*/ | ||
// TODO: write unit tests | ||
function isArrayItem(json, path) { | ||
if (path.length === 0) { | ||
return false; | ||
} | ||
var parent = (0, _immutabilityHelpers.getIn)(json, (0, _utils.initial)(path)); | ||
@@ -199,0 +202,0 @@ return Array.isArray(parent); |
@@ -1,2 +0,2 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
@@ -3,0 +3,0 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
@@ -168,5 +168,8 @@ import { deleteIn, existsIn, getIn, insertAt, setIn } from './immutabilityHelpers.js'; | ||
*/ | ||
// TODO: write unit tests | ||
export function isArrayItem(json, path) { | ||
if (path.length === 0) { | ||
return false; | ||
} | ||
var parent = getIn(json, initial(path)); | ||
@@ -173,0 +176,0 @@ return Array.isArray(parent); |
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); } | ||
@@ -82,6 +82,6 @@ /** | ||
function isObjectOrArray(value) { | ||
return _typeof(value) === 'object' && value !== null; | ||
return _typeof$1(value) === 'object' && value !== null; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
@@ -92,3 +92,3 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
/** | ||
@@ -110,3 +110,3 @@ * Shallow clone of an Object, Array, or value | ||
return copy; | ||
} else if (_typeof$1(value) === 'object') { | ||
} else if (_typeof(value) === 'object') { | ||
// copy object properties | ||
@@ -505,5 +505,8 @@ var _copy = _objectSpread({}, value); // copy all symbols | ||
*/ | ||
// TODO: write unit tests | ||
function isArrayItem(json, path) { | ||
if (path.length === 0) { | ||
return false; | ||
} | ||
var parent = getIn(json, initial(path)); | ||
@@ -510,0 +513,0 @@ return Array.isArray(parent); |
@@ -1,1 +0,1 @@ | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).immutableJSONPatch={})}(this,function(r){"use strict";function t(r){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function i(r,t){return r===t}function a(r){return r.slice(0,r.length-1)}function u(r){return"object"===t(r)&&null!==r}function e(t,r){var e,n=Object.keys(t);return Object.getOwnPropertySymbols&&(e=Object.getOwnPropertySymbols(t),r&&(e=e.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),n.push.apply(n,e)),n}function o(n){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach(function(r){var t,e;t=n,r=o[e=r],e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(o,r))})}return n}function f(r){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function c(t){if(Array.isArray(t)){var e=t.slice();return Object.getOwnPropertySymbols(t).forEach(function(r){e[r]=t[r]}),e}if("object"!==f(t))return t;var n=o({},t);return Object.getOwnPropertySymbols(t).forEach(function(r){n[r]=t[r]}),n}function p(r,t,e){if(r[t]===e)return r;r=c(r);return r[t]=e,r}function l(r,t){for(var e=r,n=0;n<t.length;)e=u(e)?e[t[n]]:void 0,n++;return e}function s(r,t,e){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(0===t.length)return e;var o=t[0],e=s(r?r[o]:void 0,t.slice(1),e,n);if(u(r))return p(r,o,e);if(n){n="number"==typeof o?[]:{};return n[o]=e,n}throw new Error("Path does not exist")}function h(r,t,e){if(0===t.length)return e(r);if(!u(r))throw new Error("Path doesn't exist");var n=t[0];return p(r,n,h(r[n],t.slice(1),e))}function y(r,t){if(0===t.length)return r;if(!u(r))throw new Error("Path does not exist");if(1===t.length){var e=t[0];if(e in r){var n=c(r);return Array.isArray(n)?n.splice(e,1):delete n[e],n}return r}n=t[0];return p(r,n,y(r[n],t.slice(1)))}function v(r,t,e){var n=t.slice(0,t.length-1),o=t[t.length-1];return h(r,n,function(r){if(!Array.isArray(r))throw new TypeError("Array expected at path "+JSON.stringify(n));r=c(r);return r.splice(o,0,e),r})}function d(r,t){return void 0!==r&&(0===t.length||d(r[t[0]],t.slice(1)))}function g(r){r=r.split("/");return r.shift(),r.map(function(r){return r.replace(/~1/g,"/").replace(/~0/g,"~")})}function m(r){return r.map(function(r){return"/"+String(r).replace(/~/g,"~0").replace(/\//g,"~1")}).join("")}function b(r,t,e){for(var n=r,o=0;o<t.length;o++){!function(r){if(!["add","remove","replace","copy","move","test"].includes(r.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(r.op));if("string"!=typeof r.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(r));if(("copy"===r.op||"move"===r.op)&&"string"!=typeof r.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(r))}(t[o]);var i=(i=n,{op:(u=t[o]).op,path:function(r,t){if("-"!==function(r){return r[r.length-1]}(t))return t;t=a(t),r=l(r,t);return t.concat(r.length)}(i,g(u.path)),from:void 0!==u.from?g(u.from):null,value:u.value});e&&e.before&&(void 0!==(f=e.before(n,i))&&(void 0!==f.json&&(n=f.json),void 0!==f.operation&&(i=f.operation)));var u=n,f=O[i.op];if(f)n=f(n,i);else{if("test"!==i.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(i.op));!function(r,t){var e=t.path;if(void 0===(t=t.value))throw new Error('Test failed: no value provided (path: "'.concat(m(e),'")'));if(!d(r,e))throw new Error('Test failed: path not found (path: "'.concat(m(e),'")'));if(!function(r,t){return JSON.stringify(r)===JSON.stringify(t)}(l(r,e),t))throw new Error('Test failed, value differs (path: "'.concat(m(e),'")'))}(n,i)}e&&e.after&&(void 0!==(u=e.after(n,i,u))&&(n=u))}return n}var O={add:function(r,t){var e=t.path,t=t.value;return(w(r,e)?v:s)(r,e,t)},remove:function(r,t){t=t.path;return y(r,t)},replace:function(r,t){var e=t.path,t=t.value;return s(r,e,t)},copy:function(r,t){var e=t.path,n=t.from,t=l(r,n);{if(w(r,e))return v(r,e,t);n=l(r,n);return s(r,e,n)}},move:function(r,t){var e=t.path,n=t.from,t=l(r,n),n=y(r,n);return(w(n,e)?v:s)(n,e,t)}};function w(r,t){t=l(r,a(t));return Array.isArray(t)}var S={add:j,remove:P,replace:n,copy:function(r,t){var e=t.path,t=t.value;return j(r,{path:e,value:t})},move:function(r,t){var e=t.path,t=t.from;if(e.length<t.length&&function(r,t,e){var n=2<arguments.length&&void 0!==e?e:i;if(!(r.length<t.length)){for(var o=0;o<t.length;o++)if(!n(r[o],t[o]))return;return 1}}(t,e))return[{op:"replace",path:m(e),value:r}];t=[{op:"move",from:m(e),path:m(t)}];!w(r,e)&&d(r,e)&&(t=t.concat(P(r,{path:e})));return t}};function n(r,t){t=t.path;return[{op:"replace",path:m(t),value:l(r,t)}]}function P(r,t){t=t.path;return[{op:"add",path:m(t),value:l(r,t)}]}function j(r,t){var e=t.path,t=t.value;return w(r,e)||!d(r,e)?[{op:"remove",path:m(e)}]:n(r,{path:e,value:t})}r.compileJSONPointer=m,r.deleteIn=y,r.existsIn=d,r.getIn=l,r.immutableJSONPatch=b,r.insertAt=v,r.parseJSONPointer=g,r.revertJSONPatch=function(r,t){var n=[];return b(r,t,{before:function(r,t){var e=S[t.op];e&&(n=e(r,t).concat(n))}}),n},r.setIn=s,r.updateIn=h,Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).immutableJSONPatch={})}(this,function(r){"use strict";function t(r){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function i(r,t){return r===t}function a(r){return r.slice(0,r.length-1)}function u(r){return"object"===t(r)&&null!==r}function e(t,r){var e,n=Object.keys(t);return Object.getOwnPropertySymbols&&(e=Object.getOwnPropertySymbols(t),r&&(e=e.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),n.push.apply(n,e)),n}function o(n){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach(function(r){var t,e;t=n,r=o[e=r],e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(o,r))})}return n}function f(r){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function c(t){if(Array.isArray(t)){var e=t.slice();return Object.getOwnPropertySymbols(t).forEach(function(r){e[r]=t[r]}),e}if("object"!==f(t))return t;var n=o({},t);return Object.getOwnPropertySymbols(t).forEach(function(r){n[r]=t[r]}),n}function p(r,t,e){if(r[t]===e)return r;r=c(r);return r[t]=e,r}function l(r,t){for(var e=r,n=0;n<t.length;)e=u(e)?e[t[n]]:void 0,n++;return e}function s(r,t,e){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(0===t.length)return e;var o=t[0],e=s(r?r[o]:void 0,t.slice(1),e,n);if(u(r))return p(r,o,e);if(n){n="number"==typeof o?[]:{};return n[o]=e,n}throw new Error("Path does not exist")}function h(r,t,e){if(0===t.length)return e(r);if(!u(r))throw new Error("Path doesn't exist");var n=t[0];return p(r,n,h(r[n],t.slice(1),e))}function y(r,t){if(0===t.length)return r;if(!u(r))throw new Error("Path does not exist");if(1===t.length){var e=t[0];if(e in r){var n=c(r);return Array.isArray(n)?n.splice(e,1):delete n[e],n}return r}n=t[0];return p(r,n,y(r[n],t.slice(1)))}function v(r,t,e){var n=t.slice(0,t.length-1),o=t[t.length-1];return h(r,n,function(r){if(!Array.isArray(r))throw new TypeError("Array expected at path "+JSON.stringify(n));r=c(r);return r.splice(o,0,e),r})}function g(r,t){return void 0!==r&&(0===t.length||g(r[t[0]],t.slice(1)))}function d(r){r=r.split("/");return r.shift(),r.map(function(r){return r.replace(/~1/g,"/").replace(/~0/g,"~")})}function m(r){return r.map(function(r){return"/"+String(r).replace(/~/g,"~0").replace(/\//g,"~1")}).join("")}function b(r,t,e){for(var n=r,o=0;o<t.length;o++){!function(r){if(!["add","remove","replace","copy","move","test"].includes(r.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(r.op));if("string"!=typeof r.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(r));if(("copy"===r.op||"move"===r.op)&&"string"!=typeof r.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(r))}(t[o]);var i=(i=n,{op:(u=t[o]).op,path:function(r,t){if("-"!==function(r){return r[r.length-1]}(t))return t;t=a(t),r=l(r,t);return t.concat(r.length)}(i,d(u.path)),from:void 0!==u.from?d(u.from):null,value:u.value});e&&e.before&&(void 0!==(f=e.before(n,i))&&(void 0!==f.json&&(n=f.json),void 0!==f.operation&&(i=f.operation)));var u=n,f=O[i.op];if(f)n=f(n,i);else{if("test"!==i.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(i.op));!function(r,t){var e=t.path,t=t.value;if(void 0===t)throw new Error('Test failed: no value provided (path: "'.concat(m(e),'")'));if(!g(r,e))throw new Error('Test failed: path not found (path: "'.concat(m(e),'")'));if(!function(r,t){return JSON.stringify(r)===JSON.stringify(t)}(l(r,e),t))throw new Error('Test failed, value differs (path: "'.concat(m(e),'")'))}(n,i)}e&&e.after&&(void 0!==(u=e.after(n,i,u))&&(n=u))}return n}var O={add:function(r,t){var e=t.path,t=t.value;return(w(r,e)?v:s)(r,e,t)},remove:function(r,t){t=t.path;return y(r,t)},replace:function(r,t){var e=t.path,t=t.value;return s(r,e,t)},copy:function(r,t){var e=t.path,n=t.from,t=l(r,n);{if(w(r,e))return v(r,e,t);n=l(r,n);return s(r,e,n)}},move:function(r,t){var e=t.path,n=t.from,t=l(r,n),n=y(r,n);return(w(n,e)?v:s)(n,e,t)}};function w(r,t){if(0!==t.length){t=l(r,a(t));return Array.isArray(t)}}var S={add:j,remove:P,replace:n,copy:function(r,t){var e=t.path,t=t.value;return j(r,{path:e,value:t})},move:function(r,t){var e=t.path,t=t.from;if(e.length<t.length&&function(r,t,e){var n=2<arguments.length&&void 0!==e?e:i;if(!(r.length<t.length)){for(var o=0;o<t.length;o++)if(!n(r[o],t[o]))return;return 1}}(t,e))return[{op:"replace",path:m(e),value:r}];t=[{op:"move",from:m(e),path:m(t)}];!w(r,e)&&g(r,e)&&(t=t.concat(P(r,{path:e})));return t}};function n(r,t){t=t.path;return[{op:"replace",path:m(t),value:l(r,t)}]}function P(r,t){t=t.path;return[{op:"add",path:m(t),value:l(r,t)}]}function j(r,t){var e=t.path,t=t.value;return w(r,e)||!g(r,e)?[{op:"remove",path:m(e)}]:n(r,{path:e,value:t})}r.compileJSONPointer=m,r.deleteIn=y,r.existsIn=g,r.getIn=l,r.immutableJSONPatch=b,r.insertAt=v,r.parseJSONPointer=d,r.revertJSONPatch=function(r,t){var n=[];return b(r,t,{before:function(r,t){var e=S[t.op];e&&(n=e(r,t).concat(n))}}),n},r.setIn=s,r.updateIn=h,Object.defineProperty(r,"__esModule",{value:!0})}); |
{ | ||
"name": "immutable-json-patch", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Immutable JSON patch with support for reverting operations", | ||
@@ -44,17 +44,17 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/cli": "7.12.10", | ||
"@babel/core": "7.12.10", | ||
"@babel/preset-env": "7.12.11", | ||
"@babel/cli": "7.14.8", | ||
"@babel/core": "7.14.8", | ||
"@babel/preset-env": "7.14.8", | ||
"cpy-cli": "3.1.1", | ||
"del-cli": "3.0.1", | ||
"eslint": "7.18.0", | ||
"eslint-config-standard": "16.0.2", | ||
"eslint-plugin-import": "2.22.1", | ||
"del-cli": "4.0.1", | ||
"eslint": "7.31.0", | ||
"eslint-config-standard": "16.0.3", | ||
"eslint-plugin-import": "2.23.4", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-promise": "4.2.1", | ||
"mocha": "8.2.1", | ||
"rollup": "2.38.0", | ||
"uglify-js": "3.12.5" | ||
"eslint-plugin-promise": "5.1.0", | ||
"mocha": "9.0.2", | ||
"rollup": "2.53.3", | ||
"uglify-js": "3.14.0" | ||
}, | ||
"dependencies": {} | ||
} |
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
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
206283
2082
34