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

immutable-json-patch

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-json-patch - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

lib/cjs/types.js

119

lib/cjs/immutabilityHelpers.js

@@ -16,2 +16,4 @@ "use strict";

var _typeguards = require("./typeguards.js");
var _utils = require("./utils.js");

@@ -25,12 +27,8 @@

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
/**
* Shallow clone of an Object, Array, or value
* Symbols are cloned too.
* @param {*} value
* @return {*}
*/
function shallowClone(value) {
if (Array.isArray(value)) {
if ((0, _typeguards.isJSONArray)(value)) {
// copy array items

@@ -40,6 +38,8 @@ var copy = value.slice(); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
copy[symbol] = value[symbol];
});
return copy;
} else if (_typeof(value) === 'object') {
} else if ((0, _typeguards.isJSONObject)(value)) {
// copy object properties

@@ -50,2 +50,4 @@ var _copy = _objectSpread({}, value); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_copy[symbol] = value[symbol];

@@ -61,6 +63,2 @@ });

* If the value is unchanged, the original object will be returned
* @param {Object | Array} object
* @param {string | index} key
* @param {*} value
* @returns {Object | Array}
*/

@@ -70,2 +68,4 @@

function applyProp(object, key, value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (object[key] === value) {

@@ -75,3 +75,5 @@ // return original object unchanged when the new value is identical to the old one

} else {
var updatedObject = shallowClone(object);
var updatedObject = shallowClone(object); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
updatedObject[key] = value;

@@ -84,6 +86,3 @@ return updatedObject;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {* | undefined} Returns the field when found, or undefined when the
* path doesn't exist
* @return Returns the field when found, or undefined when the path doesn't exist
*/

@@ -97,4 +96,6 @@

while (i < path.length) {
if ((0, _utils.isObjectOrArray)(value)) {
if ((0, _typeguards.isJSONObject)(value)) {
value = value[path[i]];
} else if ((0, _typeguards.isJSONArray)(value)) {
value = value[parseInt(path[i])];
} else {

@@ -113,13 +114,13 @@ value = undefined;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @param {boolean} [createPath=false]
* @param object
* @param path
* @param value
* @param [createPath=false]
* If true, `path` will be created when (partly) missing in
* the object. For correctly creating nested Arrays or
* Objects, the function relies on `path` containing a number
* Objects, the function relies on `path` containing number
* in case of array indexes.
* If false (default), an error will be thrown when the
* path doesn't exist.
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -135,8 +136,14 @@

var key = path[0];
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = setIn(object ? object[key] : undefined, path.slice(1), value, createPath);
if (!(0, _utils.isObjectOrArray)(object)) {
if ((0, _typeguards.isJSONObject)(object) || (0, _typeguards.isJSONArray)(object)) {
return applyProp(object, key, updatedValue);
} else {
if (createPath) {
var newObject = typeof key === 'number' ? [] : {};
var newObject = IS_INTEGER_REGEX.test(key) ? [] : {}; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
newObject[key] = updatedValue;

@@ -148,5 +155,5 @@ return newObject;

}
}
return applyProp(object, key, updatedValue);
}
var IS_INTEGER_REGEX = /^\d+$/;
/**

@@ -156,9 +163,5 @@ * helper function to replace a nested property in an object with a new value

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {function} callback
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/
function updateIn(object, path, callback) {

@@ -173,4 +176,8 @@ if (path.length === 0) {

var key = path[0];
var updatedValue = updateIn(object[key], path.slice(1), callback);
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = updateIn(object[key], path.slice(1), callback); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -182,5 +189,3 @@ }

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -207,5 +212,7 @@

if (Array.isArray(updatedObject)) {
updatedObject.splice(_key, 1);
} else {
if ((0, _typeguards.isJSONArray)(updatedObject)) {
updatedObject.splice(parseInt(_key), 1);
}
if ((0, _typeguards.isJSONObject)(updatedObject)) {
delete updatedObject[_key];

@@ -218,4 +225,8 @@ }

var key = path[0];
var updatedValue = deleteIn(object[key], path.slice(1));
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = deleteIn(object[key], path.slice(1)); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -228,7 +239,2 @@ }

* insertAt({arr: [1,2,3]}, ['arr', '2'], 'inserted') // [1,2,'inserted',3]
*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @return {Array}
*/

@@ -246,3 +252,3 @@

var updatedItems = shallowClone(items);
updatedItems.splice(index, 0, value);
updatedItems.splice(parseInt(index), 0, value);
return updatedItems;

@@ -254,6 +260,2 @@ });

* and allow replacing Objects/Arrays/values.
* @param {JSONData} json
* @param {function (json: JSONData, path: JSONPath) : JSONData} callback
* @param {JSONPath} [path]
* @return {JSONData}
*/

@@ -266,3 +268,3 @@

if (Array.isArray(json)) {
if ((0, _typeguards.isJSONArray)(updated1)) {
// array

@@ -288,3 +290,3 @@ var updated2;

return updated2 || updated1;
} else if (json && _typeof(json) === 'object') {
} else if ((0, _typeguards.isJSONObject)(updated1)) {
// object

@@ -317,6 +319,3 @@ var _updated;

* Test whether a path exists in a JSON object
* @param {JSONData} json
* @param {JSONPath} path
* @return {boolean} Returns true if the path exists, else returns false
* @private
* @return Returns true if the path exists, else returns false
*/

@@ -332,6 +331,8 @@

return true;
}
} // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return existsIn(json[path[0]], path.slice(1));
}
//# sourceMappingURL=immutabilityHelpers.js.map

@@ -29,6 +29,2 @@ "use strict";

* instead, the patch is applied in an immutable way
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {JSONPatchOptions} [options]
* @return {JSONData} Returns the updated json
*/

@@ -72,3 +68,3 @@ function immutableJSONPatch(json, operations, options) {

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
} // TODO: test after

@@ -90,6 +86,2 @@

* Replace an existing item
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
*/

@@ -103,5 +95,2 @@

* Remove an item or property
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONData}
*/

@@ -114,6 +103,3 @@

/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
* Add an item or property
*/

@@ -131,6 +117,2 @@

* Copy a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath } from
* @return {JSONData}
*/

@@ -152,6 +134,2 @@

* Move a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONData}
*/

@@ -161,3 +139,5 @@

