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 1.0.0 to 1.1.0

7

CHANGELOG.md
# Changelog
## not yet published, version 1.0.0
## 2021-01-20, version 1.1.0
- Expose util functions `parseJSONPointer`, `compileJSONPointer`, `getIn`, `setIn`, `updateIn`, `deleteIn`, `existsIn`, and `insertAt`.
## 2020-11-30, version 1.0.0
- Initial release.

@@ -18,2 +18,50 @@ "use strict";

});
Object.defineProperty(exports, "compileJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.compileJSONPointer;
}
});
Object.defineProperty(exports, "parseJSONPointer", {
enumerable: true,
get: function get() {
return _jsonPointer.parseJSONPointer;
}
});
Object.defineProperty(exports, "getIn", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.getIn;
}
});
Object.defineProperty(exports, "setIn", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.setIn;
}
});
Object.defineProperty(exports, "existsIn", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.existsIn;
}
});
Object.defineProperty(exports, "insertAt", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.insertAt;
}
});
Object.defineProperty(exports, "deleteIn", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.deleteIn;
}
});
Object.defineProperty(exports, "updateIn", {
enumerable: true,
get: function get() {
return _immutabilityHelpers.updateIn;
}
});

@@ -23,2 +71,6 @@ var _immutableJSONPatch = require("./immutableJSONPatch.js");

var _revertJSONPatch = require("./revertJSONPatch.js");
var _jsonPointer = require("./jsonPointer.js");
var _immutabilityHelpers = require("./immutabilityHelpers.js");
//# sourceMappingURL=index.js.map

2

lib/cjs/jsonPointer.js

@@ -16,3 +16,3 @@ "use strict";

var path = pointer.split('/');
path.shift(); // remove the first empty entrypa
path.shift(); // remove the first empty entry

