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

rfc6902

Package Overview
Dependencies
Maintainers
1
Versions
44
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.0.6 to 1.0.7

diff.js

2

package.json
{
"name": "rfc6902",
"version": "1.0.6",
"version": "1.0.7",
"description": "Complete implementation of RFC6902 (patch and diff)",

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

@@ -74,9 +74,10 @@ # rfc6902

you'll realize that computing diffs is rarely deterministic.
(This explains why 2 out of the 94 tests are currently failing.)
(This explains why 2 out of the 103 tests are currently failing.)
Applying `json-patch` documents is way easier than generating them,
which might explain why there are more than five patch-applying RFC6902 implementations in NPM,
but only one (_yours truly_) that attempts to generate patch documents from two distinct objects.
but only one (this one) that attempts to generate patch documents from two distinct objects (there's one that uses `Object.observe()`, which is cheating, and only works when you're the one making the changes).
So when comparing _your_ data objects, you'll want to ensure that the patches it generates meet your needs.
The algorithm used by this library is not optimal, but it's more efficient than the strategy of wholesale replacing everything that's not an exact match.

@@ -121,3 +122,3 @@ Of course, this only applies to generating the patches.

1. `/_updated`: this selects the value of for that key, which is just a number: `1417985649051`
1. `/_updated`: this selects the value of that key, which is just a number: `1417985649051`
2. `/flickr-with-uploads`: This selects the entire object:

@@ -132,6 +133,12 @@

},
"homepage": "https://github.com/chbrown/flickr-with-uploads",
"keywords": [
"flickr",
"api",
"backup"
],
...
}
3. `/flickr-with-uploads/name`: this effectively applies the `/name` pointer to the result of the previous item, which selects the string, `"flickr-with-uploads"`.
4. `/flickr-with-uploads/keywords/1`: Array indices are 0-indexed, so this selects the second item from the `keywords` array, namely, `"api"`.
4. `/flickr-with-uploads/keywords/1`: Array indices start at 0, so this selects the second item from the `keywords` array, namely, `"api"`.

@@ -142,9 +149,9 @@ **Rules:**

