Socket
Socket
Sign inDemoInstall

rfc6902

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rfc6902 - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

3

diff.d.ts

@@ -50,6 +50,7 @@ import { Pointer } from './pointer';

op: 'test';
from: string;
path: string;
value: string;
}
export declare type Operation = AddOperation | RemoveOperation | ReplaceOperation | MoveOperation | CopyOperation | TestOperation;
export declare function isDestructive({op}: Operation): boolean;
/**

@@ -56,0 +57,0 @@ subtract(a, b) returns the keys in `a` that are not in `b`.

import { compare } from './equal';
export function isDestructive({ op }) {
return op === 'remove' || op === 'replace' || op === 'copy' || op === 'move';
}
/**

@@ -3,0 +6,0 @@ subtract(a, b) returns the keys in `a` that are not in `b`.

@@ -1,2 +0,2 @@

import { Operation } from './diff';
import { Operation, TestOperation } from './diff';
/**

@@ -30,1 +30,12 @@ Apply a 'application/json-patch+json'-type patch to an object.

export declare function createPatch(input: any, output: any): Operation[];
/**
Produce an 'application/json-patch+json'-type list of tests, to verify that
existing values in an object are identical to the those captured at some
checkpoint (whenever this function is called).
This does not alter `input` or `output` unless they have a property getter with
side-effects (which is not a good idea anyway).
Returns list of test operations.
*/
export declare function createTests(input: any, patch: Operation[]): TestOperation[];
import { InvalidOperationError } from './errors';
import { Pointer } from './pointer';
import * as operationFunctions from './patch';
import { diffAny } from './diff';
import { diffAny, isDestructive } from './diff';
/**

@@ -46,1 +46,31 @@ Apply a 'application/json-patch+json'-type patch to an object.

}
function createTest(input, path) {
const endpoint = Pointer.fromJSON(path).evaluate(input);
if (endpoint !== undefined) {
return { op: 'test', path, value: endpoint.value };
}
}
/**
Produce an 'application/json-patch+json'-type list of tests, to verify that
existing values in an object are identical to the those captured at some
checkpoint (whenever this function is called).
This does not alter `input` or `output` unless they have a property getter with
side-effects (which is not a good idea anyway).
Returns list of test operations.
*/
export function createTests(input, patch) {
const tests = new Array();
patch.filter(isDestructive).forEach(operation => {
const pathTest = createTest(input, operation.path);
if (pathTest)
tests.push(pathTest);
if ('from' in operation) {
const fromTest = createTest(input, operation['from']);
if (fromTest)
tests.push(fromTest);
}
});
return tests;
}
{
"name": "rfc6902",
"version": "1.2.2",
"version": "1.3.0",
"description": "Complete implementation of RFC6902 (patch and diff)",

@@ -5,0 +5,0 @@ "keywords": [

@@ -38,11 +38,23 @@ # rfc6902

**Create tests** for a patch and a given object:
var obj = {flavors: ['apple', 'banana', 'cherry']};
rfc6902.createTests(obj, [
{op: 'remove', path: '/flavors/1'}
]);
> `[{op: 'test', path: '/flavors/1', value: 'banana'}]`
# API
`rfc6902` exposes two methods. (I'm using TypeScript-like type annotations here.)
`rfc6902` exports three methods, no default. So in ES6 syntax, that would be:
* `rfc6902.applyPatch(object: any, patch: Operation[]): Array<Error | null>`
import {applyPatch, createPatch, createTests} from 'rfc6902';
Using TypeScript annotations:
* `applyPatch(object: any, patch: Operation[]): Array<Error | null>`
The operations in `patch` are applied to `object` in-place, and it returns a list of results. The returned list will have the same length as `patch`. If all operations were successful, each item in the returned list will be `null`. If any of them failed, the corresponding item in the returned list will be an Error instance with descriptive `.name` and `.message` properties.
* `rfc6902.createPatch(input: any, output: any): Operation[]`
* `createPatch(input: any, output: any): Operation[]`

@@ -49,0 +61,0 @@ Returns a list of operations (a JSON Patch) of the required operations to make `input` equal to `output`. In most cases, there is more than one way to transform an object into another. This method is more efficient than wholesale replacement, but does not always provide the optimal list of patches. It uses a simple Levenshtein-type implementation with Arrays, but it doesn't try for anything much smarter than that, so it's limited to `remove`, `add`, and `replace` operations.

@@ -8,2 +8,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.rfc6902 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

exports.isDestructive = isDestructive;
/**

@@ -54,2 +56,8 @@ subtract(a, b) returns the keys in `a` that are not in `b`.

function isDestructive(_ref) {
var op = _ref.op;
return op === "remove" || op === "replace" || op === "copy" || op === "move";
}
function subtract(a, b) {

@@ -426,2 +434,14 @@ var obj = {};

exports.createPatch = createPatch;
/**
Produce an 'application/json-patch+json'-type list of tests, to verify that
existing values in an object are identical to the those captured at some
checkpoint (whenever this function is called).
This does not alter `input` or `output` unless they have a property getter with
side-effects (which is not a good idea anyway).
Returns list of test operations.
*/
exports.createTests = createTests;
Object.defineProperty(exports, "__esModule", {

@@ -437,4 +457,7 @@ value: true

var diffAny = _dereq_("./diff").diffAny;
var _diff = _dereq_("./diff");
var diffAny = _diff.diffAny;
var isDestructive = _diff.isDestructive;
function applyPatch(object, patch) {

@@ -457,2 +480,21 @@ return patch.map(function (operation) {

function createTest(input, path) {
var endpoint = Pointer.fromJSON(path).evaluate(input);
if (endpoint !== undefined) {
return { op: "test", path: path, value: endpoint.value };
}
}
function createTests(input, patch) {
var tests = new Array();
patch.filter(isDestructive).forEach(function (operation) {
var pathTest = createTest(input, operation.path);
if (pathTest) tests.push(pathTest);
if ("from" in operation) {
var fromTest = createTest(input, operation.from);
if (fromTest) tests.push(fromTest);
}
});
return tests;
}
},{"./diff":1,"./errors":3,"./patch":5,"./pointer":6}],5:[function(_dereq_,module,exports){

@@ -459,0 +501,0 @@

@@ -1,16 +0,17 @@

(function(p){"object"===typeof exports&&"undefined"!==typeof module?module.exports=p():"function"===typeof define&&define.amd?define([],p):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=p()})(function(){return function m(n,c,l){function g(a,b){if(!c[a]){if(!n[a]){var e="function"==typeof require&&require;if(!b&&e)return e(a,!0);if(k)return k(a,!0);e=Error("Cannot find module '"+a+"'");throw e.code="MODULE_NOT_FOUND",e;}e=c[a]={exports:{}};
n[a][0].call(e.exports,function(e){var b=n[a][1][e];return g(b?b:e)},e,e.exports,m,n,c,l)}return c[a].exports}for(var k="function"==typeof require&&require,h=0;h<l.length;h++)g(l[h]);return g}({1:[function(m,n,c){function l(a,e){var b={},d;for(d in a)b[d]=1;for(var f in e)delete b[f];return Object.keys(b)}function g(a){var e={};a.forEach(function(a){for(var b in a)e[b]=(e[b]||0)+1});a=a.length;for(var b in e)e[b]<a&&delete e[b];return Object.keys(e)}function k(a){return void 0===a?"undefined":null===
a?"null":Array.isArray(a)?"array":typeof a}function h(a,b,c){function h(e,d){var f=k[e+","+d];if(void 0===f){if(q(a[e-1],b[d-1]))f=h(e-1,d-1);else{f=[];if(0<e){var c=h(e-1,d);f.push({operations:c.operations.concat({op:"remove",index:e-1}),cost:c.cost+1})}0<d&&(c=h(e,d-1),f.push({operations:c.operations.concat({op:"add",index:e-1,value:b[d-1]}),cost:c.cost+1}));0<e&&0<d&&(c=h(e-1,d-1),f.push({operations:c.operations.concat({op:"replace",index:e-1,original:a[e-1],value:b[d-1]}),cost:c.cost+1}));f=f.sort(function(a,
e){return a.cost-e.cost})[0]}k[e+","+d]=f}return f}var k={"0,0":{operations:[],cost:0}},l=isNaN(a.length)||0>=a.length?0:a.length,g=isNaN(b.length)||0>=b.length?0:b.length,g=h(l,g).operations.reduce(function(a,b){var h=d(a,2),k=h[0],h=h[1];if("add"===b.op){var g=b.index+1+h,g={op:b.op,path:c.add(g<l+h?String(g):"-").toString(),value:b.value};return[k.concat(g),h+1]}if("remove"===b.op)return g={op:b.op,path:c.add(String(b.index+h)).toString()},[k.concat(g),h-1];g=c.add(String(b.index+h));g=e(b.original,
b.value,g);return[k.concat.apply(k,f(g)),h]},[[],0]);return d(g,2)[0]}function a(a,b,d){var c=[];l(a,b).forEach(function(a){c.push({op:"remove",path:d.add(a).toString()})});l(b,a).forEach(function(a){c.push({op:"add",path:d.add(a).toString(),value:b[a]})});g([a,b]).forEach(function(h){c.push.apply(c,f(e(a[h],b[h],d.add(h))))});return c}function b(a,b,e){return q(a,b)?[]:[{op:"replace",path:e.toString(),value:b}]}function e(e,d,f){var c=k(e),g=k(d);return"array"==c&&"array"==g?h(e,d,f):"object"==c&&
"object"==g?a(e,d,f):b(e,d,f)}var d=function(a,e){if(Array.isArray(a))return a;if(Symbol.iterator in Object(a)){for(var b=[],d=a[Symbol.iterator](),f;!(f=d.next()).done&&(b.push(f.value),!e||b.length!==e););return b}throw new TypeError("Invalid attempt to destructure non-iterable instance");},f=function(a){if(Array.isArray(a)){for(var b=0,e=Array(a.length);b<a.length;b++)e[b]=a[b];return e}return Array.from(a)};c.subtract=l;c.intersection=g;c.objectType=k;c.diffArrays=h;c.diffObjects=a;c.diffValues=
b;c.diffAny=e;Object.defineProperty(c,"__esModule",{value:!0});var q=m("./equal").compare},{"./equal":2}],2:[function(m,n,c){function l(a,b){for(var e=[],d=0,f=a.length;d<f;d++)e.push([a[d],b[d]]);return e}function g(a,b){return a.length!==b.length?!1:l(a,b).every(function(a){return h(a[0],a[1])})}function k(a,b){var e=Object.keys(a),d=Object.keys(b);return g(e,d)?e.every(function(e){return h(a[e],b[e])}):!1}function h(a,b){return a===b?!0:Array.isArray(a)&&Array.isArray(b)?g(a,b):Object(a)===a&&
Object(b)===b?k(a,b):!1}c.compare=h;Object.defineProperty(c,"__esModule",{value:!0})},{}],3:[function(m,n,c){var l=function a(b,e,d){var f=Object.getOwnPropertyDescriptor(b,e);if(void 0===f)return b=Object.getPrototypeOf(b),null===b?void 0:a(b,e,d);if("value"in f&&f.writable)return f.value;e=f.get;return void 0===e?void 0:e.call(d)},g=function(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&
b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}});b&&(a.__proto__=b)},k=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function");};Object.defineProperty(c,"__esModule",{value:!0});c.MissingError=function(a){function b(a){k(this,b);l(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Value required at path: "+a);this.path=a;this.name=this.constructor.name}g(b,a);return b}(Error);c.InvalidOperationError=function(a){function b(a){k(this,
b);l(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Invalid operation: "+a);this.op=a;this.name=this.constructor.name}g(b,a);return b}(Error);c.TestError=function(a){function b(a,d){k(this,b);l(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Test failed: "+a+" != "+d);this.actual=a;this.expected=d;this.name=this.constructor.name;this.actual=a;this.expected=d}g(b,a);return b}(Error)},{}],4:[function(m,n,c){c.applyPatch=function(a,b){return b.map(function(b){var d=
k[b.op];return void 0===d?new l(b.op):d(a,b)})};c.createPatch=function(a,b){var e=new g;return h(a,b,e)};Object.defineProperty(c,"__esModule",{value:!0});var l=m("./errors").InvalidOperationError,g=m("./pointer").Pointer,k=function(a){return a&&a.__esModule?a:{"default":a}}(m("./patch")),h=m("./diff").diffAny},{"./diff":1,"./errors":3,"./patch":5,"./pointer":6}],5:[function(m,n,c){function l(a,b,f){Array.isArray(a)?"-"==b?a.push(f):a.splice(b,0,f):a[b]=f}function g(a,b){Array.isArray(a)?a.splice(b,
1):delete a[b]}c.add=function(b,d){var f=k.fromJSON(d.path).evaluate(b);if(void 0===f.parent)return new a(d.path);l(f.parent,f.key,d.value);return null};c.remove=function(b,d){var f=k.fromJSON(d.path).evaluate(b);if(void 0===f.value)return new a(d.path);g(f.parent,f.key);return null};c.replace=function(b,d){var f=k.fromJSON(d.path).evaluate(b);if(void 0===f.value)return new a(d.path);f.parent[f.key]=d.value;return null};c.move=function(b,d){var f=k.fromJSON(d.from).evaluate(b);if(void 0===f.value)return new a(d.from);
var c=k.fromJSON(d.path).evaluate(b);if(void 0===c.parent)return new a(d.path);g(f.parent,f.key);l(c.parent,c.key,f.value);return null};c.copy=function(b,d){var c=k.fromJSON(d.from).evaluate(b);if(void 0===c.value)return new a(d.from);var h=k.fromJSON(d.path).evaluate(b);if(void 0===h.parent)return new a(d.path);g(c.parent,c.key);l(h.parent,h.key,c.value);return null};c.test=function(a,d){var c=k.fromJSON(d.path).evaluate(a);return h(c.value,d.value)?null:new b(c.value,d.value)};Object.defineProperty(c,
"__esModule",{value:!0});var k=m("./pointer").Pointer,h=m("./equal").compare;m=m("./errors");var a=m.MissingError,b=m.TestError},{"./equal":2,"./errors":3,"./pointer":6}],6:[function(m,n,c){function l(c){return c.replace(/~1/g,"/").replace(/~0/g,"~")}function g(c){return c.replace(/~/g,"~0").replace(/\//g,"~1")}var k=function(){function c(a,b){for(var e in b){var d=b[e];d.configurable=!0;d.value&&(d.writable=!0)}Object.defineProperties(a,b)}return function(a,b,e){b&&c(a.prototype,b);e&&c(a,e);return a}}();
Object.defineProperty(c,"__esModule",{value:!0});c.Pointer=function(){function c(a){a=void 0===a?[""]:a;if(!(this instanceof c))throw new TypeError("Cannot call a class as a function");this.tokens=a}k(c,{toString:{value:function(){return this.tokens.map(g).join("/")}},evaluate:{value:function(a){for(var b=null,c=null,d=1,f=this.tokens.length;d<f;d++)b=a,c=this.tokens[d],a=(b||{})[c];return{parent:b,key:c,value:a}}},push:{value:function(a){this.tokens.push(a)}},add:{value:function(a){a=this.tokens.concat(String(a));
return new c(a)}}},{fromJSON:{value:function(a){var b=a.split("/").map(l);if(""!==b[0])throw Error("Invalid JSON Pointer: "+a);return new c(b)}}});return c}()},{}]},{},[4])(4)});
(function(q){"object"===typeof exports&&"undefined"!==typeof module?module.exports=q():"function"===typeof define&&define.amd?define([],q):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=q()})(function(){return function m(p,d,f){function n(c,a){if(!d[c]){if(!p[c]){var b="function"==typeof require&&require;if(!a&&b)return b(c,!0);if(h)return h(c,!0);b=Error("Cannot find module '"+c+"'");throw b.code="MODULE_NOT_FOUND",b;}b=d[c]={exports:{}};
p[c][0].call(b.exports,function(b){var a=p[c][1][b];return n(a?a:b)},b,b.exports,m,p,d,f)}return d[c].exports}for(var h="function"==typeof require&&require,l=0;l<f.length;l++)n(f[l]);return n}({1:[function(m,p,d){function f(b,c){var a={},e;for(e in b)a[e]=1;for(var g in c)delete a[g];return Object.keys(a)}function n(b){var c={};b.forEach(function(b){for(var a in b)c[a]=(c[a]||0)+1});b=b.length;for(var a in c)c[a]<b&&delete c[a];return Object.keys(c)}function h(b){return void 0===b?"undefined":null===
b?"null":Array.isArray(b)?"array":typeof b}function l(c,a,d){function k(b,e){var g=l[b+","+e];if(void 0===g){if(r(c[b-1],a[e-1]))g=k(b-1,e-1);else{g=[];if(0<b){var d=k(b-1,e);g.push({operations:d.operations.concat({op:"remove",index:b-1}),cost:d.cost+1})}0<e&&(d=k(b,e-1),g.push({operations:d.operations.concat({op:"add",index:b-1,value:a[e-1]}),cost:d.cost+1}));0<b&&0<e&&(d=k(b-1,e-1),g.push({operations:d.operations.concat({op:"replace",index:b-1,original:c[b-1],value:a[e-1]}),cost:d.cost+1}));g=g.sort(function(b,
c){return b.cost-c.cost})[0]}l[b+","+e]=g}return g}var l={"0,0":{operations:[],cost:0}},h=isNaN(c.length)||0>=c.length?0:c.length,f=isNaN(a.length)||0>=a.length?0:a.length,f=k(h,f).operations.reduce(function(c,a){var k=e(c,2),l=k[0],k=k[1];if("add"===a.op){var f=a.index+1+k,f={op:a.op,path:d.add(f<h+k?String(f):"-").toString(),value:a.value};return[l.concat(f),k+1]}if("remove"===a.op)return f={op:a.op,path:d.add(String(a.index+k)).toString()},[l.concat(f),k-1];f=d.add(String(a.index+k));f=b(a.original,
a.value,f);return[l.concat.apply(l,g(f)),k]},[[],0]);return e(f,2)[0]}function c(a,c,e){var d=[];f(a,c).forEach(function(b){d.push({op:"remove",path:e.add(b).toString()})});f(c,a).forEach(function(b){d.push({op:"add",path:e.add(b).toString(),value:c[b]})});n([a,c]).forEach(function(k){d.push.apply(d,g(b(a[k],c[k],e.add(k))))});return d}function a(b,a,c){return r(b,a)?[]:[{op:"replace",path:c.toString(),value:a}]}function b(b,e,g){var d=h(b),k=h(e);return"array"==d&&"array"==k?l(b,e,g):"object"==d&&
"object"==k?c(b,e,g):a(b,e,g)}var e=function(b,a){if(Array.isArray(b))return b;if(Symbol.iterator in Object(b)){for(var c=[],e=b[Symbol.iterator](),g;!(g=e.next()).done&&(c.push(g.value),!a||c.length!==a););return c}throw new TypeError("Invalid attempt to destructure non-iterable instance");},g=function(b){if(Array.isArray(b)){for(var a=0,c=Array(b.length);a<b.length;a++)c[a]=b[a];return c}return Array.from(b)};d.isDestructive=function(b){b=b.op;return"remove"===b||"replace"===b||"copy"===b||"move"===
b};d.subtract=f;d.intersection=n;d.objectType=h;d.diffArrays=l;d.diffObjects=c;d.diffValues=a;d.diffAny=b;Object.defineProperty(d,"__esModule",{value:!0});var r=m("./equal").compare},{"./equal":2}],2:[function(m,p,d){function f(c,a){for(var b=[],e=0,g=c.length;e<g;e++)b.push([c[e],a[e]]);return b}function n(c,a){return c.length!==a.length?!1:f(c,a).every(function(b){return l(b[0],b[1])})}function h(c,a){var b=Object.keys(c),e=Object.keys(a);return n(b,e)?b.every(function(b){return l(c[b],a[b])}):
!1}function l(c,a){return c===a?!0:Array.isArray(c)&&Array.isArray(a)?n(c,a):Object(c)===c&&Object(a)===a?h(c,a):!1}d.compare=l;Object.defineProperty(d,"__esModule",{value:!0})},{}],3:[function(m,p,d){var f=function c(a,b,e){var g=Object.getOwnPropertyDescriptor(a,b);if(void 0===g){if(a=Object.getPrototypeOf(a),null!==a)return c(a,b,e)}else{if("value"in g&&g.writable)return g.value;b=g.get;return void 0===b?void 0:b.call(e)}},n=function(c,a){if("function"!==typeof a&&null!==a)throw new TypeError("Super expression must either be null or a function, not "+
typeof a);c.prototype=Object.create(a&&a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}});a&&(c.__proto__=a)},h=function(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function");};Object.defineProperty(d,"__esModule",{value:!0});d.MissingError=function(c){function a(b){h(this,a);f(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Value required at path: "+b);this.path=b;this.name=this.constructor.name}n(a,c);return a}(Error);d.InvalidOperationError=
function(c){function a(b){h(this,a);f(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Invalid operation: "+b);this.op=b;this.name=this.constructor.name}n(a,c);return a}(Error);d.TestError=function(c){function a(b,c){h(this,a);f(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Test failed: "+b+" != "+c);this.actual=b;this.expected=c;this.name=this.constructor.name;this.actual=b;this.expected=c}n(a,c);return a}(Error)},{}],4:[function(m,p,d){function f(b,a){var c=
h.fromJSON(a).evaluate(b);if(void 0!==c)return{op:"test",path:a,value:c.value}}d.applyPatch=function(b,a){return a.map(function(a){var c=l[a.op];return void 0===c?new n(a.op):c(b,a)})};d.createPatch=function(b,a){var e=new h;return c(b,a,e)};d.createTests=function(b,c){var e=[];c.filter(a).forEach(function(a){var c=f(b,a.path);c&&e.push(c);"from"in a&&(a=f(b,a.from))&&e.push(a)});return e};Object.defineProperty(d,"__esModule",{value:!0});var n=m("./errors").InvalidOperationError,h=m("./pointer").Pointer,
l=function(b){return b&&b.__esModule?b:{"default":b}}(m("./patch"));m=m("./diff");var c=m.diffAny,a=m.isDestructive},{"./diff":1,"./errors":3,"./patch":5,"./pointer":6}],5:[function(m,p,d){function f(b,a,c){Array.isArray(b)?"-"==a?b.push(c):b.splice(a,0,c):b[a]=c}function n(b,a){Array.isArray(b)?b.splice(a,1):delete b[a]}d.add=function(b,a){var e=h.fromJSON(a.path).evaluate(b);if(void 0===e.parent)return new c(a.path);f(e.parent,e.key,a.value);return null};d.remove=function(b,a){var e=h.fromJSON(a.path).evaluate(b);
if(void 0===e.value)return new c(a.path);n(e.parent,e.key);return null};d.replace=function(b,a){var e=h.fromJSON(a.path).evaluate(b);if(void 0===e.value)return new c(a.path);e.parent[e.key]=a.value;return null};d.move=function(a,e){var b=h.fromJSON(e.from).evaluate(a);if(void 0===b.value)return new c(e.from);var d=h.fromJSON(e.path).evaluate(a);if(void 0===d.parent)return new c(e.path);n(b.parent,b.key);f(d.parent,d.key,b.value);return null};d.copy=function(a,e){var b=h.fromJSON(e.from).evaluate(a);
if(void 0===b.value)return new c(e.from);var d=h.fromJSON(e.path).evaluate(a);if(void 0===d.parent)return new c(e.path);n(b.parent,b.key);f(d.parent,d.key,b.value);return null};d.test=function(b,c){var e=h.fromJSON(c.path).evaluate(b);return l(e.value,c.value)?null:new a(e.value,c.value)};Object.defineProperty(d,"__esModule",{value:!0});var h=m("./pointer").Pointer,l=m("./equal").compare;m=m("./errors");var c=m.MissingError,a=m.TestError},{"./equal":2,"./errors":3,"./pointer":6}],6:[function(m,p,
d){function f(d){return d.replace(/~1/g,"/").replace(/~0/g,"~")}function n(d){return d.replace(/~/g,"~0").replace(/\//g,"~1")}var h=function(){function d(c,a){for(var b in a){var e=a[b];e.configurable=!0;e.value&&(e.writable=!0)}Object.defineProperties(c,a)}return function(c,a,b){a&&d(c.prototype,a);b&&d(c,b);return c}}();Object.defineProperty(d,"__esModule",{value:!0});d.Pointer=function(){function d(c){c=void 0===c?[""]:c;if(!(this instanceof d))throw new TypeError("Cannot call a class as a function");
this.tokens=c}h(d,{toString:{value:function(){return this.tokens.map(n).join("/")}},evaluate:{value:function(c){for(var a=null,b=null,d=1,f=this.tokens.length;d<f;d++)a=c,b=this.tokens[d],c=(a||{})[b];return{parent:a,key:b,value:c}}},push:{value:function(c){this.tokens.push(c)}},add:{value:function(c){c=this.tokens.concat(String(c));return new d(c)}}},{fromJSON:{value:function(c){var a=c.split("/").map(f);if(""!==a[0])throw Error("Invalid JSON Pointer: "+c);return new d(a)}}});return d}()},{}]},{},
[4])(4)});
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