function move(json, path, from) {
var value = (0, _immutabilityHelpers.getIn)(json, from);
var value = (0, _immutabilityHelpers.getIn)(json, from); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var removedJson = (0, _immutabilityHelpers.deleteIn)(json, from);

@@ -169,5 +149,2 @@ return isArrayItem(removedJson, path) ? (0, _immutabilityHelpers.insertAt)(removedJson, path, value) : (0, _immutabilityHelpers.setIn)(removedJson, path, value);

* Throws an error when the test fails
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
*/

@@ -191,9 +168,3 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @returns {boolean}
*/
function isArrayItem(json, path) {

@@ -209,5 +180,3 @@ if (path.length === 0) {

* Resolve the path index of an array, resolves indexes '-'
* @param {JSONData} json
* @param {JSONPath} path
* @returns {JSONPath} Returns the resolved path
* @returns Returns the resolved path
*/

@@ -222,3 +191,5 @@

var parentPath = (0, _utils.initial)(path);
var parent = (0, _immutabilityHelpers.getIn)(json, parentPath);
var parent = (0, _immutabilityHelpers.getIn)(json, parentPath); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return parentPath.concat(parent.length);

@@ -229,3 +200,2 @@ }

* Throws an error when there is an issue
* @param {JSONPatchOperation} operation
*/

@@ -252,18 +222,7 @@

}
/**
* @param {JSONData} json
* @param {JSONPointer} pointer
* @return {JSONPath}
*/
function parsePath(json, pointer) {
return resolvePathIndex(json, (0, _jsonPointer.parseJSONPointer)(pointer));
}
/**
* @param {JSONPointer} fromPointer
* @return {JSONPath}
*/
function parseFrom(fromPointer) {

@@ -270,0 +229,0 @@ return (0, _jsonPointer.parseJSONPointer)(fromPointer);

@@ -6,20 +6,14 @@ "use strict";

});
Object.defineProperty(exports, "appendToJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.appendToJSONPointer;
}
});
Object.defineProperty(exports, "compileJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.compileJSONPointer;
}
});
Object.defineProperty(exports, "compileJSONPointerProp", {
enumerable: true,
get: function get() {
return _jsonPointer.compileJSONPointerProp;
}
});
var _exportNames = {
immutableJSONPatch: true,
parsePath: true,
parseFrom: true,
revertJSONPatch: true,
getIn: true,
setIn: true,
existsIn: true,
insertAt: true,
deleteIn: true,
updateIn: true
};
Object.defineProperty(exports, "deleteIn", {

@@ -55,44 +49,2 @@ enumerable: true,

});
Object.defineProperty(exports, "isJSONPatchAdd", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchAdd;
}
});
Object.defineProperty(exports, "isJSONPatchCopy", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchCopy;
}
});
Object.defineProperty(exports, "isJSONPatchMove", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchMove;
}
});
Object.defineProperty(exports, "isJSONPatchOperation", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchOperation;
}
});
Object.defineProperty(exports, "isJSONPatchRemove", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchRemove;
}
});
Object.defineProperty(exports, "isJSONPatchReplace", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchReplace;
}
});
Object.defineProperty(exports, "isJSONPatchTest", {
enumerable: true,
get: function get() {
return _typeguards.isJSONPatchTest;
}
});
Object.defineProperty(exports, "parseFrom", {

@@ -104,8 +56,2 @@ enumerable: true,

});
Object.defineProperty(exports, "parseJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.parseJSONPointer;
}
});
Object.defineProperty(exports, "parsePath", {

@@ -129,8 +75,2 @@ enumerable: true,

});
Object.defineProperty(exports, "startsWithJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.startsWithJSONPointer;
}
});
Object.defineProperty(exports, "updateIn", {

@@ -147,7 +87,45 @@ enumerable: true,

var _types = require("./types.js");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _types[key];
}
});
});
var _jsonPointer = require("./jsonPointer.js");
Object.keys(_jsonPointer).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _jsonPointer[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _jsonPointer[key];
}
});
});
var _typeguards = require("./typeguards.js");
Object.keys(_typeguards).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _typeguards[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _typeguards[key];
}
});
});
var _immutabilityHelpers = require("./immutabilityHelpers.js");
//# sourceMappingURL=index.js.map

@@ -14,4 +14,2 @@ "use strict";

* Parse a JSON Pointer
* @param {JSONPointer} pointer
* @return {string[]}
*/