@@ -19,0 +19,0 @@ return path.map(function (p) {

export { immutableJSONPatch } from './immutableJSONPatch.js';
export { revertJSONPatch } from './revertJSONPatch.js';
export { revertJSONPatch } from './revertJSONPatch.js'; // utils
export { compileJSONPointer, parseJSONPointer } from './jsonPointer.js';
export { getIn, setIn, existsIn, insertAt, deleteIn, updateIn } from './immutabilityHelpers.js';
//# sourceMappingURL=index.js.map

@@ -8,3 +8,3 @@ /**

var path = pointer.split('/');
path.shift(); // remove the first empty entrypa
path.shift(); // remove the first empty entry

@@ -11,0 +11,0 @@ return path.map(function (p) {

@@ -34,1 +34,11 @@

export declare function revertJSONPatch (json: JSONData, operations: JSONPatchDocument) : JSONPatchDocument
// utils
export declare function parseJSONPointer (pointer: string) : JSONPath
export declare function compileJSONPointer (path: JSONPath) : string
export declare function getIn(json: JSONData, path: JSONPath) : JSONData
export declare function setIn(json: JSONData, path: JSONPath, value: JSONData, createPath?: boolean) : JSONData
export declare function updateIn(json: JSONData, path: JSONPath, callback: (json: JSONData) => JSONData) : JSONData
export declare function deleteIn(json: JSONData, path: JSONPath) : JSONData
export declare function existsIn(json: JSONData, path: JSONPath) : boolean
export declare function insertAt(json: JSONData, path: JSONPath, value: JSONData) : JSONData

@@ -285,3 +285,3 @@ (function (global, factory) {

var path = pointer.split('/');
path.shift(); // remove the first empty entrypa
path.shift(); // remove the first empty entry

@@ -650,4 +650,12 @@ return path.map(function (p) {

exports.compileJSONPointer = compileJSONPointer;
exports.deleteIn = deleteIn;
exports.existsIn = existsIn;
exports.getIn = getIn;
exports.immutableJSONPatch = immutableJSONPatch;
exports.insertAt = insertAt;
exports.parseJSONPointer = parseJSONPointer;
exports.revertJSONPatch = revertJSONPatch;
exports.setIn = setIn;
exports.updateIn = updateIn;

@@ -654,0 +662,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -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 a(r){return r.slice(0,r.length-1)}function i(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 u(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 c(r,t,e){if(r[t]===e)return r;r=u(r);return r[t]=e,r}function p(r,t){for(var e=r,n=0;n<t.length;)e=i(e)?e[t[n]]:void 0,n++;return e}function l(r,t,e,n){var o=3<arguments.length&&void 0!==n&&n;if(0===t.length)return e;n=t[0],e=l(r?r[n]:void 0,t.slice(1),e,o);if(i(r))return c(r,n,e);if(o){o="number"==typeof n?[]:{};return o[n]=e,o}throw new Error("Path does not exist")}function s(r,t){if(0===t.length)return r;if(!i(r))throw new Error("Path does not exist");if(1===t.length){var e=t[0];if(e in r){var n=u(r);return Array.isArray(n)?n.splice(e,1):delete n[e],n}return r}n=t[0];return c(r,n,s(r[n],t.slice(1)))}function y(r,t,e){var n=t.slice(0,t.length-1),o=t[t.length-1];return function r(t,e,n){if(0===e.length)return n(t);if(!i(t))throw new Error("Path doesn't exist");var o=e[0];return c(t,o,r(t[o],e.slice(1),n))}(r,n,function(r){if(!Array.isArray(r))throw new TypeError("Array expected at path "+JSON.stringify(n));r=u(r);return r.splice(o,0,e),r})}function h(r,t){return void 0!==r&&(0===t.length||h(r[t[0]],t.slice(1)))}function v(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:(f=t[o]).op,path:function(r,t){if("-"!==function(r){return r[r.length-1]}(t))return t;t=a(t),r=p(r,t);return t.concat(r.length)}(i,v(f.path)),from:void 0!==f.from?v(f.from):null,value:f.value});e&&e.before&&(void 0!==(u=e.before(n,i))&&(void 0!==u.json&&(n=u.json),void 0!==u.operation&&(i=u.operation)));var f=n,u=d[i.op];if(u)n=u(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(!h(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)}(p(r,e),t))throw new Error('Test failed, value differs (path: "'.concat(m(e),'")'))}(n,i)}e&&e.after&&(void 0!==(f=e.after(n,i,f))&&(n=f))}return n}var d={add:function(r,t){var e=t.path,t=t.value;return(g(r,e)?y:l)(r,e,t)},remove:function(r,t){t=t.path;return s(r,t)},replace:function(r,t){var e=t.path,t=t.value;return l(r,e,t)},copy:function(r,t){var e=t.path,n=t.from,t=p(r,n);{if(g(r,e))return y(r,e,t);n=p(r,n);return l(r,e,n)}},move:function(r,t){var e=t.path,n=t.from,t=p(r,n),n=s(r,n);return(g(n,e)?y:l)(n,e,t)}};function g(r,t){t=p(r,a(t));return Array.isArray(t)}var O={add:S,remove:w,replace:n,copy:function(r,t){var e=t.path,t=t.value;return S(r,{path:e,value:t})},move:function(r,t){var e=t.path,t=t.from,t=[{op:"move",from:m(e),path:m(t)}];!g(r,e)&&h(r,e)&&(t=t.concat(w(r,{path:e})));return t}};function n(r,t){t=t.path;return[{op:"replace",path:m(t),value:p(r,t)}]}function w(r,t){t=t.path;return[{op:"add",path:m(t),value:p(r,t)}]}function S(r,t){var e=t.path,t=t.value;return g(r,e)||!h(r,e)?[{op:"remove",path:m(e)}]:n(r,{path:e,value:t})}r.immutableJSONPatch=b,r.revertJSONPatch=function(r,t){var n=[];return b(r,t,{before:function(r,t){var e=O[t.op];e&&(n=e(r,t).concat(n))}}),n},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 a(r){return r.slice(0,r.length-1)}function i(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 u(r){return(u="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 f(t){if(Array.isArray(t)){var e=t.slice();return Object.getOwnPropertySymbols(t).forEach(function(r){e[r]=t[r]}),e}if("object"!==u(t))return t;var n=o({},t);return Object.getOwnPropertySymbols(t).forEach(function(r){n[r]=t[r]}),n}function c(r,t,e){if(r[t]===e)return r;r=f(r);return r[t]=e,r}function p(r,t){for(var e=r,n=0;n<t.length;)e=i(e)?e[t[n]]:void 0,n++;return e}function l(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=l(r?r[o]:void 0,t.slice(1),e,n);if(i(r))return c(r,o,e);if(n){n="number"==typeof o?[]:{};return n[o]=e,n}throw new Error("Path does not exist")}function s(r,t,e){if(0===t.length)return e(r);if(!i(r))throw new Error("Path doesn't exist");var n=t[0];return c(r,n,s(r[n],t.slice(1),e))}function y(r,t){if(0===t.length)return r;if(!i(r))throw new Error("Path does not exist");if(1===t.length){var e=t[0];if(e in r){var n=f(r);return Array.isArray(n)?n.splice(e,1):delete n[e],n}return r}n=t[0];return c(r,n,y(r[n],t.slice(1)))}function h(r,t,e){var n=t.slice(0,t.length-1),o=t[t.length-1];return s(r,n,function(r){if(!Array.isArray(r))throw new TypeError("Array expected at path "+JSON.stringify(n));r=f(r);return r.splice(o,0,e),r})}function v(r,t){return void 0!==r&&(0===t.length||v(r[t[0]],t.slice(1)))}function m(r){r=r.split("/");return r.shift(),r.map(function(r){return r.replace(/~1/g,"/").replace(/~0/g,"~")})}function d(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=p(r,t);return t.concat(r.length)}(i,m(u.path)),from:void 0!==u.from?m(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=g[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(d(e),'")'));if(!v(r,e))throw new Error('Test failed: path not found (path: "'.concat(d(e),'")'));if(!function(r,t){return JSON.stringify(r)===JSON.stringify(t)}(p(r,e),t))throw new Error('Test failed, value differs (path: "'.concat(d(e),'")'))}(n,i)}e&&e.after&&(void 0!==(u=e.after(n,i,u))&&(n=u))}return n}var g={add:function(r,t){var e=t.path,t=t.value;return(O(r,e)?h:l)(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 l(r,e,t)},copy:function(r,t){var e=t.path,n=t.from,t=p(r,n);{if(O(r,e))return h(r,e,t);n=p(r,n);return l(r,e,n)}},move:function(r,t){var e=t.path,n=t.from,t=p(r,n),n=y(r,n);return(O(n,e)?h:l)(n,e,t)}};function O(r,t){t=p(r,a(t));return Array.isArray(t)}var w={add:P,remove:S,replace:n,copy:function(r,t){var e=t.path,t=t.value;return P(r,{path:e,value:t})},move:function(r,t){var e=t.path,t=t.from,t=[{op:"move",from:d(e),path:d(t)}];!O(r,e)&&v(r,e)&&(t=t.concat(S(r,{path:e})));return t}};function n(r,t){t=t.path;return[{op:"replace",path:d(t),value:p(r,t)}]}function S(r,t){t=t.path;return[{op:"add",path:d(t),value:p(r,t)}]}function P(r,t){var e=t.path,t=t.value;return O(r,e)||!v(r,e)?[{op:"remove",path:d(e)}]:n(r,{path:e,value:t})}r.compileJSONPointer=d,r.deleteIn=y,r.existsIn=v,r.getIn=p,r.immutableJSONPatch=b,r.insertAt=h,r.parseJSONPointer=m,r.revertJSONPatch=function(r,t){var n=[];return b(r,t,{before:function(r,t){var e=w[t.op];e&&(n=e(r,t).concat(n))}}),n},r.setIn=l,r.updateIn=s,Object.defineProperty(r,"__esModule",{value:!0})});
The ISC License
Copyright (c) 2020 by Jos de Jong
Copyright (c) 2020-2021 by Jos de Jong

@@ -5,0 +5,0 @@ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

{
"name": "immutable-json-patch",
"version": "1.0.0",
"version": "1.1.0",
"description": "Immutable JSON patch with support for reverting operations",

@@ -44,17 +44,17 @@ "repository": {

"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/preset-env": "7.12.1",
"@babel/cli": "7.12.10",
"@babel/core": "7.12.10",
"@babel/preset-env": "7.12.11",
"cpy-cli": "3.1.1",
"del-cli": "3.0.1",
"eslint": "7.12.1",
"eslint-config-standard": "16.0.1",
"eslint": "7.18.0",
"eslint-config-standard": "16.0.2",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"mocha": "8.2.0",
"rollup": "2.33.1",
"uglify-js": "3.11.5"
"mocha": "8.2.1",
"rollup": "2.37.1",
"uglify-js": "3.12.5"
},
"dependencies": {}
}

@@ -11,4 +11,7 @@ # immutable-json-patch

Try it out on a playground: https://josdejong.github.io/immutable-json-patch/
See http://jsonpatch.com/ for a clear description of the JSONPatch standard itself.
## Install

@@ -118,3 +121,3 @@

```ts
export declare function revertJSONPatch (json: JSONData, operations: JSONPatchDocument) : JSONPatchDocument
declare function revertJSONPatch (json: JSONData, operations: JSONPatchDocument) : JSONPatchDocument
```

@@ -129,3 +132,18 @@

#### util functions
The library exposes a set of internally used functions to work with JSON pointers and to do immutable operations on JSON data:
```ts
declare function parseJSONPointer (pointer: string) : JSONPath
declare function compileJSONPointer (path: JSONPath) : string
declare function getIn(json: JSONData, path: JSONPath) : JSONData
declare function setIn(json: JSONData, path: JSONPath, value: JSONData, createPath?: boolean) : JSONData
declare function updateIn(json: JSONData, path: JSONPath, callback: (json: JSONData) => JSONData)
declare function deleteIn(json: JSONData, path: JSONPath) : JSONData
declare function existsIn(json: JSONData, path: JSONPath) : boolean
declare function insertAt(json: JSONData, path: JSONPath, value: JSONData) : JSONData
```
### Develop

@@ -132,0 +150,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

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