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 4.0.2 to 5.0.0

3

dist/rfc6902.js

@@ -73,2 +73,5 @@ (function (global, factory) {

key = this.tokens[i];
if (key == '__proto__' || key == 'constructor' || key == 'prototype') {
continue;
}
// not sure if this the best way to handle non-existant paths...

@@ -75,0 +78,0 @@ value = (parent || {})[key];

38

dist/rfc6902.min.js

@@ -1,27 +0,11 @@

var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(c){return c.raw=c};$jscomp.createTemplateTagFirstArgWithRaw=function(c,d){c.raw=d;return c};$jscomp.arrayIteratorImpl=function(c){var d=0;return function(){return d<c.length?{done:!1,value:c[d++]}:{done:!0}}};$jscomp.arrayIterator=function(c){return{next:$jscomp.arrayIteratorImpl(c)}};$jscomp.makeIterator=function(c){var d="undefined"!=typeof Symbol&&Symbol.iterator&&c[Symbol.iterator];return d?d.call(c):$jscomp.arrayIterator(c)};
$jscomp.arrayFromIterator=function(c){for(var d,f=[];!(d=c.next()).done;)f.push(d.value);return f};$jscomp.arrayFromIterable=function(c){return c instanceof Array?c:$jscomp.arrayFromIterator($jscomp.makeIterator(c))};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;
$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==typeof Object.create?Object.create:function(c){var d=function(){};d.prototype=c;return new d};$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,d,f){if(c==Array.prototype||c==Object.prototype)return c;c[d]=f.value;return c};
$jscomp.getGlobal=function(c){c=["object"==typeof globalThis&&globalThis,c,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var d=0;d<c.length;++d){var f=c[d];if(f&&f.Math==Math)return f}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);$jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};
$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(c,d){var f=$jscomp.propertyToPolyfillSymbol[d];if(null==f)return c[d];f=c[f];return void 0!==f?f:c[d]};$jscomp.polyfill=function(c,d,f,k){d&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(c,d,f,k):$jscomp.polyfillUnisolated(c,d,f,k))};
$jscomp.polyfillUnisolated=function(c,d,f,k){f=$jscomp.global;c=c.split(".");for(k=0;k<c.length-1;k++){var h=c[k];if(!(h in f))return;f=f[h]}c=c[c.length-1];k=f[c];d=d(k);d!=k&&null!=d&&$jscomp.defineProperty(f,c,{configurable:!0,writable:!0,value:d})};
$jscomp.polyfillIsolated=function(c,d,f,k){var h=c.split(".");c=1===h.length;k=h[0];k=!c&&k in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var u=0;u<h.length-1;u++){var x=h[u];if(!(x in k))return;k=k[x]}h=h[h.length-1];f=$jscomp.IS_SYMBOL_NATIVE&&"es6"===f?k[h]:null;d=d(f);null!=d&&(c?$jscomp.defineProperty($jscomp.polyfills,h,{configurable:!0,writable:!0,value:d}):d!==f&&(void 0===$jscomp.propertyToPolyfillSymbol[h]&&($jscomp.propertyToPolyfillSymbol[h]=$jscomp.IS_SYMBOL_NATIVE?$jscomp.global.Symbol(h):
$jscomp.POLYFILL_PREFIX+h),$jscomp.defineProperty(k,$jscomp.propertyToPolyfillSymbol[h],{configurable:!0,writable:!0,value:d})))};
$jscomp.getConstructImplementation=function(){function c(){function f(){}new f;Reflect.construct(f,[],function(){});return new f instanceof f}if($jscomp.TRUST_ES6_POLYFILLS&&"undefined"!=typeof Reflect&&Reflect.construct){if(c())return Reflect.construct;var d=Reflect.construct;return function(f,k,h){f=d(f,k);h&&Reflect.setPrototypeOf(f,h.prototype);return f}}return function(f,k,h){void 0===h&&(h=f);h=$jscomp.objectCreate(h.prototype||Object.prototype);return Function.prototype.apply.call(f,h,k)||
h}};$jscomp.construct={valueOf:$jscomp.getConstructImplementation}.valueOf();$jscomp.underscoreProtoCanBeSet=function(){var c={a:!0},d={};try{return d.__proto__=c,d.a}catch(f){}return!1};$jscomp.setPrototypeOf=$jscomp.TRUST_ES6_POLYFILLS&&"function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(c,d){c.__proto__=d;if(c.__proto__!==d)throw new TypeError(c+" is not extensible");return c}:null;
$jscomp.inherits=function(c,d){c.prototype=$jscomp.objectCreate(d.prototype);c.prototype.constructor=c;if($jscomp.setPrototypeOf){var f=$jscomp.setPrototypeOf;f(c,d)}else for(f in d)if("prototype"!=f)if(Object.defineProperties){var k=Object.getOwnPropertyDescriptor(d,f);k&&Object.defineProperty(c,f,k)}else c[f]=d[f];c.superClass_=d.prototype};$jscomp.polyfill("Reflect",function(c){return c?c:{}},"es6","es3");$jscomp.polyfill("Reflect.construct",function(c){return $jscomp.construct},"es6","es3");
$jscomp.polyfill("Reflect.setPrototypeOf",function(c){if(c)return c;if($jscomp.setPrototypeOf){var d=$jscomp.setPrototypeOf;return function(f,k){try{return d(f,k),!0}catch(h){return!1}}}return null},"es6","es5");$jscomp.initSymbol=function(){};
$jscomp.polyfill("Symbol",function(c){if(c)return c;var d=function(h,u){this.$jscomp$symbol$id_=h;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:u})};d.prototype.toString=function(){return this.$jscomp$symbol$id_};var f=0,k=function(h){if(this instanceof k)throw new TypeError("Symbol is not a constructor");return new d("jscomp_symbol_"+(h||"")+"_"+f++,h)};return k},"es6","es3");
$jscomp.polyfill("Symbol.iterator",function(c){if(c)return c;c=Symbol("Symbol.iterator");for(var d="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),f=0;f<d.length;f++){var k=$jscomp.global[d[f]];"function"===typeof k&&"function"!=typeof k.prototype[c]&&$jscomp.defineProperty(k.prototype,c,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}})}return c},"es6",
"es3");$jscomp.iteratorPrototype=function(c){c={next:c};c[Symbol.iterator]=function(){return this};return c};$jscomp.iteratorFromArray=function(c,d){c instanceof String&&(c+="");var f=0,k=!1,h={next:function(){if(!k&&f<c.length){var u=f++;return{value:d(u,c[u]),done:!1}}k=!0;return{done:!0,value:void 0}}};h[Symbol.iterator]=function(){return h};return h};$jscomp.polyfill("Array.prototype.keys",function(c){return c?c:function(){return $jscomp.iteratorFromArray(this,function(d){return d})}},"es6","es3");
(function(c,d){"object"===typeof exports&&"undefined"!==typeof module?d(exports):"function"===typeof define&&define.amd?define(["exports"],d):(c="undefined"!==typeof globalThis?globalThis:c||self,d(c.rfc6902={}))})(this,function(c){function d(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function f(a){return a.replace(/~/g,"~0").replace(/\//g,"~1")}function k(a){return void 0===a?"undefined":null===a?"null":Array.isArray(a)?"array":typeof a}function h(a){if(null==a||"object"!=typeof a)return a;
if(a.constructor==Array){for(var b=a.length,e=Array(b),g=0;g<b;g++)e[g]=h(a[g]);return e}if(a.constructor==Date)return new Date(+a);b={};for(e in a)A.call(a,e)&&(b[e]=h(a[e]));return b}function u(a){a=a.op;return"remove"===a||"replace"===a||"copy"===a||"move"===a}function x(a,b){var e={},g;for(g in a)A.call(a,g)&&void 0!==a[g]&&(e[g]=1);for(var l in b)A.call(b,l)&&void 0!==b[l]&&delete e[l];return Object.keys(e)}function I(a){for(var b=a.length,e={},g=0;g<b;g++){var l=a[g],n;for(n in l)A.call(l,n)&&
void 0!==l[n]&&(e[n]=(e[n]||0)+1)}for(var y in e)e[y]<b&&delete e[y];return Object.keys(e)}function B(a,b){return{operations:a.operations.concat(b),cost:a.cost+1}}function J(a,b,e,g){function l(q,m){var t=q+","+m,r=n[t];if(void 0===r){if(0<q&&0<m&&!g(a[q-1],b[m-1],new p).length)r=l(q-1,m-1);else{r=[];if(0<q){var z=l(q-1,m);r.push(B(z,{op:"remove",index:q-1}))}0<m&&(z=l(q,m-1),r.push(B(z,{op:"add",index:q-1,value:b[m-1]})));0<q&&0<m&&(z=l(q-1,m-1),r.push(B(z,{op:"replace",index:q-1,original:a[q-1],
value:b[m-1]})));r=r.sort(function(K,L){return K.cost-L.cost})[0]}n[t]=r}return r}g=void 0===g?w:g;var n={"0,0":{operations:[],cost:0}},y=isNaN(a.length)||0>=a.length?0:a.length,C=isNaN(b.length)||0>=b.length?0:b.length;C=l(y,C).operations;return $jscomp.makeIterator(C.reduce(function(q,m){var t=$jscomp.makeIterator(q);q=t.next().value;t=t.next().value;if("add"===m.op){var r=m.index+1+t;m={op:m.op,path:e.add(r<y+t?String(r):"-").toString(),value:m.value};return[q.concat(m),t+1]}if("remove"===m.op)return m=
{op:m.op,path:e.add(String(m.index+t)).toString()},[q.concat(m),t-1];r=e.add(String(m.index+t));m=g(m.original,m.value,r);return[q.concat.apply(q,$jscomp.arrayFromIterable(m)),t]},[[],0])).next().value}function M(a,b,e,g){g=void 0===g?w:g;var l=[];x(a,b).forEach(function(n){l.push({op:"remove",path:e.add(n).toString()})});x(b,a).forEach(function(n){l.push({op:"add",path:e.add(n).toString(),value:b[n]})});I([a,b]).forEach(function(n){l.push.apply(l,$jscomp.arrayFromIterable(g(a[n],b[n],e.add(n))))});
return l}function w(a,b,e,g){g=void 0===g?w:g;if(a===b)return[];var l=k(a),n=k(b);return"array"==l&&"array"==n?J(a,b,e,g):"object"==l&&"object"==n?M(a,b,e,g):[{op:"replace",path:e.toString(),value:b}]}function D(a,b,e){Array.isArray(a)?"-"==b?a.push(e):(b=parseInt(b,10),a.splice(b,0,e)):a[b]=e}function E(a,b){Array.isArray(a)?(b=parseInt(b,10),a.splice(b,1)):delete a[b]}function N(a,b){a=p.fromJSON(b.path).evaluate(a);if(null===a.parent)return new v(b.path);if(Array.isArray(a.parent)){if(parseInt(a.key,
10)>=a.parent.length)return new v(b.path)}else if(void 0===a.value)return new v(b.path);a.parent[a.key]=b.value;return null}function O(a,b){switch(b.op){case "add":return a=p.fromJSON(b.path).evaluate(a),void 0===a.parent?b=new v(b.path):(D(a.parent,a.key,h(b.value)),b=null),b;case "remove":return a=p.fromJSON(b.path).evaluate(a),void 0===a.value?b=new v(b.path):(E(a.parent,a.key),b=null),b;case "replace":return N(a,b);case "move":var e=p.fromJSON(b.from).evaluate(a);void 0===e.value?b=new v(b.from):
(a=p.fromJSON(b.path).evaluate(a),void 0===a.parent?b=new v(b.path):(E(e.parent,e.key),D(a.parent,a.key,e.value),b=null));return b;case "copy":return e=p.fromJSON(b.from).evaluate(a),void 0===e.value?b=new v(b.from):(a=p.fromJSON(b.path).evaluate(a),void 0===a.parent?b=new v(b.path):(D(a.parent,a.key,h(e.value)),b=null)),b;case "test":return a=p.fromJSON(b.path).evaluate(a),b=w(a.value,b.value,new p).length?new F(a.value,b.value):null,b}return new G(b)}function P(a){function b(e,g,l){var n=a(e,g,
l);return Array.isArray(n)?n:w(e,g,l,b)}return b}function H(a,b){a=p.fromJSON(b).evaluate(a);if(void 0!==a)return{op:"test",path:b,value:a.value}}var p=function(a){this.tokens=a=void 0===a?[""]:a};p.fromJSON=function(a){var b=a.split("/").map(d);if(""!==b[0])throw Error("Invalid JSON Pointer: "+a);return new p(b)};p.prototype.toString=function(){return this.tokens.map(f).join("/")};p.prototype.evaluate=function(a){for(var b=null,e="",g=1,l=this.tokens.length;g<l;g++)b=a,e=this.tokens[g],a=(b||{})[e];
return{parent:b,key:e,value:a}};p.prototype.get=function(a){return this.evaluate(a).value};p.prototype.set=function(a,b){for(var e=1,g=this.tokens.length-1,l=this.tokens[e];e<g;e++)a=(a||{})[l];a&&(a[this.tokens[this.tokens.length-1]]=b)};p.prototype.push=function(a){this.tokens.push(a)};p.prototype.add=function(a){a=this.tokens.concat(String(a));return new p(a)};var A=Object.prototype.hasOwnProperty,v=function(a){var b=Error.call(this,"Value required at path: "+a);this.message=b.message;"stack"in
b&&(this.stack=b.stack);this.path=a;this.name="MissingError"};$jscomp.inherits(v,Error);var F=function(a,b){var e=Error.call(this,"Test failed: "+a+" != "+b);this.message=e.message;"stack"in e&&(this.stack=e.stack);this.actual=a;this.expected=b;this.name="TestError"};$jscomp.inherits(F,Error);var G=function(a){var b=Error.call(this,"Invalid operation: "+a.op);this.message=b.message;"stack"in b&&(this.stack=b.stack);this.operation=a;this.name="InvalidOperationError"};$jscomp.inherits(G,Error);c.applyPatch=
function(a,b){return b.map(function(e){return O(a,e)})};c.createPatch=function(a,b,e){var g=new p;return(e?P(e):w)(a,b,g)};c.createTests=function(a,b){var e=[];b.filter(u).forEach(function(g){var l=H(a,g.path);l&&e.push(l);"from"in g&&(g=H(a,g.from))&&e.push(g)});return e};Object.defineProperty(c,"__esModule",{value:!0})});
(function(p,r){"object"===typeof exports&&"undefined"!==typeof module?r(exports):"function"===typeof define&&define.amd?define(["exports"],r):(p="undefined"!==typeof globalThis?globalThis:p||self,r(p.rfc6902={}))})(this,function(p){function r(a){return a.replace(/~1/g,"/").replace(/~0/g,"~")}function E(a){return a.replace(/~/g,"~0").replace(/\//g,"~1")}function z(a){return void 0===a?"undefined":null===a?"null":Array.isArray(a)?"array":typeof a}function v(a){if(null==a||"object"!=typeof a)return a;
if(a.constructor==Array){var b=a.length,c=Array(b);for(let d=0;d<b;d++)c[d]=v(a[d]);return c}if(a.constructor==Date)return new Date(+a);b={};for(c in a)w.call(a,c)&&(b[c]=v(a[c]));return b}function F({op:a}){return"remove"===a||"replace"===a||"copy"===a||"move"===a}function A(a,b){const c={};for(const d in a)w.call(a,d)&&void 0!==a[d]&&(c[d]=1);for(const d in b)w.call(b,d)&&void 0!==b[d]&&delete c[d];return Object.keys(c)}function G(a){const b=a.length,c={};for(let d=0;d<b;d++){const e=a[d];for(const f in e)w.call(e,
f)&&void 0!==e[f]&&(c[f]=(c[f]||0)+1)}for(const d in c)c[d]<b&&delete c[d];return Object.keys(c)}function x(a,b){return{operations:a.operations.concat(b),cost:a.cost+1}}function H(a,b,c,d=q){function e(k,g){const h=`${k},${g}`;var l=f[h];if(void 0===l){if(0<k&&0<g&&!d(a[k-1],b[g-1],new m).length)l=e(k-1,g-1);else{l=[];if(0<k){var t=e(k-1,g);l.push(x(t,{op:"remove",index:k-1}))}0<g&&(t=e(k,g-1),l.push(x(t,{op:"add",index:k-1,value:b[g-1]})));0<k&&0<g&&(t=e(k-1,g-1),l.push(x(t,{op:"replace",index:k-
1,original:a[k-1],value:b[g-1]})));l=l.sort((I,J)=>I.cost-J.cost)[0]}f[h]=l}return l}const f={"0,0":{operations:[],cost:0}},B=isNaN(a.length)||0>=a.length?0:a.length;var u=isNaN(b.length)||0>=b.length?0:b.length;u=e(B,u).operations;[u]=u.reduce(([k,g],h)=>{if("add"===h.op){var l=h.index+1+g;h={op:h.op,path:c.add(l<B+g?String(l):"-").toString(),value:h.value};return[k.concat(h),g+1]}if("remove"===h.op)return h={op:h.op,path:c.add(String(h.index+g)).toString()},[k.concat(h),g-1];l=c.add(String(h.index+
g));h=d(h.original,h.value,l);return[k.concat(...h),g]},[[],0]);return u}function K(a,b,c,d=q){const e=[];A(a,b).forEach(f=>{e.push({op:"remove",path:c.add(f).toString()})});A(b,a).forEach(f=>{e.push({op:"add",path:c.add(f).toString(),value:b[f]})});G([a,b]).forEach(f=>{e.push(...d(a[f],b[f],c.add(f)))});return e}function q(a,b,c,d=q){if(a===b)return[];const e=z(a),f=z(b);return"array"==e&&"array"==f?H(a,b,c,d):"object"==e&&"object"==f?K(a,b,c,d):[{op:"replace",path:c.toString(),value:b}]}function y(a,
b,c){Array.isArray(a)?"-"==b?a.push(c):(b=parseInt(b,10),a.splice(b,0,c)):a[b]=c}function C(a,b){Array.isArray(a)?(b=parseInt(b,10),a.splice(b,1)):delete a[b]}function L(a,b){a=m.fromJSON(b.path).evaluate(a);if(null===a.parent)return new n(b.path);if(Array.isArray(a.parent)){if(parseInt(a.key,10)>=a.parent.length)return new n(b.path)}else if(void 0===a.value)return new n(b.path);a.parent[a.key]=b.value;return null}function M(a,b){switch(b.op){case "add":return a=m.fromJSON(b.path).evaluate(a),void 0===
a.parent?b=new n(b.path):(y(a.parent,a.key,v(b.value)),b=null),b;case "remove":return a=m.fromJSON(b.path).evaluate(a),void 0===a.value?b=new n(b.path):(C(a.parent,a.key),b=null),b;case "replace":return L(a,b);case "move":var c=m.fromJSON(b.from).evaluate(a);void 0===c.value?b=new n(b.from):(a=m.fromJSON(b.path).evaluate(a),void 0===a.parent?b=new n(b.path):(C(c.parent,c.key),y(a.parent,a.key,c.value),b=null));return b;case "copy":return c=m.fromJSON(b.from).evaluate(a),void 0===c.value?b=new n(b.from):
(a=m.fromJSON(b.path).evaluate(a),void 0===a.parent?b=new n(b.path):(y(a.parent,a.key,v(c.value)),b=null)),b;case "test":return a=m.fromJSON(b.path).evaluate(a),b=q(a.value,b.value,new m).length?new N(a.value,b.value):null,b}return new O(b)}function P(a){function b(c,d,e){const f=a(c,d,e);return Array.isArray(f)?f:q(c,d,e,b)}return b}function D(a,b){a=m.fromJSON(b).evaluate(a);if(void 0!==a)return{op:"test",path:b,value:a.value}}class m{constructor(a=[""]){this.tokens=a}static fromJSON(a){const b=
a.split("/").map(r);if(""!==b[0])throw Error(`Invalid JSON Pointer: ${a}`);return new m(b)}toString(){return this.tokens.map(E).join("/")}evaluate(a){let b=null,c="";for(let d=1,e=this.tokens.length;d<e;d++)b=a,c=this.tokens[d],"__proto__"!=c&&"constructor"!=c&&"prototype"!=c&&(a=(b||{})[c]);return{parent:b,key:c,value:a}}get(a){return this.evaluate(a).value}set(a,b){for(let c=1,d=this.tokens.length-1,e=this.tokens[c];c<d;c++)a=(a||{})[e];a&&(a[this.tokens[this.tokens.length-1]]=b)}push(a){this.tokens.push(a)}add(a){a=
this.tokens.concat(String(a));return new m(a)}}const w=Object.prototype.hasOwnProperty;class n extends Error{constructor(a){super(`Value required at path: ${a}`);this.path=a;this.name="MissingError"}}class N extends Error{constructor(a,b){super(`Test failed: ${a} != ${b}`);this.actual=a;this.expected=b;this.name="TestError"}}class O extends Error{constructor(a){super(`Invalid operation: ${a.op}`);this.operation=a;this.name="InvalidOperationError"}}p.applyPatch=function(a,b){return b.map(c=>M(a,c))};
p.createPatch=function(a,b,c){const d=new m;return(c?P(c):q)(a,b,d)};p.createTests=function(a,b){const c=[];b.filter(F).forEach(d=>{const e=D(a,d.path);e&&c.push(e);"from"in d&&(d=D(a,d.from))&&c.push(d)});return c};Object.defineProperty(p,"__esModule",{value:!0})});
{
"name": "rfc6902",
"version": "4.0.2",
"version": "5.0.0",
"description": "Complete implementation of RFC6902 (patch and diff)",

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

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

key = this.tokens[i];
if (key == '__proto__' || key == 'constructor' || key == 'prototype') {
continue;
}
// not sure if this the best way to handle non-existant paths...

@@ -73,0 +76,0 @@ value = (parent || {})[key];

@@ -14,5 +14,10 @@ # rfc6902

## Demo
Simple [web app](https://chbrown.github.io/rfc6902/) using the browser-compiled version of the code.
## Quickstart
#### Install locally:
### Install locally

@@ -23,3 +28,3 @@ ```sh

#### Import in your script:
### Import in your script

@@ -30,3 +35,3 @@ ```js

#### Calculate diff between two objects:
### Calculate diff between two objects

@@ -38,3 +43,3 @@ ```js

#### Apply a patch to some object:
### Apply a patch to some object

@@ -59,3 +64,3 @@ ```js

# API
## API

@@ -87,2 +92,5 @@ In ES6 syntax:

<details>
<summary>Optional <code>diff</code> argument</summary>
The optional `diff` argument allows the user to specify a partial function

@@ -101,2 +109,4 @@ that's called before the built-in `diffAny` function.

</details>
### `Operation`

@@ -117,9 +127,40 @@

## Demo
## Changelog
Simple [web app](https://chbrown.github.io/rfc6902) using the browser-compiled version of the code.
I'm not going to copy & paste my relatively descriptive commit messages into groups here;
rather, these are just the changes that merited major version bumps:
### `4.x.x` → `5.0.0` (2021-12-15)
## Determinism
* Short-circuits JSON pointer traversal over the prototype-polluting tokens `__proto__`, `constructor`, and `prototype`. I.e., `/a/__proto__/b` and `/a/b` evaluate to the same thing.
This is in violation of the spec,
which makes no special provisions for this idiosyncrasy of the JavaScript language,
but AFAIK there's no way to strictly comply with the spec in JavaScript.
It would probably be more correct to throw an error in those cases,
but this 'solution' feels less disruptive / more in line with workarounds implemented by other libraries.
### `3.x.x` → `4.0.0` (2020-07-27)
* Potential performance regression due to consolidating separate `compare(a, b): boolean` and `diff(a, b): Operation[]` logic into basically defining `compare(a, b)` as `!diff(a, b).length` (i.e., `diff(a, b)` returns empty array).
This simplifies the codebase and ensures underlying semantics do not diverge,
but potentially does unnecessary work in computing a full diff when all we really care about is whether there is at least one difference.
It also facilitates the user completely specifying custom diff functionality with just one `diff` function,
as opposed to a `diff` and corresponding `compare`
(and avoids the headache of having to propagate both of those around internally).
### `2.x.x` → `3.0.0` (2018-09-17)
* Corrects improper behavior in a few buggy edge cases,
which might conceivably break consumers relying on incorrect behavior.
(Tbh [that applies to most bugfixes](https://xkcd.com/1172/) but I felt there were enough to add up to incrementing the major version.)
* Also moves around some of the internal API that was not intended to be used externally,
but technically _was_ exported.
If you're only importing the public API of `applyPatch`, `createPatch`, and `createTests` from `'rfc6902'`,
nothing has changed.
## Implementation details
### Determinism
If you've ever implemented Levenshtein's algorithm,

@@ -152,7 +193,4 @@ or played tricks with `git rebase` to get a reasonable sequence of commits,

### JSON Pointer (RFC6901)
# Tutorial
## JSON Pointer (RFC6901)
The [RFC](http://tools.ietf.org/html/rfc6901) is a quick and easy read, but here's the gist:

@@ -215,3 +253,3 @@

**Rules:**
#### Rules:

@@ -232,3 +270,3 @@ * A pointer, if it is not empty, must always start with a slash;

### Example
#### Example

@@ -248,5 +286,4 @@ This project implements JSON Pointer functionality in `rfc6902/pointer`; e.g.:

### JSON Patch (RFC6902)
## JSON Patch (RFC6902)
The [RFC](http://tools.ietf.org/html/rfc6902) is only 18 pages long, but here are the basics:

@@ -292,3 +329,3 @@

Copyright 2014-2019 Christopher Brown.
[MIT Licensed](https://chbrown.github.io/licenses/MIT/#2014-2019).
Copyright 2014-2021 Christopher Brown.
[MIT Licensed](https://chbrown.github.io/licenses/MIT/#2014-2021).
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