@@ -28,4 +26,2 @@ function parseJSONPointer(pointer) {

* Compile a JSON Pointer
* @param {JSONPath} path
* @return {JSONPointer}
*/

@@ -39,4 +35,2 @@

* Compile a single path property from a JSONPath
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -50,5 +44,2 @@

* Append a path property to a JSONPointer
* @param {JSONPointer} pointer
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -61,5 +52,3 @@

/**
* @param {JSONPointer} pointer
* @param {JSONPointer} searchPointer
* @returns {boolean}
* Test whether `pointer` starts with `searchPointer`
*/

@@ -66,0 +55,0 @@

@@ -16,8 +16,20 @@ "use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* Create the inverse of a set of json patch operations
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {RevertJSONPatchOptions} [options]
* @return {JSONPatchDocument} Returns the operations to revert the changes
* @param json
* @param operations Array with JSON patch actions
* @param [options]
* @return Returns the operations to revert the changes
*/

@@ -32,3 +44,3 @@ function revertJSONPatch(json, operations, options) {

if (operation.op === 'add') {
revertOperations = revertAdd(json, path, operation.value);
revertOperations = revertAdd(json, path);
} else if (operation.op === 'remove') {

@@ -39,3 +51,3 @@ revertOperations = revertRemove(json, path);

} else if (operation.op === 'copy') {
revertOperations = revertCopy(json, path, operation.value);
revertOperations = revertCopy(json, path);
} else if (operation.op === 'move') {

@@ -46,3 +58,3 @@ revertOperations = revertMove(json, path, (0, _immutableJSONPatch.parseFrom)(operation.from));

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
}

@@ -75,9 +87,3 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/
function revertReplace(json, path) {

@@ -90,9 +96,3 @@ return [{

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/
function revertRemove(json, path) {

@@ -105,11 +105,4 @@ return [{

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertAdd(json, path, value) {
function revertAdd(json, path) {
if ((0, _immutableJSONPatch.isArrayItem)(json, path) || !(0, _immutabilityHelpers.existsIn)(json, path)) {

@@ -121,24 +114,10 @@ return [{

} else {
return revertReplace(json, path, value);
return revertReplace(json, path);
}
}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertCopy(json, path, value) {
return revertAdd(json, path, value);
function revertCopy(json, path) {
return revertAdd(json, path);
}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONPatchDocument}
*/
function revertMove(json, path, from) {

@@ -154,15 +133,15 @@ if (path.length < from.length && (0, _utils.startsWith)(from, path)) {

var revert = [{
var move = {
op: 'move',
from: (0, _jsonPointer.compileJSONPointer)(path),
path: (0, _jsonPointer.compileJSONPointer)(from)
}];
};
if (!(0, _immutableJSONPatch.isArrayItem)(json, path) && (0, _immutabilityHelpers.existsIn)(json, path)) {
// the move replaces an existing value in an object
revert = revert.concat(revertRemove(json, path));
return [move].concat(_toConsumableArray(revertRemove(json, path)));
} else {
return [move];
}
return revert;
}
//# sourceMappingURL=revertJSONPatch.js.map

@@ -6,2 +6,4 @@ "use strict";

});
exports.isJSONArray = isJSONArray;
exports.isJSONObject = isJSONObject;
exports.isJSONPatchAdd = isJSONPatchAdd;

@@ -15,63 +17,53 @@ exports.isJSONPatchCopy = isJSONPatchCopy;

/**
* @param {unknown} value
* @return {boolean}
*/
function isJSONPatchOperation(value) {
return value ? typeof value.op === 'string' : false;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function isJSONArray(value) {
return Array.isArray(value);
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONObject(value) {
return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
}
function isJSONPatchAdd(operation) {
return operation ? operation.op === 'add' : false;
function isJSONPatchOperation(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? typeof value.op === 'string' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchAdd(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'add' : false;
}
function isJSONPatchRemove(operation) {
return operation ? operation.op === 'remove' : false;
function isJSONPatchRemove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'remove' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchReplace(operation) {
return operation ? operation.op === 'replace' : false;
function isJSONPatchReplace(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'replace' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchCopy(operation) {
return operation ? operation.op === 'copy' : false;
function isJSONPatchCopy(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'copy' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchMove(operation) {
return operation ? operation.op === 'move' : false;
function isJSONPatchMove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'move' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchTest(operation) {
return operation ? operation.op === 'test' : false;
function isJSONPatchTest(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'test' : false;
}
//# sourceMappingURL=typeguards.js.map

@@ -17,5 +17,2 @@ "use strict";

* Test deep equality of two JSON values, objects, or arrays
* @param {JSONData} a
* @param {JSONData} b
* @returns {boolean}
*/

@@ -30,5 +27,2 @@ // TODO: write unit tests

* Test whether two values are strictly equal
* @param {*} a
* @param {*} b
* @returns {boolean}
*/

@@ -42,4 +36,2 @@

* Get all but the last items from an array
* @param {Array} array
* @return {Array}
*/

@@ -54,4 +46,2 @@ // TODO: write unit tests

* Get the last item from an array
* @param {Array} array
* @returns {*}
*/

@@ -66,5 +56,5 @@ // TODO: write unit tests

* Test whether array1 starts with array2
* @param {Array} array1
* @param {Array} array2
* @param {function} [isEqual=strictEqual] Optional function to check equality
* @param array1
* @param array2
* @param [isEqual] Optional function to check equality
*/

@@ -90,4 +80,2 @@

* Test whether a value is an Object or an Array (and not a primitive JSON value)
* @param {*} value
* @return {boolean}
*/

@@ -94,0 +82,0 @@ // TODO: write unit tests

@@ -7,4 +7,2 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
/**

@@ -20,2 +18,3 @@ * Immutability helpers

*/
import { isJSONArray, isJSONObject } from './typeguards.js';
import { isObjectOrArray } from './utils.js';

@@ -25,8 +24,6 @@ /**

* Symbols are cloned too.
* @param {*} value
* @return {*}
*/
export function shallowClone(value) {
if (Array.isArray(value)) {
if (isJSONArray(value)) {
// copy array items

@@ -36,6 +33,8 @@ var copy = value.slice(); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
copy[symbol] = value[symbol];
});
return copy;
} else if (_typeof(value) === 'object') {
} else if (isJSONObject(value)) {
// copy object properties

@@ -46,2 +45,4 @@ var _copy = _objectSpread({}, value); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_copy[symbol] = value[symbol];

@@ -57,9 +58,7 @@ });

* If the value is unchanged, the original object will be returned
* @param {Object | Array} object
* @param {string | index} key
* @param {*} value
* @returns {Object | Array}
*/
export function applyProp(object, key, value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (object[key] === value) {

@@ -69,3 +68,5 @@ // return original object unchanged when the new value is identical to the old one

} else {
var updatedObject = shallowClone(object);
var updatedObject = shallowClone(object); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
updatedObject[key] = value;

@@ -78,6 +79,3 @@ return updatedObject;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {* | undefined} Returns the field when found, or undefined when the
* path doesn't exist
* @return Returns the field when found, or undefined when the path doesn't exist
*/

@@ -90,4 +88,6 @@

while (i < path.length) {
if (isObjectOrArray(value)) {
if (isJSONObject(value)) {
value = value[path[i]];
} else if (isJSONArray(value)) {
value = value[parseInt(path[i])];
} else {

@@ -106,13 +106,13 @@ value = undefined;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @param {boolean} [createPath=false]
* @param object
* @param path
* @param value
* @param [createPath=false]
* If true, `path` will be created when (partly) missing in
* the object. For correctly creating nested Arrays or
* Objects, the function relies on `path` containing a number
* Objects, the function relies on `path` containing number
* in case of array indexes.
* If false (default), an error will be thrown when the
* path doesn't exist.
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -127,8 +127,14 @@

var key = path[0];
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = setIn(object ? object[key] : undefined, path.slice(1), value, createPath);
if (!isObjectOrArray(object)) {
if (isJSONObject(object) || isJSONArray(object)) {
return applyProp(object, key, updatedValue);
} else {
if (createPath) {
var newObject = typeof key === 'number' ? [] : {};
var newObject = IS_INTEGER_REGEX.test(key) ? [] : {}; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
newObject[key] = updatedValue;

@@ -140,5 +146,4 @@ return newObject;

}
return applyProp(object, key, updatedValue);
}
var IS_INTEGER_REGEX = /^\d+$/;
/**

@@ -148,6 +153,3 @@ * helper function to replace a nested property in an object with a new value

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {function} callback
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -164,4 +166,8 @@

var key = path[0];
var updatedValue = updateIn(object[key], path.slice(1), callback);
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = updateIn(object[key], path.slice(1), callback); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -173,5 +179,3 @@ }

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -197,5 +201,7 @@

if (Array.isArray(updatedObject)) {
updatedObject.splice(_key, 1);
} else {
if (isJSONArray(updatedObject)) {
updatedObject.splice(parseInt(_key), 1);
}
if (isJSONObject(updatedObject)) {
delete updatedObject[_key];

@@ -208,4 +214,8 @@ }

var key = path[0];
var updatedValue = deleteIn(object[key], path.slice(1));
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = deleteIn(object[key], path.slice(1)); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -218,7 +228,2 @@ }

* insertAt({arr: [1,2,3]}, ['arr', '2'], 'inserted') // [1,2,'inserted',3]
*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @return {Array}
*/

@@ -235,3 +240,3 @@

var updatedItems = shallowClone(items);
updatedItems.splice(index, 0, value);
updatedItems.splice(parseInt(index), 0, value);
return updatedItems;

@@ -243,6 +248,2 @@ });

* and allow replacing Objects/Arrays/values.
* @param {JSONData} json
* @param {function (json: JSONData, path: JSONPath) : JSONData} callback
* @param {JSONPath} [path]
* @return {JSONData}
*/

@@ -254,3 +255,3 @@

if (Array.isArray(json)) {
if (isJSONArray(updated1)) {
// array

@@ -276,3 +277,3 @@ var updated2;

return updated2 || updated1;
} else if (json && _typeof(json) === 'object') {
} else if (isJSONObject(updated1)) {
// object

@@ -305,6 +306,3 @@ var _updated;

* Test whether a path exists in a JSON object
* @param {JSONData} json
* @param {JSONPath} path
* @return {boolean} Returns true if the path exists, else returns false
* @private
* @return Returns true if the path exists, else returns false
*/

@@ -319,6 +317,8 @@

return true;
}
} // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return existsIn(json[path[0]], path.slice(1));
}
//# sourceMappingURL=immutabilityHelpers.js.map

@@ -8,6 +8,2 @@ import { deleteIn, existsIn, getIn, insertAt, setIn } from './immutabilityHelpers.js';

* instead, the patch is applied in an immutable way
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {JSONPatchOptions} [options]
* @return {JSONData} Returns the updated json
*/

@@ -52,3 +48,3 @@

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
} // TODO: test after

@@ -70,6 +66,2 @@

* Replace an existing item
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
*/

@@ -82,5 +74,2 @@

* Remove an item or property
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONData}
*/

@@ -92,6 +81,3 @@

/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
* Add an item or property
*/

@@ -108,6 +94,2 @@

* Copy a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath } from
* @return {JSONData}
*/

@@ -128,10 +110,8 @@

* Move a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONData}
*/
export function move(json, path, from) {
var value = getIn(json, from);
var value = getIn(json, from); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var removedJson = deleteIn(json, from);

@@ -143,5 +123,2 @@ return isArrayItem(removedJson, path) ? insertAt(removedJson, path, value) : setIn(removedJson, path, value);

* Throws an error when the test fails
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
*/

@@ -164,8 +141,2 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @returns {boolean}
*/
export function isArrayItem(json, path) {

@@ -181,5 +152,3 @@ if (path.length === 0) {

* Resolve the path index of an array, resolves indexes '-'
* @param {JSONData} json
* @param {JSONPath} path
* @returns {JSONPath} Returns the resolved path
* @returns Returns the resolved path
*/

@@ -193,3 +162,5 @@

var parentPath = initial(path);
var parent = getIn(json, parentPath);
var parent = getIn(json, parentPath); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return parentPath.concat(parent.length);

@@ -200,3 +171,2 @@ }

* Throws an error when there is an issue
* @param {JSONPatchOperation} operation
*/

@@ -222,16 +192,5 @@

}
/**
* @param {JSONData} json
* @param {JSONPointer} pointer
* @return {JSONPath}
*/
export function parsePath(json, pointer) {
return resolvePathIndex(json, parseJSONPointer(pointer));
}
/**
* @param {JSONPointer} fromPointer
* @return {JSONPath}
*/
export function parseFrom(fromPointer) {

@@ -238,0 +197,0 @@ return parseJSONPointer(fromPointer);

export { immutableJSONPatch, parsePath, parseFrom } from './immutableJSONPatch.js';
export { revertJSONPatch } from './revertJSONPatch.js'; // utils
export { revertJSONPatch } from './revertJSONPatch.js'; // types
export { compileJSONPointer, compileJSONPointerProp, parseJSONPointer, startsWithJSONPointer, appendToJSONPointer } from './jsonPointer.js';
export { isJSONPatchOperation, isJSONPatchAdd, isJSONPatchRemove, isJSONPatchReplace, isJSONPatchCopy, isJSONPatchMove, isJSONPatchTest } from './typeguards.js';
export * from './types.js'; // utils
export * from './jsonPointer.js';
export * from './typeguards.js';
export { getIn, setIn, existsIn, insertAt, deleteIn, updateIn } from './immutabilityHelpers.js';
//# sourceMappingURL=index.js.map
/**
* Parse a JSON Pointer
* @param {JSONPointer} pointer
* @return {string[]}
*/

@@ -16,4 +14,2 @@ export function parseJSONPointer(pointer) {

* Compile a JSON Pointer
* @param {JSONPath} path
* @return {JSONPointer}
*/

@@ -26,4 +22,2 @@

* Compile a single path property from a JSONPath
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -36,5 +30,2 @@

* Append a path property to a JSONPointer
* @param {JSONPointer} pointer
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -46,5 +37,3 @@

/**
* @param {JSONPointer} pointer
* @param {JSONPointer} searchPointer
* @returns {boolean}
* Test whether `pointer` starts with `searchPointer`
*/

@@ -51,0 +40,0 @@

@@ -0,1 +1,13 @@

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
import { existsIn, getIn } from './immutabilityHelpers.js';

@@ -7,6 +19,6 @@ import { immutableJSONPatch, isArrayItem, parseFrom, parsePath } from './immutableJSONPatch.js';

* Create the inverse of a set of json patch operations
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {RevertJSONPatchOptions} [options]
* @return {JSONPatchDocument} Returns the operations to revert the changes
* @param json
* @param operations Array with JSON patch actions
* @param [options]
* @return Returns the operations to revert the changes
*/

@@ -22,3 +34,3 @@

if (operation.op === 'add') {
revertOperations = revertAdd(json, path, operation.value);
revertOperations = revertAdd(json, path);
} else if (operation.op === 'remove') {

@@ -29,3 +41,3 @@ revertOperations = revertRemove(json, path);

} else if (operation.op === 'copy') {
revertOperations = revertCopy(json, path, operation.value);
revertOperations = revertCopy(json, path);
} else if (operation.op === 'move') {

@@ -36,3 +48,3 @@ revertOperations = revertMove(json, path, parseFrom(operation.from));

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
}

@@ -65,7 +77,2 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/

@@ -79,9 +86,3 @@ function revertReplace(json, path) {

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/
function revertRemove(json, path) {

@@ -94,11 +95,4 @@ return [{

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertAdd(json, path, value) {
function revertAdd(json, path) {
if (isArrayItem(json, path) || !existsIn(json, path)) {

@@ -110,24 +104,10 @@ return [{

} else {
return revertReplace(json, path, value);
return revertReplace(json, path);
}
}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertCopy(json, path, value) {
return revertAdd(json, path, value);
function revertCopy(json, path) {
return revertAdd(json, path);
}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONPatchDocument}
*/
function revertMove(json, path, from) {

@@ -143,15 +123,15 @@ if (path.length < from.length && startsWith(from, path)) {

var revert = [{
var move = {
op: 'move',
from: compileJSONPointer(path),
path: compileJSONPointer(from)
}];
};
if (!isArrayItem(json, path) && existsIn(json, path)) {
// the move replaces an existing value in an object
revert = revert.concat(revertRemove(json, path));
return [move].concat(_toConsumableArray(revertRemove(json, path)));
} else {
return [move];
}
return revert;
}
//# sourceMappingURL=revertJSONPatch.js.map

@@ -1,56 +0,44 @@

/**
* @param {unknown} value
* @return {boolean}
*/
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
export function isJSONArray(value) {
return Array.isArray(value);
}
export function isJSONObject(value) {
return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
}
export function isJSONPatchOperation(value) {
return value ? typeof value.op === 'string' : false;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? typeof value.op === 'string' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchAdd(operation) {
return operation ? operation.op === 'add' : false;
export function isJSONPatchAdd(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'add' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchRemove(operation) {
return operation ? operation.op === 'remove' : false;
export function isJSONPatchRemove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'remove' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchReplace(operation) {
return operation ? operation.op === 'replace' : false;
export function isJSONPatchReplace(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'replace' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchCopy(operation) {
return operation ? operation.op === 'copy' : false;
export function isJSONPatchCopy(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'copy' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchMove(operation) {
return operation ? operation.op === 'move' : false;
export function isJSONPatchMove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'move' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
export function isJSONPatchTest(operation) {
return operation ? operation.op === 'test' : false;
export function isJSONPatchTest(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof(value) === 'object' ? value.op === 'test' : false;
}
//# sourceMappingURL=typeguards.js.map

@@ -5,5 +5,2 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

* Test deep equality of two JSON values, objects, or arrays
* @param {JSONData} a
* @param {JSONData} b
* @returns {boolean}
*/

@@ -18,5 +15,2 @@ // TODO: write unit tests

* Test whether two values are strictly equal
* @param {*} a
* @param {*} b
* @returns {boolean}
*/

@@ -29,4 +23,2 @@

* Get all but the last items from an array
* @param {Array} array
* @return {Array}
*/

@@ -40,4 +32,2 @@ // TODO: write unit tests

* Get the last item from an array
* @param {Array} array
* @returns {*}
*/

@@ -51,5 +41,5 @@ // TODO: write unit tests

* Test whether array1 starts with array2
* @param {Array} array1
* @param {Array} array2
* @param {function} [isEqual=strictEqual] Optional function to check equality
* @param array1
* @param array2
* @param [isEqual] Optional function to check equality
*/

@@ -74,4 +64,2 @@

* Test whether a value is an Object or an Array (and not a primitive JSON value)
* @param {*} value
* @return {boolean}
*/

@@ -78,0 +66,0 @@ // TODO: write unit tests

@@ -9,7 +9,48 @@ (function (global, factory) {

function isJSONArray(value) {
return Array.isArray(value);
}
function isJSONObject(value) {
return value !== null && _typeof$1(value) === 'object' && !Array.isArray(value);
}
function isJSONPatchOperation(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? typeof value.op === 'string' : false;
}
function isJSONPatchAdd(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'add' : false;
}
function isJSONPatchRemove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'remove' : false;
}
function isJSONPatchReplace(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'replace' : false;
}
function isJSONPatchCopy(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'copy' : false;
}
function isJSONPatchMove(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'move' : false;
}
function isJSONPatchTest(value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return value && _typeof$1(value) === 'object' ? value.op === 'test' : false;
}
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
/**
* Test deep equality of two JSON values, objects, or arrays
* @param {JSONData} a
* @param {JSONData} b
* @returns {boolean}
*/

@@ -24,5 +65,2 @@ // TODO: write unit tests

* Test whether two values are strictly equal
* @param {*} a
* @param {*} b
* @returns {boolean}
*/

@@ -35,4 +73,2 @@

* Get all but the last items from an array
* @param {Array} array
* @return {Array}
*/

@@ -46,4 +82,2 @@ // TODO: write unit tests

* Get the last item from an array
* @param {Array} array
* @returns {*}
*/

@@ -57,5 +91,5 @@ // TODO: write unit tests

* Test whether array1 starts with array2
* @param {Array} array1
* @param {Array} array2
* @param {function} [isEqual=strictEqual] Optional function to check equality
* @param array1
* @param array2
* @param [isEqual] Optional function to check equality
*/

@@ -80,4 +114,2 @@

* Test whether a value is an Object or an Array (and not a primitive JSON value)
* @param {*} value
* @return {boolean}
*/

@@ -87,3 +119,3 @@ // TODO: write unit tests

function isObjectOrArray(value) {
return _typeof$1(value) === 'object' && value !== null;
return _typeof(value) === 'object' && value !== null;
}

@@ -96,13 +128,9 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
/**
* Shallow clone of an Object, Array, or value
* Symbols are cloned too.
* @param {*} value
* @return {*}
*/
function shallowClone(value) {
if (Array.isArray(value)) {
if (isJSONArray(value)) {
// copy array items

@@ -112,6 +140,8 @@ var copy = value.slice(); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
copy[symbol] = value[symbol];
});
return copy;
} else if (_typeof(value) === 'object') {
} else if (isJSONObject(value)) {
// copy object properties

@@ -122,2 +152,4 @@ var _copy = _objectSpread({}, value); // copy all symbols

Object.getOwnPropertySymbols(value).forEach(function (symbol) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_copy[symbol] = value[symbol];

@@ -133,9 +165,7 @@ });

* If the value is unchanged, the original object will be returned
* @param {Object | Array} object
* @param {string | index} key
* @param {*} value
* @returns {Object | Array}
*/
function applyProp(object, key, value) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (object[key] === value) {

@@ -145,3 +175,5 @@ // return original object unchanged when the new value is identical to the old one

} else {
var updatedObject = shallowClone(object);
var updatedObject = shallowClone(object); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
updatedObject[key] = value;

@@ -154,6 +186,3 @@ return updatedObject;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {* | undefined} Returns the field when found, or undefined when the
* path doesn't exist
* @return Returns the field when found, or undefined when the path doesn't exist
*/

@@ -166,4 +195,6 @@

while (i < path.length) {
if (isObjectOrArray(value)) {
if (isJSONObject(value)) {
value = value[path[i]];
} else if (isJSONArray(value)) {
value = value[parseInt(path[i])];
} else {

@@ -182,13 +213,13 @@ value = undefined;

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @param {boolean} [createPath=false]
* @param object
* @param path
* @param value
* @param [createPath=false]
* If true, `path` will be created when (partly) missing in
* the object. For correctly creating nested Arrays or
* Objects, the function relies on `path` containing a number
* Objects, the function relies on `path` containing number
* in case of array indexes.
* If false (default), an error will be thrown when the
* path doesn't exist.
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -203,8 +234,14 @@

var key = path[0];
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = setIn(object ? object[key] : undefined, path.slice(1), value, createPath);
if (!isObjectOrArray(object)) {
if (isJSONObject(object) || isJSONArray(object)) {
return applyProp(object, key, updatedValue);
} else {
if (createPath) {
var newObject = typeof key === 'number' ? [] : {};
var newObject = IS_INTEGER_REGEX.test(key) ? [] : {}; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
newObject[key] = updatedValue;

@@ -216,5 +253,4 @@ return newObject;

}
return applyProp(object, key, updatedValue);
}
var IS_INTEGER_REGEX = /^\d+$/;
/**

@@ -224,6 +260,3 @@ * helper function to replace a nested property in an object with a new value

*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {function} callback
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -240,4 +273,8 @@

var key = path[0];
var updatedValue = updateIn(object[key], path.slice(1), callback);
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = updateIn(object[key], path.slice(1), callback); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -249,5 +286,3 @@ }

*
* @param {Object | Array} object
* @param {JSONPath} path
* @return {Object | Array} Returns a new, updated object or array
* @return Returns a new, updated object or array
*/

@@ -273,5 +308,7 @@

if (Array.isArray(updatedObject)) {
updatedObject.splice(_key, 1);
} else {
if (isJSONArray(updatedObject)) {
updatedObject.splice(parseInt(_key), 1);
}
if (isJSONObject(updatedObject)) {
delete updatedObject[_key];

@@ -284,4 +321,8 @@ }

var key = path[0];
var updatedValue = deleteIn(object[key], path.slice(1));
var key = path[0]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var updatedValue = deleteIn(object[key], path.slice(1)); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return applyProp(object, key, updatedValue);

@@ -294,7 +335,2 @@ }

* insertAt({arr: [1,2,3]}, ['arr', '2'], 'inserted') // [1,2,'inserted',3]
*
* @param {Object | Array} object
* @param {JSONPath} path
* @param {*} value
* @return {Array}
*/

@@ -311,3 +347,3 @@

var updatedItems = shallowClone(items);
updatedItems.splice(index, 0, value);
updatedItems.splice(parseInt(index), 0, value);
return updatedItems;

@@ -318,6 +354,3 @@ });

* Test whether a path exists in a JSON object
* @param {JSONData} json
* @param {JSONPath} path
* @return {boolean} Returns true if the path exists, else returns false
* @private
* @return Returns true if the path exists, else returns false
*/

@@ -332,4 +365,6 @@

return true;
}
} // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return existsIn(json[path[0]], path.slice(1));

@@ -340,4 +375,2 @@ }

* Parse a JSON Pointer
* @param {JSONPointer} pointer
* @return {string[]}
*/

@@ -354,4 +387,2 @@ function parseJSONPointer(pointer) {

* Compile a JSON Pointer
* @param {JSONPath} path
* @return {JSONPointer}
*/

@@ -364,4 +395,2 @@

* Compile a single path property from a JSONPath
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -374,5 +403,2 @@

* Append a path property to a JSONPointer
* @param {JSONPointer} pointer
* @param {string | number} pathProp
* @returns {JSONPointer}
*/

@@ -384,5 +410,3 @@

/**
* @param {JSONPointer} pointer
* @param {JSONPointer} searchPointer
* @returns {boolean}
* Test whether `pointer` starts with `searchPointer`
*/

@@ -398,6 +422,2 @@

* instead, the patch is applied in an immutable way
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {JSONPatchOptions} [options]
* @return {JSONData} Returns the updated json
*/

@@ -442,3 +462,3 @@

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
} // TODO: test after

@@ -460,6 +480,2 @@

* Replace an existing item
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
*/

@@ -472,5 +488,2 @@

* Remove an item or property
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONData}
*/

@@ -482,6 +495,3 @@

/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONData}
* Add an item or property
*/

@@ -498,6 +508,2 @@

* Copy a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath } from
* @return {JSONData}
*/

@@ -518,10 +524,8 @@

* Move a value
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONData}
*/
function move(json, path, from) {
var value = getIn(json, from);
var value = getIn(json, from); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var removedJson = deleteIn(json, from);

@@ -533,5 +537,2 @@ return isArrayItem(removedJson, path) ? insertAt(removedJson, path, value) : setIn(removedJson, path, value);

* Throws an error when the test fails
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
*/

@@ -554,8 +555,2 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @returns {boolean}
*/
function isArrayItem(json, path) {

@@ -571,5 +566,3 @@ if (path.length === 0) {

* Resolve the path index of an array, resolves indexes '-'
* @param {JSONData} json
* @param {JSONPath} path
* @returns {JSONPath} Returns the resolved path
* @returns Returns the resolved path
*/

@@ -583,3 +576,5 @@

var parentPath = initial(path);
var parent = getIn(json, parentPath);
var parent = getIn(json, parentPath); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return parentPath.concat(parent.length);

@@ -590,3 +585,2 @@ }

* Throws an error when there is an issue
* @param {JSONPatchOperation} operation
*/

@@ -612,16 +606,5 @@

}
/**
* @param {JSONData} json
* @param {JSONPointer} pointer
* @return {JSONPath}
*/
function parsePath(json, pointer) {
return resolvePathIndex(json, parseJSONPointer(pointer));
}
/**
* @param {JSONPointer} fromPointer
* @return {JSONPath}
*/
function parseFrom(fromPointer) {

@@ -631,8 +614,19 @@ return parseJSONPointer(fromPointer);

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* Create the inverse of a set of json patch operations
* @param {JSONData} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {RevertJSONPatchOptions} [options]
* @return {JSONPatchDocument} Returns the operations to revert the changes
* @param json
* @param operations Array with JSON patch actions
* @param [options]
* @return Returns the operations to revert the changes
*/

@@ -648,3 +642,3 @@

if (operation.op === 'add') {
revertOperations = revertAdd(json, path, operation.value);
revertOperations = revertAdd(json, path);
} else if (operation.op === 'remove') {

@@ -655,3 +649,3 @@ revertOperations = revertRemove(json, path);

} else if (operation.op === 'copy') {
revertOperations = revertCopy(json, path, operation.value);
revertOperations = revertCopy(json, path);
} else if (operation.op === 'move') {

@@ -662,3 +656,3 @@ revertOperations = revertMove(json, path, parseFrom(operation.from));

} else {
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation.op));
throw new Error('Unknown JSONPatch operation ' + JSON.stringify(operation));
}

@@ -691,7 +685,2 @@

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/

@@ -705,9 +694,3 @@ function revertReplace(json, path) {

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @return {JSONPatchDocument}
*/
function revertRemove(json, path) {

@@ -720,11 +703,4 @@ return [{

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertAdd(json, path, value) {
function revertAdd(json, path) {
if (isArrayItem(json, path) || !existsIn(json, path)) {

@@ -739,21 +715,7 @@ return [{

}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONData} value
* @return {JSONPatchDocument}
*/
function revertCopy(json, path, value) {
function revertCopy(json, path) {
return revertAdd(json, path);
}
/**
* @param {JSONData} json
* @param {JSONPath} path
* @param {JSONPath} from
* @return {JSONPatchDocument}
*/
function revertMove(json, path, from) {

@@ -769,72 +731,16 @@ if (path.length < from.length && startsWith(from, path)) {

var revert = [{
var move = {
op: 'move',
from: compileJSONPointer(path),
path: compileJSONPointer(from)
}];
};
if (!isArrayItem(json, path) && existsIn(json, path)) {
// the move replaces an existing value in an object
revert = revert.concat(revertRemove(json, path));
return [move].concat(_toConsumableArray(revertRemove(json, path)));
} else {
return [move];
}
return revert;
}
/**
* @param {unknown} value
* @return {boolean}
*/
function isJSONPatchOperation(value) {
return value ? typeof value.op === 'string' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchAdd(operation) {
return operation ? operation.op === 'add' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchRemove(operation) {
return operation ? operation.op === 'remove' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchReplace(operation) {
return operation ? operation.op === 'replace' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchCopy(operation) {
return operation ? operation.op === 'copy' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchMove(operation) {
return operation ? operation.op === 'move' : false;
}
/**
* @param {unknown} operation
* @return {boolean}
*/
function isJSONPatchTest(operation) {
return operation ? operation.op === 'test' : false;
}
exports.appendToJSONPointer = appendToJSONPointer;

@@ -848,2 +754,4 @@ exports.compileJSONPointer = compileJSONPointer;

exports.insertAt = insertAt;
exports.isJSONArray = isJSONArray;
exports.isJSONObject = isJSONObject;
exports.isJSONPatchAdd = isJSONPatchAdd;

@@ -850,0 +758,0 @@ exports.isJSONPatchCopy = isJSONPatchCopy;

@@ -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 t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){return e===t}function r(e){return e.slice(0,e.length-1)}function i(e){return"object"===t(e)&&null!==e}function f(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function o(n){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?f(Object(o),!0).forEach(function(e){var t,r;t=n,r=o[e=e],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)):f(Object(o)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))})}return n}function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(t){var r,n;return Array.isArray(t)?(r=t.slice(),Object.getOwnPropertySymbols(t).forEach(function(e){r[e]=t[e]}),r):"object"===u(t)?(n=o({},t),Object.getOwnPropertySymbols(t).forEach(function(e){n[e]=t[e]}),n):t}function p(e,t,r){return e[t]===r?e:((e=a(e))[t]=r,e)}function g(e,t){for(var r=e,n=0;n<t.length;)r=i(r)?r[t[n]]:void 0,n++;return r}function m(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=m(e?e[o]:void 0,t.slice(1),r,n);if(i(e))return p(e,o,t);if(n)return(r="number"==typeof o?[]:{})[o]=t,r;throw new Error("Path does not exist")}function l(e,t,r){if(0===t.length)return r(e);if(!i(e))throw new Error("Path doesn't exist");var n=t[0];return p(e,n,l(e[n],t.slice(1),r))}function O(e,t){if(0===t.length)return e;if(!i(e))throw new Error("Path does not exist");var r;if(1===t.length)return(n=t[0])in e?(r=a(e),Array.isArray(r)?r.splice(n,1):delete r[n],r):e;var n=t[0];return p(e,n,O(e[n],t.slice(1)))}function b(e,t,r){var n=t.slice(0,t.length-1),o=t[t.length-1];return l(e,n,function(e){if(!Array.isArray(e))throw new TypeError("Array expected at path "+JSON.stringify(n));e=a(e);return e.splice(o,0,r),e})}function S(e,t){return void 0!==e&&(0===t.length||S(e[t[0]],t.slice(1)))}function n(e){e=e.split("/");return e.shift(),e.map(function(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")})}function w(e){return e.map(s).join("")}function s(e){return"/"+String(e).replace(/~/g,"~0").replace(/\//g,"~1")}function h(e,t,r){for(var n,o,i,f,c,u,a=e,p=0;p<t.length;p++){l=void 0;var l=t[p];if(!["add","remove","replace","copy","move","test"].includes(l.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(l.op));if("string"!=typeof l.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(l));if(("copy"===l.op||"move"===l.op)&&"string"!=typeof l.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(l));var l=t[p],s=(r&&r.before&&(void 0!==(s=r.before(a,l))&&(void 0!==s.json&&(a=s.json),void 0!==s.operation&&(l=s.operation))),a),h=J(a,l.path);if("add"===l.op)f=a,c=h,u=l.value,a=(P(f,c)?b:m)(f,c,u);else if("remove"===l.op)a=O(a,h);else if("replace"===l.op)f=a,c=l.value,a=m(f,h,c);else if("copy"===l.op)u=a,n=h,o=N(l.from),i=void 0,i=g(u,o),a=P(u,n)?b(u,n,i):(i=g(u,o),m(u,n,i));else if("move"===l.op)o=a,n=h,i=N(l.from),y=void 0,y=g(o,i),a=(P(o=O(o,i),n)?b:m)(o,n,y);else{if("test"!==l.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(l.op));d=v=y=void 0;var y=a,v=h,d=l.value;if(void 0===d)throw new Error('Test failed: no value provided (path: "'.concat(w(v),'")'));if(!S(y,v))throw new Error('Test failed: path not found (path: "'.concat(w(v),'")'));if(!function(e,t){return JSON.stringify(e)===JSON.stringify(t)}(g(y,v),d))throw new Error('Test failed, value differs (path: "'.concat(w(v),'")'))}r&&r.after&&(void 0!==(h=r.after(a,l,s))&&(a=h))}return a}function P(e,t){if(0!==t.length)return e=g(e,r(t)),Array.isArray(e)}function J(e,t){return e=e,"-"!==(t=n(t))[t.length-1]?t:(t=r(t),e=g(e,t),t.concat(e.length))}function N(e){return n(e)}function y(e,t){return[{op:"replace",path:w(t),value:g(e,t)}]}function v(e,t){return[{op:"add",path:w(t),value:g(e,t)}]}function d(e,t){return P(e,t)||!S(e,t)?[{op:"remove",path:w(t)}]:y(e,t)}e.appendToJSONPointer=function(e,t){return e+s(t)},e.compileJSONPointer=w,e.compileJSONPointerProp=s,e.deleteIn=O,e.existsIn=S,e.getIn=g,e.immutableJSONPatch=h,e.insertAt=b,e.isJSONPatchAdd=function(e){return!!e&&"add"===e.op},e.isJSONPatchCopy=function(e){return!!e&&"copy"===e.op},e.isJSONPatchMove=function(e){return!!e&&"move"===e.op},e.isJSONPatchOperation=function(e){return!!e&&"string"==typeof e.op},e.isJSONPatchRemove=function(e){return!!e&&"remove"===e.op},e.isJSONPatchReplace=function(e){return!!e&&"replace"===e.op},e.isJSONPatchTest=function(e){return!!e&&"test"===e.op},e.parseFrom=N,e.parseJSONPointer=n,e.parsePath=J,e.revertJSONPatch=function(e,t,i){var f=[];return h(e,t,{before:function(e,t){var r,n,o=J(e,t.path);if("add"===t.op)r=d(e,o,t.value);else if("remove"===t.op)r=v(e,o);else if("replace"===t.op)r=y(e,o);else if("copy"===t.op)t.value,r=d(e,o);else if("move"===t.op)r=function(e,t,r){if(t.length<r.length&&function(e,t,r){var n=2<arguments.length&&void 0!==r?r:c;if(!(e.length<t.length)){for(var o=0;o<t.length;o++)if(!n(e[o],t[o]))return;return 1}}(r,t))return[{op:"replace",path:w(t),value:e}];r=[{op:"move",from:w(t),path:w(r)}];!P(e,t)&&S(e,t)&&(r=r.concat(v(e,t)));return r}(e,o,N(t.from));else{if("test"!==t.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(t.op));r=[]}if(i&&i.before&&((o=i.before(e,t,r))&&o.revertOperations&&(r=o.revertOperations),o&&o.json&&(n=o.json)),f=r.concat(f),void 0!==n)return{json:n}}}),f},e.setIn=m,e.startsWithJSONPointer=function(e,t){return e.startsWith(t)&&(e.length===t.length||"/"===e[t.length])},e.updateIn=l,Object.defineProperty(e,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).immutableJSONPatch={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t){return Array.isArray(t)}function f(t){return null!==t&&"object"===e(t)&&!Array.isArray(t)}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){return t===e}function n(t){return t.slice(0,t.length-1)}function o(t){return"object"===r(t)&&null!==t}function a(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function u(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?a(Object(o),!0).forEach(function(t){var e,r;e=n,r=o[t=t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):a(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}function p(e){var r,n;return i(e)?(r=e.slice(),Object.getOwnPropertySymbols(e).forEach(function(t){r[t]=e[t]}),r):f(e)?(n=u({},e),Object.getOwnPropertySymbols(e).forEach(function(t){n[t]=e[t]}),n):e}function l(t,e,r){return t[e]===r?t:((t=p(t))[e]=r,t)}function b(t,e){for(var r=t,n=0;n<e.length;)r=f(r)?r[e[n]]:i(r)?r[parseInt(e[n])]:void 0,n++;return r}function m(t,e,r){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(0===e.length)return r;var o=e[0],e=m(t?t[o]:void 0,e.slice(1),r,n);if(f(t)||i(t))return l(t,o,e);if(n)return(r=s.test(o)?[]:{})[o]=e,r;throw new Error("Path does not exist")}var s=/^\d+$/;function y(t,e,r){if(0===e.length)return r(t);var n;if(o(t))return l(t,n=e[0],y(t[n],e.slice(1),r));throw new Error("Path doesn't exist")}function g(t,e){if(0===e.length)return t;var r,n;if(o(t))return 1===e.length?(n=e[0])in t?(i(r=p(t))&&r.splice(parseInt(n),1),f(r)&&delete r[n],r):t:l(t,n=e[0],g(t[n],e.slice(1)));throw new Error("Path does not exist")}function O(t,e,r){var n=e.slice(0,e.length-1),o=e[e.length-1];return y(t,n,function(t){if(Array.isArray(t))return(t=p(t)).splice(parseInt(o),0,r),t;throw new TypeError("Array expected at path "+JSON.stringify(n))})}function S(t,e){return void 0!==t&&(0===e.length||S(t[e[0]],e.slice(1)))}function h(t){t=t.split("/");return t.shift(),t.map(function(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")})}function w(t){return t.map(d).join("")}function d(t){return"/"+String(t).replace(/~/g,"~0").replace(/\//g,"~1")}function v(t,e,r){for(var n,o,i,f,c,a,u=t,p=0;p<e.length;p++){l=void 0;var l=e[p];if(!["add","remove","replace","copy","move","test"].includes(l.op))throw new Error("Unknown JSONPatch op "+JSON.stringify(l.op));if("string"!=typeof l.path)throw new Error('Required property "path" missing or not a string in operation '+JSON.stringify(l));if(("copy"===l.op||"move"===l.op)&&"string"!=typeof l.from)throw new Error('Required property "from" missing or not a string in operation '+JSON.stringify(l));var l=e[p],s=(r&&r.before&&(void 0!==(s=r.before(u,l))&&(void 0!==s.json&&(u=s.json),void 0!==s.operation&&(l=s.operation))),u),y=P(u,l.path);if("add"===l.op)f=u,c=y,a=l.value,u=(j(f,c)?O:m)(f,c,a);else if("remove"===l.op)u=g(u,y);else if("replace"===l.op)f=u,c=l.value,u=m(f,y,c);else if("copy"===l.op)a=u,n=y,o=J(l.from),i=void 0,i=b(a,o),u=j(a,n)?O(a,n,i):(i=b(a,o),m(a,n,i));else if("move"===l.op)o=u,n=y,i=J(l.from),h=void 0,h=b(o,i),u=(j(o=g(o,i),n)?O:m)(o,n,h);else{if("test"!==l.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(l));v=d=h=void 0;var h=u,d=y,v=l.value;if(void 0===v)throw new Error('Test failed: no value provided (path: "'.concat(w(d),'")'));if(!S(h,d))throw new Error('Test failed: path not found (path: "'.concat(w(d),'")'));if(!function(t,e){return JSON.stringify(t)===JSON.stringify(e)}(b(h,d),v))throw new Error('Test failed, value differs (path: "'.concat(w(d),'")'))}r&&r.after&&(void 0!==(y=r.after(u,l,s))&&(u=y))}return u}function j(t,e){if(0!==e.length)return t=b(t,n(e)),Array.isArray(t)}function P(t,e){return t=t,"-"!==(e=h(e))[e.length-1]?e:(e=b(t,t=n(e)),t.concat(e.length))}function J(t){return h(t)}function N(t){return function(t){if(Array.isArray(t))return A(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){var r;if(t)return"string"==typeof t?A(t,e):"Map"===(r="Object"===(r=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(t,e):void 0}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function E(t,e){return[{op:"replace",path:w(e),value:b(t,e)}]}function I(t,e){return[{op:"add",path:w(e),value:b(t,e)}]}function T(t,e){return j(t,e)||!S(t,e)?[{op:"remove",path:w(e)}]:E(t,e)}t.appendToJSONPointer=function(t,e){return t+d(e)},t.compileJSONPointer=w,t.compileJSONPointerProp=d,t.deleteIn=g,t.existsIn=S,t.getIn=b,t.immutableJSONPatch=v,t.insertAt=O,t.isJSONArray=i,t.isJSONObject=f,t.isJSONPatchAdd=function(t){return!(!t||"object"!==e(t))&&"add"===t.op},t.isJSONPatchCopy=function(t){return!(!t||"object"!==e(t))&&"copy"===t.op},t.isJSONPatchMove=function(t){return!(!t||"object"!==e(t))&&"move"===t.op},t.isJSONPatchOperation=function(t){return!(!t||"object"!==e(t))&&"string"==typeof t.op},t.isJSONPatchRemove=function(t){return!(!t||"object"!==e(t))&&"remove"===t.op},t.isJSONPatchReplace=function(t){return!(!t||"object"!==e(t))&&"replace"===t.op},t.isJSONPatchTest=function(t){return!(!t||"object"!==e(t))&&"test"===t.op},t.parseFrom=J,t.parseJSONPointer=h,t.parsePath=P,t.revertJSONPatch=function(t,e,i){var f=[];return v(t,e,{before:function(t,e){var r,n,o=P(t,e.path);if("add"===e.op)r=T(t,o);else if("remove"===e.op)r=I(t,o);else if("replace"===e.op)r=E(t,o);else if("copy"===e.op)r=T(t,o);else if("move"===e.op)r=function(t,e,r){if(e.length<r.length&&function(t,e,r){var n=2<arguments.length&&void 0!==r?r:c;if(!(t.length<e.length)){for(var o=0;o<e.length;o++)if(!n(t[o],e[o]))return;return 1}}(r,e))return[{op:"replace",path:w(e),value:t}];r={op:"move",from:w(e),path:w(r)};return!j(t,e)&&S(t,e)?[r].concat(N(I(t,e))):[r]}(t,o,J(e.from));else{if("test"!==e.op)throw new Error("Unknown JSONPatch operation "+JSON.stringify(e));r=[]}if(i&&i.before&&((o=i.before(t,e,r))&&o.revertOperations&&(r=o.revertOperations),o&&o.json&&(n=o.json)),f=r.concat(f),void 0!==n)return{json:n}}}),f},t.setIn=m,t.startsWithJSONPointer=function(t,e){return t.startsWith(e)&&(t.length===e.length||"/"===t[e.length])},t.updateIn=y,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "immutable-json-patch",
"version": "3.0.0",
"version": "4.0.0",
"description": "Immutable JSON patch with support for reverting operations",

@@ -10,6 +10,6 @@ "repository": {

"type": "module",
"main": "lib/cjs/index.js",
"main": "lib/esm/index.js",
"module": "lib/esm/index.js",
"browser": "lib/umd/immutableJSONPatch.js",
"types": "lib/index.d.ts",
"types": "lib/types/index.d.ts",
"keywords": [

@@ -25,11 +25,10 @@ "json",

"test:lib": "mocha test-lib/*.test.*",
"build": "npm run clean && npm run build:ts && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build": "npm run clean && npm-run-all build:**",
"clean": "del-cli lib",
"build:ts": "cpy src/index.d.ts lib --flat",
"build:esm": "babel src --out-dir lib/esm --source-maps --config-file ./babel.config.json",
"build:cjs": "babel src --out-dir lib/cjs --source-maps --config-file ./babel-cjs.config.json && cpy tools/cjs/package.json lib/cjs --flat",
"build:esm": "babel src --out-dir lib/esm --extensions \".ts\" --source-maps --config-file ./babel.config.json",
"build:cjs": "babel src --out-dir lib/cjs --extensions \".ts\" --source-maps --config-file ./babel-cjs.config.json && cpy tools/cjs/package.json lib/cjs --flat",
"build:umd": "rollup lib/esm/index.js --format umd --name 'immutableJSONPatch' --sourcemap --output.file lib/umd/immutableJSONPatch.js && cpy tools/cjs/package.json lib/umd --flat",
"build:umd:min": "uglifyjs --compress --mangle --source-map --comments --output lib/umd/immutableJSONPatch.min.js -- lib/umd/immutableJSONPatch.js",
"link": "npm run build",
"lint": "eslint src/**/*.js",
"build:types": "tsc --project tsconfig-types.json",
"lint": "eslint src/**/*.ts",
"build-and-test": "npm run lint && npm run build && npm run test:lib",

@@ -46,17 +45,26 @@ "prepublishOnly": "npm run build-and-test"

"devDependencies": {
"@babel/cli": "7.18.6",
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/cli": "7.18.10",
"@babel/core": "7.18.10",
"@babel/plugin-transform-typescript": "7.18.12",
"@babel/preset-env": "7.18.10",
"@babel/preset-typescript": "7.18.6",
"@types/mocha": "9.1.1",
"@types/node": "18.7.9",
"@typescript-eslint/eslint-plugin": "5.33.1",
"@typescript-eslint/parser": "5.33.1",
"cpy-cli": "4.1.0",
"del-cli": "4.0.1",
"eslint": "8.18.0",
"del-cli": "5.0.0",
"eslint": "8.22.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.3",
"eslint-plugin-n": "15.2.5",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.0.0",
"mocha": "10.0.0",
"rollup": "2.75.7",
"uglify-js": "3.16.1"
"npm-run-all": "4.1.5",
"rollup": "2.78.1",
"ts-node": "10.9.1",
"typescript": "4.7.4",
"uglify-js": "3.17.0"
}
}

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

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

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

Sorry, the diff of this file is not supported yet

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