* If a key within the JSON document contains a forward slash character (which is totally valid JSON, but not very nice), the `/` in the desired key should be replaced by the escape sequence, `~1`.
* If a key within the JSON document contains a tilde (again valid JSON, but not very common), the `~` should be replaced by the other escape sequence, `~0`. This allows keys containing the literal string `~1` (which is especially cruel) to be referenced by a JSON pointer.
* If a key within the JSON document contains a tilde (again valid JSON, but not very common), the `~` should be replaced by the other escape sequence, `~0`. This allows keys containing the literal string `~1` (which is especially cruel) to be referenced by a JSON pointer (e.g., `/~01` should return `true` when applied to the object `{"~1":true}`).
* All double quotation marks, reverse slashes, and control characters _must_ escaped, since a JSON Pointer is a JSON string.
* A pointer that refers to a non-existent value counts as an error, too. But not necessarily as fatal as the syntax error.
* A pointer that refers to a non-existent value counts as an error, too. But not necessarily as fatal as a syntax error.
## JSON Patch (RFC6902)
The [RFC](http://tools.ietf.org/html/rfc6902) is only 18 pages long, and pretty straight-forward, but here are the basics.
The [RFC](http://tools.ietf.org/html/rfc6902) is only 18 pages long, and pretty straightforward, but here are the basics.

@@ -151,0 +158,0 @@ A JSON Patch document is a JSON document such that:

@@ -10,4 +10,30 @@ declare module "rfc6902" {

interface OperationResult extends Error { }
/**
Apply a 'application/json-patch+json'-type patch to an object.
`patch` *must* be an array of operations.
> Operation objects MUST have exactly one "op" member, whose value
> indicates the operation to perform. Its value MUST be one of "add",
> "remove", "replace", "move", "copy", or "test"; other values are
> errors.
This method currently operates on the target object in-place.
Returns list of results, one for each operation.
- `null` indicated success.
- otherwise, the result will be an instance of one of the Error classe
defined in errors.js.
*/
function applyPatch(object: any, patch: Patch): OperationResult[];
/**
Produce a 'application/json-patch+json'-type patch to get from one object to
another.
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 operations to perform on `input` to produce `output`.
*/
function createPatch(input: any, output: any): Patch;
}
(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){
'use strict';
var equal_1 = _dereq_('./equal');
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.diffAny = diffAny;
var _equal = _dereq_('./equal');
function pushAll(array, items) {

@@ -97,3 +103,3 @@ return Array.prototype.push.apply(array, items);

if (memoized === undefined) {
if (equal_1.compare(input[i - 1], output[j - 1])) {
if ((0, _equal.compare)(input[i - 1], output[j - 1])) {
// equal (no operations => no cost)

@@ -183,3 +189,3 @@ memoized = dist(i - 1, j - 1);

function diffObjects(input, output, ptr) {
// if a key is in input but not output -> remove
// if a key is in input but not output -> remove it
var operations = [];

@@ -189,7 +195,7 @@ subtract(input, output).forEach(function (key) {

});
// if a key is in output but not input -> add
// if a key is in output but not input -> add it
subtract(output, input).forEach(function (key) {
operations.push({ op: 'add', path: ptr.add(key).toString(), value: output[key] });
});
// if a key is in both, diff it
// if a key is in both, diff it recursively
intersection([input, output]).forEach(function (key) {

@@ -202,3 +208,3 @@ pushAll(operations, diffAny(input[key], output[key], ptr.add(key)));

var operations = [];
if (!equal_1.compare(input, output)) {
if (!(0, _equal.compare)(input, output)) {
operations.push({ op: 'replace', path: ptr.toString(), value: output });

@@ -208,2 +214,3 @@ }

}
function diffAny(input, output, ptr) {

@@ -222,3 +229,2 @@ var input_type = objectType(input);

}
exports.diffAny = diffAny;

@@ -231,2 +237,6 @@ },{"./equal":2}],2:[function(_dereq_,module,exports){

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.compare = compare;
function zip(a, b) {

@@ -281,2 +291,3 @@ var zipped = [];

*/
function compare(left, right) {

@@ -296,3 +307,2 @@ // strict equality handles literals, numbers, and strings (a sufficient but not necessary cause)

}
exports.compare = compare;

@@ -376,2 +386,4 @@ },{}],3:[function(_dereq_,module,exports){

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
var _errors = _dereq_('./errors');

@@ -383,2 +395,4 @@

var operationFunctions = _interopRequireWildcard(_patch);
var _diff = _dereq_('./diff');

@@ -392,2 +406,3 @@

exports.version = version;
/**

@@ -410,7 +425,6 @@ Apply a 'application/json-patch+json'-type patch to an object.

*/
exports.version = version;
function applyPatch(object, patch) {
return patch.map(function (operation) {
var operationFunction = _patch.operationFunctions[operation.op];
var operationFunction = operationFunctions[operation.op];
// speedy exit if we don't recognize the operation name

@@ -457,3 +471,3 @@ if (operationFunction === undefined) {

"name": "rfc6902",
"version": "1.0.5",
"version": "1.0.6",
"description": "Complete implementation of RFC6902 (patch and diff)",

@@ -493,2 +507,8 @@ "keywords": [

});
exports.add = add;
exports.remove = remove;
exports.replace = replace;
exports.move = move;
exports.copy = copy;
exports.test = test;

@@ -532,2 +552,3 @@ var _pointer = _dereq_('./pointer');

*/
function add(object, operation) {

@@ -547,2 +568,3 @@ var endpoint = _pointer.Pointer.fromJSON(operation.path).evaluate(object);

*/
function remove(object, operation) {

@@ -571,2 +593,3 @@ // endpoint has parent, key, and value properties

*/
function replace(object, operation) {

@@ -595,2 +618,3 @@ var endpoint = _pointer.Pointer.fromJSON(operation.path).evaluate(object);

*/
function move(object, operation) {

@@ -621,2 +645,3 @@ var from_endpoint = _pointer.Pointer.fromJSON(operation.from).evaluate(object);

*/
function copy(object, operation) {

@@ -641,2 +666,3 @@ var from_endpoint = _pointer.Pointer.fromJSON(operation.from).evaluate(object);

*/
function test(object, operation) {

@@ -649,12 +675,2 @@ var endpoint = _pointer.Pointer.fromJSON(operation.path).evaluate(object);

var operationFunctions = {
add: add,
remove: remove,
replace: replace,
move: move,
copy: copy,
test: test
};
exports.operationFunctions = operationFunctions;
},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(_dereq_,module,exports){

@@ -683,2 +699,10 @@ /**

Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function unescape(token) {

@@ -701,54 +725,73 @@ return token.replace(/~1/g, '/').replace(/~0/g, '~');

*/
var Pointer = (function () {
function Pointer(tokens) {
if (tokens === void 0) {
tokens = [''];
}
function Pointer() {
var tokens = arguments.length <= 0 || arguments[0] === undefined ? [''] : arguments[0];
_classCallCheck(this, Pointer);
this.tokens = tokens;
}
/**
`path` *must* be a properly escaped string.
*/
Pointer.fromJSON = function (path) {
var tokens = path.split('/').map(unescape);
if (tokens[0] !== '') throw new Error("Invalid JSON Pointer: " + path);
return new Pointer(tokens);
};
Pointer.prototype.toString = function () {
return this.tokens.map(escape).join('/');
};
/**
Returns an object with 'parent', 'key', and 'value' properties.
In the special case that pointer = "", parent and key will be null, and `value = obj`
Otherwise, parent will be the such that `parent[key] == value`
*/
Pointer.prototype.evaluate = function (object) {
var parent = null;
var token = null;
for (var i = 1, l = this.tokens.length; i < l; i++) {
parent = object;
token = this.tokens[i];
// not sure if this the best way to handle non-existant paths...
object = (parent || {})[token];
_createClass(Pointer, [{
key: 'toString',
value: function toString() {
return this.tokens.map(escape).join('/');
}
return {
parent: parent,
key: token,
value: object
};
};
Pointer.prototype.push = function (token) {
// mutable
this.tokens.push(token);
};
/**
`token` should be a String. It'll be coerced to one anyway.
immutable (shallowly)
*/
Pointer.prototype.add = function (token) {
var tokens = this.tokens.concat(String(token));
return new Pointer(tokens);
};
/**
Returns an object with 'parent', 'key', and 'value' properties.
In the special case that pointer = "", parent and key will be null, and `value = obj`
Otherwise, parent will be the such that `parent[key] == value`
*/
}, {
key: 'evaluate',
value: function evaluate(object) {
var parent = null;
var token = null;
for (var i = 1, l = this.tokens.length; i < l; i++) {
parent = object;
token = this.tokens[i];
// not sure if this the best way to handle non-existant paths...
object = (parent || {})[token];
}
return {
parent: parent,
key: token,
value: object
};
}
}, {
key: 'push',
value: function push(token) {
// mutable
this.tokens.push(token);
}
/**
`token` should be a String. It'll be coerced to one anyway.
immutable (shallowly)
*/
}, {
key: 'add',
value: function add(token) {
var tokens = this.tokens.concat(String(token));
return new Pointer(tokens);
}
}], [{
key: 'fromJSON',
value: function fromJSON(path) {
var tokens = path.split('/').map(unescape);
if (tokens[0] !== '') throw new Error('Invalid JSON Pointer: ' + path);
return new Pointer(tokens);
}
}]);
return Pointer;
})();
exports.Pointer = Pointer;

@@ -755,0 +798,0 @@

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

(function(m){"object"===typeof exports&&"undefined"!==typeof module?module.exports=m():"function"===typeof define&&define.amd?define([],m):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=m()})(function(){return function f(l,c,g){function k(b,e){if(!c[b]){if(!l[b]){var a="function"==typeof require&&require;if(!e&&a)return a(b,!0);if(h)return h(b,!0);a=Error("Cannot find module '"+b+"'");throw a.code="MODULE_NOT_FOUND",a;}a=c[b]={exports:{}};
l[b][0].call(a.exports,function(a){var e=l[b][1][a];return k(e?e:a)},a,a.exports,f,l,c,g)}return c[b].exports}for(var h="function"==typeof require&&require,d=0;d<g.length;d++)k(g[d]);return k}({1:[function(f,l,c){function g(a,b){var e={},d;for(d in a)e[d]=1;for(var h in b)delete e[h];return Object.keys(e)}function k(a){var b={};a.forEach(function(a){for(var e in a)b[e]=(b[e]||0)+1});a=a.length;for(var e in b)b[e]<a&&delete b[e];return Object.keys(b)}function h(a){return void 0===a?"undefined":null===
a?"null":Array.isArray(a)?"array":typeof a}function d(b,e,d){function h(d,c){var g=f[d+","+c];if(void 0===g){if(a.compare(b[d-1],e[c-1]))g=h(d-1,c-1);else{g=[];if(0<d){var k=h(d-1,c);g.push({operations:k.operations.concat({op:"remove",index:d-1}),cost:k.cost+1})}0<c&&(k=h(d,c-1),g.push({operations:k.operations.concat({op:"add",index:d-1,value:e[c-1]}),cost:k.cost+1}));0<d&&0<c&&(k=h(d-1,c-1),g.push({operations:k.operations.concat({op:"replace",index:d-1,value:e[c-1]}),cost:k.cost+1}));g=g.sort(function(a,
b){return a.cost-b.cost})[0]}f[d+","+c]=g}return g}var f={"0,0":{operations:[],cost:0}},c=0;return h(b.length,e.length).operations.map(function(a){if("add"===a.op){var e=a.index+1+c;a={op:a.op,path:d.add(e<b.length?String(e):"-").toString(),value:a.value};c++;return a}return"remove"===a.op?(a={op:a.op,path:d.add(String(a.index+c)).toString()},c--,a):{op:a.op,path:d.add(String(a.index+c)).toString(),value:a.value}})}function b(a,b,d){var c=[];g(a,b).forEach(function(a){c.push({op:"remove",path:d.add(a).toString()})});
g(b,a).forEach(function(a){c.push({op:"add",path:d.add(a).toString(),value:b[a]})});k([a,b]).forEach(function(h){h=e(a[h],b[h],d.add(h));Array.prototype.push.apply(c,h)});return c}function e(e,c,f){var g=h(e),k=h(c);if("array"==g&&"array"==k)return d(e,c,f);if("object"==g&&"object"==k)return b(e,c,f);g=[];a.compare(e,c)||g.push({op:"replace",path:f.toString(),value:c});return g}var a=f("./equal");c.diffAny=e},{"./equal":2}],2:[function(f,l,c){function g(b,e){for(var a=[],d=0,c=b.length;d<c;d++)a.push([b[d],
e[d]]);return a}function k(b,e){return b.length!==e.length?!1:g(b,e).every(function(a){return d(a[0],a[1])})}function h(b,e){var a=Object.keys(b),c=Object.keys(e);return k(a,c)?a.every(function(a){return d(b[a],e[a])}):!1}function d(b,e){return b===e?!0:Array.isArray(b)&&Array.isArray(e)?k(b,e):Object(b)===b&&Object(e)===e?h(b,e):!1}c.compare=d},{}],3:[function(f,l,c){function g(d,b){if(!(d instanceof b))throw new TypeError("Cannot call a class as a function");}function k(d,b){if("function"!==typeof b&&
null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);d.prototype=Object.create(b&&b.prototype,{constructor:{value:d,enumerable:!1,writable:!0,configurable:!0}});b&&(Object.setPrototypeOf?Object.setPrototypeOf(d,b):d.__proto__=b)}Object.defineProperty(c,"__esModule",{value:!0});var h=function(d,b,e){var a=!0;for(;a;)if(null===d&&(d=Function.prototype),a=Object.getOwnPropertyDescriptor(d,b),void 0===a){d=Object.getPrototypeOf(d);if(null===d)break;a=!0}else{if("value"in
a)return a.value;b=a.get;return void 0===b?void 0:b.call(e)}};f=function(d){function b(e){g(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Value required at path: "+e);this.name=this.constructor.name;this.path=e}k(b,d);return b}(Error);c.MissingError=f;f=function(d){function b(e){g(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Invalid operation: "+e);this.name=this.constructor.name;this.op=e}k(b,d);return b}(Error);c.InvalidOperationError=
f;f=function(d){function b(e,a){g(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Test failed: "+e+" != "+a);this.name=this.constructor.name;this.actual=e;this.expected=a}k(b,d);return b}(Error);c.TestError=f},{}],4:[function(f,l,c){function g(a,e){return e.map(function(e){var d=b.operationFunctions[e.op];return void 0===d?new h.InvalidOperationError(e.op):d(a,e)})}function k(a,b){var c=new d.Pointer,c=(0,e.diffAny)(a,b,c);c.forEach(function(a){a.path=a.path.toString()});
return c}Object.defineProperty(c,"__esModule",{value:!0});c.applyPatch=g;c.patch=function(a,b){console.error("rfc6902.patch(object, patch) has been deprecated. Use rfc6902.applyPatch(object, patch) instead.");return g(a,b)};c.createPatch=k;c.diff=function(a,b){console.error("rfc6902.diff(input, output) has been deprecated. Use rfc6902.createPatch(input, output) instead.");return k(a,b)};var h=f("./errors"),d=f("./pointer"),b=f("./patch"),e=f("./diff");f=f("./package");c.version=(f&&f.__esModule?f:
{"default":f})["default"].version},{"./diff":1,"./errors":3,"./package":5,"./patch":6,"./pointer":7}],5:[function(f,l,c){l.exports={name:"rfc6902",version:"1.0.5",description:"Complete implementation of RFC6902 (patch and diff)",keywords:["json","patch","diff","rfc6902"],homepage:"https://github.com/chbrown/rfc6902",repository:"git://github.com/chbrown/rfc6902.git",author:"Christopher Brown <io@henrian.com> (http://henrian.com)",license:"MIT",main:"./rfc6902.js",dependencies:{},devDependencies:{babel:"*",
babelify:"*",browserify:"*",derequire:"*","js-yaml":"*",mocha:"*",typescript:"*"},scripts:{test:"make test"}}},{}],6:[function(f,l,c){function g(b,a,d){Array.isArray(b)?"-"==a?b.push(d):b.splice(a,0,d):b[a]=d}function k(b,a){Array.isArray(b)?b.splice(a,1):delete b[a]}Object.defineProperty(c,"__esModule",{value:!0});var h=f("./pointer"),d=f("./equal"),b=f("./errors");c.operationFunctions={add:function(d,a){var c=h.Pointer.fromJSON(a.path).evaluate(d);if(void 0===c.parent)return new b.MissingError(a.path);
g(c.parent,c.key,a.value);return null},remove:function(d,a){var c=h.Pointer.fromJSON(a.path).evaluate(d);if(void 0===c.value)return new b.MissingError(a.path);k(c.parent,c.key);return null},replace:function(d,a){var c=h.Pointer.fromJSON(a.path).evaluate(d);if(void 0===c.value)return new b.MissingError(a.path);c.parent[c.key]=a.value;return null},move:function(d,a){var c=h.Pointer.fromJSON(a.from).evaluate(d);if(void 0===c.value)return new b.MissingError(a.from);var f=h.Pointer.fromJSON(a.path).evaluate(d);
if(void 0===f.parent)return new b.MissingError(a.path);k(c.parent,c.key);g(f.parent,f.key,c.value);return null},copy:function(d,a){var c=h.Pointer.fromJSON(a.from).evaluate(d);if(void 0===c.value)return new b.MissingError(a.from);var f=h.Pointer.fromJSON(a.path).evaluate(d);if(void 0===f.parent)return new b.MissingError(a.path);k(c.parent,c.key);g(f.parent,f.key,c.value);return null},test:function(c,a){var f=h.Pointer.fromJSON(a.path).evaluate(c);return(0,d.compare)(f.value,a.value)?null:new b.TestError(f.value,
a.value)}}},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(f,l,c){function g(c){return c.replace(/~1/g,"/").replace(/~0/g,"~")}function k(c){return c.replace(/~/g,"~0").replace(/\//g,"~1")}f=function(){function c(d){void 0===d&&(d=[""]);this.tokens=d}c.fromJSON=function(d){var b=d.split("/").map(g);if(""!==b[0])throw Error("Invalid JSON Pointer: "+d);return new c(b)};c.prototype.toString=function(){return this.tokens.map(k).join("/")};c.prototype.evaluate=function(c){for(var b=null,e=null,
a=1,f=this.tokens.length;a<f;a++)b=c,e=this.tokens[a],c=(b||{})[e];return{parent:b,key:e,value:c}};c.prototype.push=function(c){this.tokens.push(c)};c.prototype.add=function(d){d=this.tokens.concat(String(d));return new c(d)};return c}();c.Pointer=f},{}]},{},[4])(4)});
(function(m){"object"===typeof exports&&"undefined"!==typeof module?module.exports=m():"function"===typeof define&&define.amd?define([],m):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=m()})(function(){return function g(l,d,h){function k(b,e){if(!d[b]){if(!l[b]){var a="function"==typeof require&&require;if(!e&&a)return a(b,!0);if(f)return f(b,!0);a=Error("Cannot find module '"+b+"'");throw a.code="MODULE_NOT_FOUND",a;}a=d[b]={exports:{}};
l[b][0].call(a.exports,function(a){var e=l[b][1][a];return k(e?e:a)},a,a.exports,g,l,d,h)}return d[b].exports}for(var f="function"==typeof require&&require,c=0;c<h.length;c++)k(h[c]);return k}({1:[function(g,l,d){function h(a,b){var e={},c;for(c in a)e[c]=1;for(var d in b)delete e[d];return Object.keys(e)}function k(a){var b={};a.forEach(function(a){for(var e in a)b[e]=(b[e]||0)+1});a=a.length;for(var e in b)b[e]<a&&delete b[e];return Object.keys(b)}function f(a){return void 0===a?"undefined":null===
a?"null":Array.isArray(a)?"array":typeof a}function c(b,e,c){function d(c,f){var h=g[c+","+f];if(void 0===h){if((0,a.compare)(b[c-1],e[f-1]))h=d(c-1,f-1);else{h=[];if(0<c){var k=d(c-1,f);h.push({operations:k.operations.concat({op:"remove",index:c-1}),cost:k.cost+1})}0<f&&(k=d(c,f-1),h.push({operations:k.operations.concat({op:"add",index:c-1,value:e[f-1]}),cost:k.cost+1}));0<c&&0<f&&(k=d(c-1,f-1),h.push({operations:k.operations.concat({op:"replace",index:c-1,value:e[f-1]}),cost:k.cost+1}));h=h.sort(function(a,
b){return a.cost-b.cost})[0]}g[c+","+f]=h}return h}var g={"0,0":{operations:[],cost:0}},f=0;return d(b.length,e.length).operations.map(function(a){if("add"===a.op){var e=a.index+1+f;a={op:a.op,path:c.add(e<b.length?String(e):"-").toString(),value:a.value};f++;return a}return"remove"===a.op?(a={op:a.op,path:c.add(String(a.index+f)).toString()},f--,a):{op:a.op,path:c.add(String(a.index+f)).toString(),value:a.value}})}function b(a,b,c){var d=[];h(a,b).forEach(function(a){d.push({op:"remove",path:c.add(a).toString()})});
h(b,a).forEach(function(a){d.push({op:"add",path:c.add(a).toString(),value:b[a]})});k([a,b]).forEach(function(f){f=e(a[f],b[f],c.add(f));Array.prototype.push.apply(d,f)});return d}function e(e,d,g){var h=f(e),k=f(d);if("array"==h&&"array"==k)return c(e,d,g);if("object"==h&&"object"==k)return b(e,d,g);h=[];(0,a.compare)(e,d)||h.push({op:"replace",path:g.toString(),value:d});return h}Object.defineProperty(d,"__esModule",{value:!0});d.diffAny=e;var a=g("./equal")},{"./equal":2}],2:[function(g,l,d){function h(b,
e){for(var a=[],c=0,d=b.length;c<d;c++)a.push([b[c],e[c]]);return a}function k(b,e){return b.length!==e.length?!1:h(b,e).every(function(a){return c(a[0],a[1])})}function f(b,e){var a=Object.keys(b),d=Object.keys(e);return k(a,d)?a.every(function(a){return c(b[a],e[a])}):!1}function c(b,e){return b===e?!0:Array.isArray(b)&&Array.isArray(e)?k(b,e):Object(b)===b&&Object(e)===e?f(b,e):!1}Object.defineProperty(d,"__esModule",{value:!0});d.compare=c},{}],3:[function(g,l,d){function h(c,b){if(!(c instanceof
b))throw new TypeError("Cannot call a class as a function");}function k(c,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);c.prototype=Object.create(b&&b.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}});b&&(Object.setPrototypeOf?Object.setPrototypeOf(c,b):c.__proto__=b)}Object.defineProperty(d,"__esModule",{value:!0});var f=function(c,b,e){var a=!0;for(;a;)if(null===c&&(c=Function.prototype),
a=Object.getOwnPropertyDescriptor(c,b),void 0===a){c=Object.getPrototypeOf(c);if(null===c)break;a=!0}else{if("value"in a)return a.value;b=a.get;return void 0===b?void 0:b.call(e)}};g=function(c){function b(e){h(this,b);f(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Value required at path: "+e);this.name=this.constructor.name;this.path=e}k(b,c);return b}(Error);d.MissingError=g;g=function(c){function b(e){h(this,b);f(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,
"Invalid operation: "+e);this.name=this.constructor.name;this.op=e}k(b,c);return b}(Error);d.InvalidOperationError=g;g=function(c){function b(e,a){h(this,b);f(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Test failed: "+e+" != "+a);this.name=this.constructor.name;this.actual=e;this.expected=a}k(b,c);return b}(Error);d.TestError=g},{}],4:[function(g,l,d){function h(a,e){return e.map(function(e){var c=b[e.op];return void 0===c?new f.InvalidOperationError(e.op):c(a,e)})}function k(a,
b){var d=new c.Pointer,d=(0,e.diffAny)(a,b,d);d.forEach(function(a){a.path=a.path.toString()});return d}Object.defineProperty(d,"__esModule",{value:!0});d.applyPatch=h;d.patch=function(a,b){console.error("rfc6902.patch(object, patch) has been deprecated. Use rfc6902.applyPatch(object, patch) instead.");return h(a,b)};d.createPatch=k;d.diff=function(a,b){console.error("rfc6902.diff(input, output) has been deprecated. Use rfc6902.createPatch(input, output) instead.");return k(a,b)};var f=g("./errors"),
c=g("./pointer"),b=function(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var e in a)Object.prototype.hasOwnProperty.call(a,e)&&(b[e]=a[e]);b["default"]=a;return b}(g("./patch")),e=g("./diff");g=g("./package");d.version=(g&&g.__esModule?g:{"default":g})["default"].version},{"./diff":1,"./errors":3,"./package":5,"./patch":6,"./pointer":7}],5:[function(g,l,d){l.exports={name:"rfc6902",version:"1.0.6",description:"Complete implementation of RFC6902 (patch and diff)",keywords:["json","patch",
"diff","rfc6902"],homepage:"https://github.com/chbrown/rfc6902",repository:"git://github.com/chbrown/rfc6902.git",author:"Christopher Brown <io@henrian.com> (http://henrian.com)",license:"MIT",main:"./rfc6902.js",dependencies:{},devDependencies:{babel:"*",babelify:"*",browserify:"*",derequire:"*","js-yaml":"*",mocha:"*",typescript:"*"},scripts:{test:"make test"}}},{}],6:[function(g,l,d){function h(b,a,c){Array.isArray(b)?"-"==a?b.push(c):b.splice(a,0,c):b[a]=c}function k(b,a){Array.isArray(b)?b.splice(a,
1):delete b[a]}Object.defineProperty(d,"__esModule",{value:!0});d.add=function(e,a){var c=f.Pointer.fromJSON(a.path).evaluate(e);if(void 0===c.parent)return new b.MissingError(a.path);h(c.parent,c.key,a.value);return null};d.remove=function(e,a){var c=f.Pointer.fromJSON(a.path).evaluate(e);if(void 0===c.value)return new b.MissingError(a.path);k(c.parent,c.key);return null};d.replace=function(e,a){var c=f.Pointer.fromJSON(a.path).evaluate(e);if(void 0===c.value)return new b.MissingError(a.path);c.parent[c.key]=
a.value;return null};d.move=function(e,a){var c=f.Pointer.fromJSON(a.from).evaluate(e);if(void 0===c.value)return new b.MissingError(a.from);var d=f.Pointer.fromJSON(a.path).evaluate(e);if(void 0===d.parent)return new b.MissingError(a.path);k(c.parent,c.key);h(d.parent,d.key,c.value);return null};d.copy=function(c,a){var d=f.Pointer.fromJSON(a.from).evaluate(c);if(void 0===d.value)return new b.MissingError(a.from);var g=f.Pointer.fromJSON(a.path).evaluate(c);if(void 0===g.parent)return new b.MissingError(a.path);
k(d.parent,d.key);h(g.parent,g.key,d.value);return null};d.test=function(e,a){var d=f.Pointer.fromJSON(a.path).evaluate(e);return(0,c.compare)(d.value,a.value)?null:new b.TestError(d.value,a.value)};var f=g("./pointer"),c=g("./equal"),b=g("./errors")},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(g,l,d){function h(c){return c.replace(/~1/g,"/").replace(/~0/g,"~")}function k(c){return c.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(d,"__esModule",{value:!0});var f=function(){function c(b,
c){for(var a=0;a<c.length;a++){var d=c[a];d.enumerable=d.enumerable||!1;d.configurable=!0;"value"in d&&(d.writable=!0);Object.defineProperty(b,d.key,d)}}return function(b,e,a){e&&c(b.prototype,e);a&&c(b,a);return b}}();g=function(){function c(){var b=0>=arguments.length||void 0===arguments[0]?[""]:arguments[0];if(!(this instanceof c))throw new TypeError("Cannot call a class as a function");this.tokens=b}f(c,[{key:"toString",value:function(){return this.tokens.map(k).join("/")}},{key:"evaluate",value:function(b){for(var c=
null,a=null,d=1,f=this.tokens.length;d<f;d++)c=b,a=this.tokens[d],b=(c||{})[a];return{parent:c,key:a,value:b}}},{key:"push",value:function(b){this.tokens.push(b)}},{key:"add",value:function(b){b=this.tokens.concat(String(b));return new c(b)}}],[{key:"fromJSON",value:function(b){var d=b.split("/").map(h);if(""!==d[0])throw Error("Invalid JSON Pointer: "+b);return new c(d)}}]);return c}();d.Pointer=g},{}]},{},[4])(4)});

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