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.5 to 1.0.6

5

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

@@ -23,3 +23,4 @@ "keywords": [

"js-yaml": "*",
"mocha": "*"
"mocha": "*",
"typescript": "*"
},

@@ -26,0 +27,0 @@ "scripts": {

2

README.md

@@ -51,3 +51,3 @@ # rfc6902

`rfc6902` exposes two methods. I'm using TypeScript-like type annotations for documentation purposes only; the library is written in standard ES6.
`rfc6902` exposes two methods. (I'm using TypeScript-like type annotations here.)

@@ -54,0 +54,0 @@ * `rfc6902.applyPatch(object: any, patch: Operation[]): Array<Error | null>`

(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){
/*jslint esnext: true */
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.diffAny = diffAny;
var _equal = _dereq_('./equal');
function pushAll(array, xs) {
return Array.prototype.push.apply(array, xs);
var equal_1 = _dereq_('./equal');
function pushAll(array, items) {
return Array.prototype.push.apply(array, items);
}
function _subtract(a, b) {
var obj = {};
for (var add_key in a) {
obj[add_key] = 1;
}
for (var del_key in b) {
delete obj[del_key];
}
return Object.keys(obj);
function last(array) {
return array[array.length - 1];
}
function _intersection(xs) {
// start similarly to _union
var obj = {};
xs.forEach(function (x) {
for (var key in x) {
obj[key] = (obj[key] || 0) + 1;
/**
subtract(a, b) returns the keys in `a` that are not in `b`.
*/
function subtract(a, b) {
var obj = {};
for (var add_key in a) {
obj[add_key] = 1;
}
});
// but then, extra requirement: delete less commonly-seen keys
var threshold = xs.length;
for (var key in obj) {
if (obj[key] < threshold) {
delete obj[key];
for (var del_key in b) {
delete obj[del_key];
}
}
return Object.keys(obj);
return Object.keys(obj);
}
/**
intersection(objects) returns the keys that shared by all given `objects`.
*/
function intersection(objects) {
// initialize like union()
var key_counts = {};
objects.forEach(function (object) {
for (var key in object) {
key_counts[key] = (key_counts[key] || 0) + 1;
}
});
// but then, extra requirement: delete less commonly-seen keys
var threshold = objects.length;
for (var key in key_counts) {
if (key_counts[key] < threshold) {
delete key_counts[key];
}
}
return Object.keys(key_counts);
}
function objectType(object) {
if (object === undefined) {
return 'undefined';
}
if (object === null) {
return 'null';
}
if (Array.isArray(object)) {
return 'array';
}
return typeof object;
if (object === undefined) {
return 'undefined';
}
if (object === null) {
return 'null';
}
if (Array.isArray(object)) {
return 'array';
}
return typeof object;
}
/**
All diff* functions should return a list of operations, often empty.
Each operation should be an object with two to four fields:
* `op`: the name of the operation; one of "add", "remove", "replace", "move",
"copy", or "test".
* `path`: a JSON pointer string
* `from`: a JSON pointer string
* `value`: a JSON value
The different operations have different arguments.
* "add": [`path`, `value`]
* "remove": [`path`]
* "replace": [`path`, `value`]
* "move": [`from`, `path`]
* "copy": [`from`, `path`]
* "test": [`path`, `value`]
Currently this only really differentiates between Arrays, Objects, and
Everything Else, which is pretty much just what JSON substantially
differentiates between.
*/
/**
Array-diffing smarter (levenshtein-like) diffing here

@@ -89,8 +64,14 @@

output
A Z
0 1 2
input A 1 0 1
B 2 1 2
C 3 2 3
A Z
- -
[0] 1 2
input A | 1 [0] 1
B | 2 [1] 1
C | 3 2 [2]
1) start at 0,0 (+0)
2) keep A (+0)
3) remove B (+1)
4) replace C with Z (+1)
if input (source) is empty, they'll all be in the top row, just a bunch of

@@ -101,144 +82,176 @@ additions. If the output is empty, everything will be in the left column, as a

function diffArrays(input, output, ptr) {
// set up cost matrix (very simple initialization: just a map)
var memo = {
'0,0': { operations: [], cost: 0 }
};
/**
input[i's] -> output[j's]
*/
function dist(i, j) {
// returns object of cost and list of operations needed to get to this place in the matrix
var memoized = memo[[i, j]];
if (memoized === undefined) {
if ((0, _equal.compare)(input[i - 1], output[j - 1])) {
memoized = dist(i - 1, j - 1); // equal (no cost = no operations)
} else {
var directions = [];
if (i > 0) {
// NOT topmost row
directions.push({ dist: dist(i - 1, j), type: 'deletion' });
}
if (j > 0) {
// NOT leftmost column
directions.push({ dist: dist(i, j - 1), type: 'insertion' });
}
if (i > 0 && j > 0) {
// TABLE MIDDLE
directions.push({ dist: dist(i - 1, j - 1), type: 'substitution' });
}
// the only other case, i === 0 && j === 0, has already been memoized
// the meat of the algorithm:
// sort by cost to find the lowest one (might be several ties for lowest)
// [4, 6, 7, 1, 2].sort(function(a, b) {return a - b;}); -> [ 1, 2, 4, 6, 7 ]
var best = directions.sort(function (a, b) {
return a.dist.cost - b.dist.cost;
})[0];
var operations = [];
if (best.type === 'deletion') {
operations.push({ op: 'remove', path: ptr.add(i - 1).toString() });
} else if (best.type === 'insertion') {
var col = j - 1;
var path = ptr.add(col < input.length ? col : '-'); // '-' is Array-only syntax (like input.length)
operations.push({ op: 'add', path: path.toString(), value: output[j - 1] });
} else {
operations.push({ op: 'replace', path: ptr.add(j - 1).toString(), value: output[j - 1] });
}
memoized = {
// the new operation(s) must be pushed on the end
operations: best.dist.operations.concat(operations),
cost: best.dist.cost + 1
};
// set up cost matrix (very simple initialization: just a map)
var memo = {
'0,0': { operations: [], cost: 0 }
};
/**
input[i's] -> output[j's]
Given the layout above, i is the row, j is the col
returns a list of Operations needed to get to from input.slice(0, i) to
output.slice(0, j), the each marked with the total cost of getting there.
`cost` is a non-negative integer.
Recursive.
*/
function dist(i, j) {
// memoized
var memoized = memo[i + ',' + j];
if (memoized === undefined) {
if (equal_1.compare(input[i - 1], output[j - 1])) {
// equal (no operations => no cost)
memoized = dist(i - 1, j - 1);
} else {
var alternatives = [];
if (i > 0) {
// NOT topmost row
var remove_alternative = dist(i - 1, j);
alternatives.push({
// the new operation must be pushed on the end
operations: remove_alternative.operations.concat({
op: 'remove',
index: i - 1
}),
cost: remove_alternative.cost + 1
});
}
if (j > 0) {
// NOT leftmost column
var add_alternative = dist(i, j - 1);
alternatives.push({
operations: add_alternative.operations.concat({
op: 'add',
index: i - 1,
value: output[j - 1]
}),
cost: add_alternative.cost + 1
});
}
if (i > 0 && j > 0) {
// TABLE MIDDLE
var replace_alternative = dist(i - 1, j - 1);
alternatives.push({
operations: replace_alternative.operations.concat({
op: 'replace',
index: i - 1,
value: output[j - 1]
}),
cost: replace_alternative.cost + 1
});
}
// the only other case, i === 0 && j === 0, has already been memoized
// the meat of the algorithm:
// sort by cost to find the lowest one (might be several ties for lowest)
// [4, 6, 7, 1, 2].sort(function(a, b) {return a - b;}); -> [ 1, 2, 4, 6, 7 ]
var best = alternatives.sort(function (a, b) {
return a.cost - b.cost;
})[0];
memoized = best;
}
memo[i + ',' + j] = memoized;
}
memo[[i, j]] = memoized;
return memoized;
}
return memoized;
}
var end = dist(input.length, output.length);
return end.operations.reverse();
var array_operations = dist(input.length, output.length).operations;
var padding = 0;
var operations = array_operations.map(function (array_operation) {
if (array_operation.op === 'add') {
var padded_index = array_operation.index + 1 + padding;
var index_token = padded_index < input.length ? String(padded_index) : '-';
var operation = {
op: array_operation.op,
path: ptr.add(index_token).toString(),
value: array_operation.value
};
padding++; // maybe only if array_operation.index > -1 ?
return operation;
} else if (array_operation.op === 'remove') {
var operation = {
op: array_operation.op,
path: ptr.add(String(array_operation.index + padding)).toString()
};
padding--;
return operation;
} else {
return {
op: array_operation.op,
path: ptr.add(String(array_operation.index + padding)).toString(),
value: array_operation.value
};
}
});
return operations;
}
function diffObjects(input, output, ptr) {
// if a key is in input but not output -> remove
var operations = [];
_subtract(input, output).forEach(function (key) {
operations.push({ op: 'remove', path: ptr.add(key).toString() });
});
// if a key is in output but not input -> add
_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
_intersection([input, output]).forEach(function (key) {
pushAll(operations, diffAny(input[key], output[key], ptr.add(key)));
});
return operations;
// if a key is in input but not output -> remove
var operations = [];
subtract(input, output).forEach(function (key) {
operations.push({ op: 'remove', path: ptr.add(key).toString() });
});
// if a key is in output but not input -> add
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
intersection([input, output]).forEach(function (key) {
pushAll(operations, diffAny(input[key], output[key], ptr.add(key)));
});
return operations;
}
function diffValues(input, output, ptr) {
var operations = [];
if (!(0, _equal.compare)(input, output)) {
operations.push({ op: 'replace', path: ptr.toString(), value: output });
}
return operations;
var operations = [];
if (!equal_1.compare(input, output)) {
operations.push({ op: 'replace', path: ptr.toString(), value: output });
}
return operations;
}
function diffAny(input, output, ptr) {
var input_type = objectType(input);
var output_type = objectType(output);
if (input_type == 'array' && output_type == 'array') {
return diffArrays(input, output, ptr);
}
if (input_type == 'object' && output_type == 'object') {
return diffObjects(input, output, ptr);
}
// only pairs of arrays and objects can go down a path to produce a smaller
// diff; everything else must be wholesale replaced if inequal
return diffValues(input, output, ptr);
var input_type = objectType(input);
var output_type = objectType(output);
if (input_type == 'array' && output_type == 'array') {
return diffArrays(input, output, ptr);
}
if (input_type == 'object' && output_type == 'object') {
return diffObjects(input, output, ptr);
}
// only pairs of arrays and objects can go down a path to produce a smaller
// diff; everything else must be wholesale replaced if inequal
return diffValues(input, output, ptr);
}
exports.diffAny = diffAny;
},{"./equal":2}],2:[function(_dereq_,module,exports){
/*jslint esnext: true */
/**
zip(a, b) assumes that a.length === b.length.
*/
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.compare = compare;
function _zip(a, b) {
var zipped = [];
for (var i = 0, l = Math.min(a.length, b.length); i < l; i++) {
zipped.push([a[i], b[i]]);
}
return zipped;
function zip(a, b) {
var zipped = [];
for (var i = 0, l = a.length; i < l; i++) {
zipped.push([a[i], b[i]]);
}
return zipped;
}
/**
Assume that left and right are both Arrays.
compareArrays(left, right) assumes that `left` and `right` are both Arrays.
*/
function _compareArrays(left, right) {
if (left.length !== right.length) return false;
return _zip(left, right).every(function (pair) {
return compare(pair[0], pair[1]);
});
function compareArrays(left, right) {
if (left.length !== right.length) return false;
return zip(left, right).every(function (pair) {
return compare(pair[0], pair[1]);
});
}
/**
Assume that left and right are both Objects.
compareObjects(left, right) assumes that `left` and `right` are both Objects.
*/
function _compareObjects(left, right) {
var left_keys = Object.keys(left);
var right_keys = Object.keys(right);
if (!_compareArrays(left_keys, right_keys)) return false;
return left_keys.every(function (key) {
return compare(left[key], right[key]);
});
function compareObjects(left, right) {
var left_keys = Object.keys(left);
var right_keys = Object.keys(right);
if (!compareArrays(left_keys, right_keys)) return false;
return left_keys.every(function (key) {
return compare(left[key], right[key]);
});
}
/**
Compare returns true if `left` and `right` are materially equal (i.e., would
produce equivalent JSON), false otherwise.
`compare()` returns true if `left` and `right` are materially equal
(i.e., would produce equivalent JSON), false otherwise.

@@ -263,17 +276,17 @@ > Here, "equal" means that the value at the target location and the

*/
function compare(left, right) {
// strict equality handles literals, numbers, and strings (a sufficient but not necessary cause)
if (left === right) return true;
// check arrays
if (Array.isArray(left) && Array.isArray(right)) {
return _compareArrays(left, right);
}
// check objects
if (Object(left) === left && Object(right) === right) {
return _compareObjects(left, right);
}
// mismatched arrays & objects, etc., are always inequal
return false;
// strict equality handles literals, numbers, and strings (a sufficient but not necessary cause)
if (left === right) return true;
// check arrays
if (Array.isArray(left) && Array.isArray(right)) {
return compareArrays(left, right);
}
// check objects
if (Object(left) === left && Object(right) === right) {
return compareObjects(left, right);
}
// mismatched arrays & objects, etc., are always inequal
return false;
}
exports.compare = compare;

@@ -434,3 +447,3 @@ },{}],3:[function(_dereq_,module,exports){

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

@@ -455,3 +468,4 @@ "keywords": [

"js-yaml": "*",
"mocha": "*"
"mocha": "*",
"typescript": "*"
},

@@ -630,3 +644,2 @@ "scripts": {

},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(_dereq_,module,exports){
/*jslint esnext: true */
/**

@@ -654,14 +667,5 @@ Unescape token part of a JSON Pointer string

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) {
return token.replace(/~1/g, '/').replace(/~0/g, '~');
return token.replace(/~1/g, '/').replace(/~0/g, '~');
}
/** Escape token part of a JSON Pointer string

@@ -676,27 +680,26 @@

function escape(token) {
return token.replace(/~/g, '~0').replace(/\//g, '~1');
return token.replace(/~/g, '~0').replace(/\//g, '~1');
}
/**
JSON Pointer representation
*/
var Pointer = (function () {
function Pointer(tokens) {
_classCallCheck(this, Pointer);
this.tokens = tokens || [''];
}
/**
`path` *must* be a properly escaped string.
*/
_createClass(Pointer, [{
key: 'toString',
value: function toString() {
return this.tokens.map(escape).join('/');
function Pointer(tokens) {
if (tokens === void 0) {
tokens = [''];
}
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.

@@ -706,48 +709,31 @@ In the special case that pointer = "", parent and key will be null, and `value = obj`

*/
}, {
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);
}
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];
}
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)
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;
Pointer.prototype.add = function (token) {
var tokens = this.tokens.concat(String(token));
return new Pointer(tokens);
};
return Pointer;
})();
exports.Pointer = Pointer;

@@ -754,0 +740,0 @@

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

(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 e(l,h,g){function f(a,d){if(!h[a]){if(!l[a]){var b="function"==typeof require&&require;if(!d&&b)return b(a,!0);if(k)return k(a,!0);b=Error("Cannot find module '"+a+"'");throw b.code="MODULE_NOT_FOUND",b;}b=h[a]={exports:{}};
l[a][0].call(b.exports,function(m){var b=l[a][1][m];return f(b?b:m)},b,b.exports,e,l,h,g)}return h[a].exports}for(var k="function"==typeof require&&require,c=0;c<g.length;c++)f(g[c]);return f}({1:[function(e,l,h){function g(a,b){var d={},c;for(c in a)d[c]=1;for(var e in b)delete d[e];return Object.keys(d)}function f(a){var b={};a.forEach(function(a){for(var m in a)b[m]=(b[m]||0)+1});a=a.length;for(var d in b)b[d]<a&&delete b[d];return Object.keys(b)}function k(a){return void 0===a?"undefined":null===
a?"null":Array.isArray(a)?"array":typeof a}function c(a,d,c){function e(k,g){var f=h[[k,g]];if(void 0===f){if((0,b.compare)(a[k-1],d[g-1]))f=e(k-1,g-1);else{f=[];0<k&&f.push({dist:e(k-1,g),type:"deletion"});0<g&&f.push({dist:e(k,g-1),type:"insertion"});0<k&&0<g&&f.push({dist:e(k-1,g-1),type:"substitution"});var f=f.sort(function(a,b){return a.dist.cost-b.dist.cost})[0],l=[];if("deletion"===f.type)l.push({op:"remove",path:c.add(k-1).toString()});else if("insertion"===f.type){var n=g-1,n=c.add(n<a.length?
n:"-");l.push({op:"add",path:n.toString(),value:d[g-1]})}else l.push({op:"replace",path:c.add(g-1).toString(),value:d[g-1]});f={operations:f.dist.operations.concat(l),cost:f.dist.cost+1}}h[[k,g]]=f}return f}var h={"0,0":{operations:[],cost:0}};return e(a.length,d.length).operations.reverse()}function a(a,b,c){var e=[];g(a,b).forEach(function(a){e.push({op:"remove",path:c.add(a).toString()})});g(b,a).forEach(function(a){e.push({op:"add",path:c.add(a).toString(),value:b[a]})});f([a,b]).forEach(function(f){f=
d(a[f],b[f],c.add(f));Array.prototype.push.apply(e,f)});return e}function d(d,e,f){var g=k(d),h=k(e);if("array"==g&&"array"==h)return c(d,e,f);if("object"==g&&"object"==h)return a(d,e,f);g=[];(0,b.compare)(d,e)||g.push({op:"replace",path:f.toString(),value:e});return g}Object.defineProperty(h,"__esModule",{value:!0});h.diffAny=d;var b=e("./equal")},{"./equal":2}],2:[function(e,l,h){function g(a,d){for(var b=[],m=0,c=Math.min(a.length,d.length);m<c;m++)b.push([a[m],d[m]]);return b}function f(a,d){return a.length!==
d.length?!1:g(a,d).every(function(a){return c(a[0],a[1])})}function k(a,d){var b=Object.keys(a),m=Object.keys(d);return f(b,m)?b.every(function(b){return c(a[b],d[b])}):!1}function c(a,d){return a===d?!0:Array.isArray(a)&&Array.isArray(d)?f(a,d):Object(a)===a&&Object(d)===d?k(a,d):!1}Object.defineProperty(h,"__esModule",{value:!0});h.compare=c},{}],3:[function(e,l,h){function g(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function");}function f(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&&(Object.setPrototypeOf?Object.setPrototypeOf(c,a):c.__proto__=a)}Object.defineProperty(h,"__esModule",{value:!0});var k=function(c,a,d){var b=!0;for(;b;)if(null===c&&(c=Function.prototype),b=Object.getOwnPropertyDescriptor(c,a),void 0===b){c=Object.getPrototypeOf(c);if(null===c)break;b=!0}else{if("value"in
b)return b.value;a=b.get;return void 0===a?void 0:a.call(d)}};e=function(c){function a(d){g(this,a);k(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Value required at path: "+d);this.name=this.constructor.name;this.path=d}f(a,c);return a}(Error);h.MissingError=e;e=function(c){function a(d){g(this,a);k(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Invalid operation: "+d);this.name=this.constructor.name;this.op=d}f(a,c);return a}(Error);h.InvalidOperationError=
e;e=function(c){function a(d,b){g(this,a);k(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,"Test failed: "+d+" != "+b);this.name=this.constructor.name;this.actual=d;this.expected=b}f(a,c);return a}(Error);h.TestError=e},{}],4:[function(e,l,h){function g(b,d){return d.map(function(d){var m=a.operationFunctions[d.op];return void 0===m?new k.InvalidOperationError(d.op):m(b,d)})}function f(a,m){var e=new c.Pointer,e=(0,d.diffAny)(a,m,e);e.forEach(function(a){a.path=a.path.toString()});
return e}Object.defineProperty(h,"__esModule",{value:!0});h.applyPatch=g;h.patch=function(a,d){console.error("rfc6902.patch(object, patch) has been deprecated. Use rfc6902.applyPatch(object, patch) instead.");return g(a,d)};h.createPatch=f;h.diff=function(a,d){console.error("rfc6902.diff(input, output) has been deprecated. Use rfc6902.createPatch(input, output) instead.");return f(a,d)};var k=e("./errors"),c=e("./pointer"),a=e("./patch"),d=e("./diff");e=e("./package");h.version=(e&&e.__esModule?e:
{"default":e})["default"].version},{"./diff":1,"./errors":3,"./package":5,"./patch":6,"./pointer":7}],5:[function(e,l,h){l.exports={name:"rfc6902",version:"1.0.4",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:"*"},scripts:{test:"make test"}}},{}],6:[function(e,l,h){function g(a,b,c){Array.isArray(a)?"-"==b?a.push(c):a.splice(b,0,c):a[b]=c}function f(a,b){Array.isArray(a)?a.splice(b,1):delete a[b]}Object.defineProperty(h,"__esModule",{value:!0});var k=e("./pointer"),c=e("./equal"),a=e("./errors");h.operationFunctions={add:function(d,b){var c=k.Pointer.fromJSON(b.path).evaluate(d);if(void 0===c.parent)return new a.MissingError(b.path);g(c.parent,
c.key,b.value);return null},remove:function(d,b){var c=k.Pointer.fromJSON(b.path).evaluate(d);if(void 0===c.value)return new a.MissingError(b.path);f(c.parent,c.key);return null},replace:function(d,b){var c=k.Pointer.fromJSON(b.path).evaluate(d);if(void 0===c.value)return new a.MissingError(b.path);c.parent[c.key]=b.value;return null},move:function(d,b){var c=k.Pointer.fromJSON(b.from).evaluate(d);if(void 0===c.value)return new a.MissingError(b.from);var e=k.Pointer.fromJSON(b.path).evaluate(d);if(void 0===
e.parent)return new a.MissingError(b.path);f(c.parent,c.key);g(e.parent,e.key,c.value);return null},copy:function(d,b){var c=k.Pointer.fromJSON(b.from).evaluate(d);if(void 0===c.value)return new a.MissingError(b.from);var e=k.Pointer.fromJSON(b.path).evaluate(d);if(void 0===e.parent)return new a.MissingError(b.path);f(c.parent,c.key);g(e.parent,e.key,c.value);return null},test:function(d,b){var e=k.Pointer.fromJSON(b.path).evaluate(d);return(0,c.compare)(e.value,b.value)?null:new a.TestError(e.value,
b.value)}}},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(e,l,h){function g(c){return c.replace(/~1/g,"/").replace(/~0/g,"~")}function f(c){return c.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(h,"__esModule",{value:!0});var k=function(){function c(a,d){for(var b=0;b<d.length;b++){var c=d[b];c.enumerable=c.enumerable||!1;c.configurable=!0;"value"in c&&(c.writable=!0);Object.defineProperty(a,c.key,c)}}return function(a,d,b){d&&c(a.prototype,d);b&&c(a,b);return a}}();e=function(){function c(a){if(!(this instanceof
c))throw new TypeError("Cannot call a class as a function");this.tokens=a||[""]}k(c,[{key:"toString",value:function(){return this.tokens.map(f).join("/")}},{key:"evaluate",value:function(a){for(var c=null,b=null,e=1,f=this.tokens.length;e<f;e++)c=a,b=this.tokens[e],a=(c||{})[b];return{parent:c,key:b,value:a}}},{key:"push",value:function(a){this.tokens.push(a)}},{key:"add",value:function(a){a=this.tokens.concat(String(a));return new c(a)}}],[{key:"fromJSON",value:function(a){var d=a.split("/").map(g);
if(""!==d[0])throw Error("Invalid JSON Pointer: "+a);return new c(d)}}]);return c}();h.Pointer=e},{}]},{},[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 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)});

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