Socket
Socket
Sign inDemoInstall

recursive-diff

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.5 to 1.0.6

1

CHANGELOG.md

@@ -15,2 +15,3 @@ - 0.1.1 - Added support of **null** value for any key in a object.

- 1.0.5 - Updated README
- 1.0.6 - Added support for including `oldVal` in the diff object using an optional third parameter in the `getDiff` API

@@ -17,0 +18,0 @@ [1]: https://github.com/IsabellaCerbino

2

dist/recursive-diff.js

@@ -117,3 +117,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

eval("const { types, iterableTypes, errors } = __webpack_require__(/*! ./config */ \"./src/config.js\");\nconst utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nconst checkType = {\n [types.NUMBER]: utils.isNumber,\n [types.BOOLEAN]: utils.isBoolean,\n [types.STRING]: utils.isString,\n [types.DATE]: utils.isDate,\n [types.UNDEFINED]: utils.isUndefined,\n [types.NULL]: utils.isNull,\n [types.ARRAY]: utils.isArray,\n [types.MAP]: utils.isMap,\n [types.SET]: utils.isSet,\n [types.ITERABLE_OBJECT]: utils.isIterableObject,\n};\n\nconst checkEqualityForComplexTypes = {\n [types.DATE]: utils.areDatesEqual,\n};\n\nfunction getType(x) {\n const keys = Object.keys(checkType);\n let type = types.DEFAULT;\n for (let i = 0; i < keys.length; i += 1) {\n if (checkType[keys[i]](x)) {\n type = keys[i];\n break;\n }\n }\n return type;\n}\n\nfunction isTraversalNeeded(type1, type2) {\n return type1 === type2 && iterableTypes.indexOf(type1) >= 0;\n}\n\nfunction areEqual(x, y, type1, type2) {\n if (type1 !== type2) {\n return false;\n }\n return checkEqualityForComplexTypes[type1] ? checkEqualityForComplexTypes[type1](x, y) : x === y;\n}\n\nfunction compareValuesAndGetDiff(x, y, type1, type2, path, diff) {\n if (type1 === types.UNDEFINED && type2 !== types.UNDEFINED) {\n diff.push({\n path,\n op: 'add',\n val: y,\n });\n } else if (type1 !== types.UNDEFINED && type2 === types.UNDEFINED) {\n diff.push({\n path,\n op: 'delete',\n val: y,\n });\n } else if (!(areEqual(x, y, type1, type2))) {\n diff.push({\n path,\n op: 'update',\n val: y,\n });\n } else {\n utils.noop();\n }\n}\n\nfunction getKeys(x, y, type) {\n let keys;\n if (type === types.ITERABLE_OBJECT) {\n keys = new Set(Object.keys(x).concat(Object.keys(y)));\n } else if (type === types.ARRAY) {\n keys = x.length > y.length ? new Array(x.length) : new Array(y.length);\n keys = keys.fill(0, 0);\n keys = keys.map((el, i) => i);\n keys = new Set(keys);\n }\n return keys;\n}\n\nfunction getDiff(x, y, path, diff) {\n const type1 = getType(x);\n const type2 = getType(y);\n const currPath = path || [];\n const currDiff = diff || [];\n if (isTraversalNeeded(type1, type2)) {\n const iterator = getKeys(x, y, type1).values();\n let key = iterator.next().value;\n while (key != null) {\n getDiff(x[key], y[key], currPath.concat(key), currDiff);\n key = iterator.next().value;\n }\n } else {\n compareValuesAndGetDiff(x, y, type1, type2, path, currDiff);\n }\n return currDiff;\n}\n\n\nconst opHandlers = {\n add: utils.setValueByPath,\n update: utils.setValueByPath,\n delete: utils.deleteValueByPath,\n};\n\nfunction applyDiff(x, diff, visitorCallback) {\n if (!(diff instanceof Array)) throw new Error(errors.INVALID_DIFF_FORMAT);\n let y = x;\n diff.forEach((diffItem) => {\n const { op, val, path } = diffItem;\n if (!opHandlers[op]) {\n throw new Error(errors.INVALID_DIFF_OP);\n }\n y = opHandlers[op](y, path, val, visitorCallback);\n });\n return y;\n}\n\nmodule.exports = {\n getDiff,\n applyDiff,\n};\n\n\n//# sourceURL=webpack://recursiveDiff/./src/recursive-diff.js?");
eval("const { types, iterableTypes, errors } = __webpack_require__(/*! ./config */ \"./src/config.js\");\nconst utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nconst checkType = {\n [types.NUMBER]: utils.isNumber,\n [types.BOOLEAN]: utils.isBoolean,\n [types.STRING]: utils.isString,\n [types.DATE]: utils.isDate,\n [types.UNDEFINED]: utils.isUndefined,\n [types.NULL]: utils.isNull,\n [types.ARRAY]: utils.isArray,\n [types.MAP]: utils.isMap,\n [types.SET]: utils.isSet,\n [types.ITERABLE_OBJECT]: utils.isIterableObject,\n};\n\nconst checkEqualityForComplexTypes = {\n [types.DATE]: utils.areDatesEqual,\n};\n\nfunction getType(x) {\n const keys = Object.keys(checkType);\n let type = types.DEFAULT;\n for (let i = 0; i < keys.length; i += 1) {\n if (checkType[keys[i]](x)) {\n type = keys[i];\n break;\n }\n }\n return type;\n}\n\nfunction isTraversalNeeded(type1, type2) {\n return type1 === type2 && iterableTypes.indexOf(type1) >= 0;\n}\n\nfunction areEqual(x, y, type1, type2) {\n if (type1 !== type2) {\n return false;\n }\n return checkEqualityForComplexTypes[type1] ? checkEqualityForComplexTypes[type1](x, y) : x === y;\n}\n\nfunction computeOp(x, y, type1, type2) {\n let op;\n if (type1 === types.UNDEFINED && type2 !== types.UNDEFINED) {\n op = 'add';\n } else if (type1 !== types.UNDEFINED && type2 === types.UNDEFINED) {\n op = 'delete';\n } else if (!(areEqual(x, y, type1, type2))) {\n op = 'update';\n } else {\n utils.noop();\n }\n return op;\n}\n\nfunction getKeys(x, y, type) {\n let keys;\n if (type === types.ITERABLE_OBJECT) {\n keys = new Set(Object.keys(x).concat(Object.keys(y)));\n } else if (type === types.ARRAY) {\n keys = x.length > y.length ? new Array(x.length) : new Array(y.length);\n keys = keys.fill(0, 0);\n keys = keys.map((el, i) => i);\n keys = new Set(keys);\n }\n return keys;\n}\n\nfunction makeDiff(x, y, op, path, keepOldVal) {\n const diffOb = {\n op,\n path,\n };\n if (op === 'add' || op === 'update') {\n diffOb.val = y;\n }\n if (keepOldVal && op !== 'add') {\n diffOb.oldVal = x;\n }\n return diffOb;\n}\n\nfunction privateGetDiff(x, y, keepOldVal, path, diff) {\n const type1 = getType(x);\n const type2 = getType(y);\n const currPath = path || [];\n const currDiff = diff || [];\n if (isTraversalNeeded(type1, type2)) {\n const iterator = getKeys(x, y, type1).values();\n let key = iterator.next().value;\n while (key != null) {\n privateGetDiff(x[key], y[key], keepOldVal, currPath.concat(key), currDiff);\n key = iterator.next().value;\n }\n } else {\n const op = computeOp(x, y, type1, type2);\n if (op != null) {\n currDiff.push(makeDiff(x, y, op, path, keepOldVal));\n }\n }\n return currDiff;\n}\n\nconst opHandlers = {\n add: utils.setValueByPath,\n update: utils.setValueByPath,\n delete: utils.deleteValueByPath,\n};\n\nfunction privateApplyDiff(x, diff, visitorCallback) {\n if (!(diff instanceof Array)) throw new Error(errors.INVALID_DIFF_FORMAT);\n let y = x;\n diff.forEach((diffItem) => {\n const { op, val, path } = diffItem;\n if (!opHandlers[op]) {\n throw new Error(errors.INVALID_DIFF_OP);\n }\n y = opHandlers[op](y, path, val, visitorCallback);\n });\n return y;\n}\n\nmodule.exports = {\n getDiff(x, y, keepOldValInDiff = false) {\n return privateGetDiff(x, y, keepOldValInDiff);\n },\n applyDiff(x, diff, visitorCallback) {\n return privateApplyDiff(x, diff, visitorCallback);\n },\n};\n\n\n//# sourceURL=webpack://recursiveDiff/./src/recursive-diff.js?");

@@ -120,0 +120,0 @@ /***/ }),

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.recursiveDiff=t():e.recursiveDiff=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){const{types:r,iterableTypes:o,errors:i}=n(1),l=n(2),f={[r.NUMBER]:l.isNumber,[r.BOOLEAN]:l.isBoolean,[r.STRING]:l.isString,[r.DATE]:l.isDate,[r.UNDEFINED]:l.isUndefined,[r.NULL]:l.isNull,[r.ARRAY]:l.isArray,[r.MAP]:l.isMap,[r.SET]:l.isSet,[r.ITERABLE_OBJECT]:l.isIterableObject},u={[r.DATE]:l.areDatesEqual};function a(e){const t=Object.keys(f);let n=r.DEFAULT;for(let r=0;r<t.length;r+=1)if(f[t[r]](e)){n=t[r];break}return n}function s(e,t,n,o,i,f){n===r.UNDEFINED&&o!==r.UNDEFINED?f.push({path:i,op:"add",val:t}):n!==r.UNDEFINED&&o===r.UNDEFINED?f.push({path:i,op:"delete",val:t}):!function(e,t,n,r){return n===r&&(u[n]?u[n](e,t):e===t)}(e,t,n,o)?f.push({path:i,op:"update",val:t}):l.noop()}const c={add:l.setValueByPath,update:l.setValueByPath,delete:l.deleteValueByPath};e.exports={getDiff:function e(t,n,i,l){const f=a(t),u=a(n),c=i||[],p=l||[];if(function(e,t){return e===t&&o.indexOf(e)>=0}(f,u)){const o=function(e,t,n){let o;return n===r.ITERABLE_OBJECT?o=new Set(Object.keys(e).concat(Object.keys(t))):n===r.ARRAY&&(o=e.length>t.length?new Array(e.length):new Array(t.length),o=o.fill(0,0),o=o.map((e,t)=>t),o=new Set(o)),o}(t,n,f).values();let i=o.next().value;for(;null!=i;)e(t[i],n[i],c.concat(i),p),i=o.next().value}else s(t,n,f,u,i,p);return p},applyDiff:function(e,t,n){if(!(t instanceof Array))throw new Error(i.INVALID_DIFF_FORMAT);let r=e;return t.forEach(e=>{const{op:t,val:o,path:l}=e;if(!c[t])throw new Error(i.INVALID_DIFF_OP);r=c[t](r,l,o,n)}),r}}},function(e,t){const n={NUMBER:"NUMBER",BOOLEAN:"BOOLEAN",STRING:"STRING",NULL:"NULL",UNDEFINED:"UNDEFINED",DATE:"DATE",ARRAY:"ARRAY",MAP:"MAP",SET:"SET",ITERABLE_OBJECT:"ITERABLE_OBJECT",DEFAULT:"OBJECT"};e.exports={types:n,iterableTypes:[n.ITERABLE_OBJECT,n.MAP,n.ARRAY,n.SET],errors:{EMPTY_DIFF:"No diff object is provided, Nothing to apply",INVALID_DIFF_FORMAT:"Invalid diff format",INVALID_DIFF_OP:"Unsupported operation provided into diff object"}}},function(e,t){const n=e=>t=>t instanceof e,r=n(Date),o=n(Array),i=n(Map),l=n(Set),f=e=>"[object Object]"===Object.prototype.toString.call(e);e.exports={isNumber:e=>"number"==typeof e,isBoolean:e=>"boolean"==typeof e,isString:e=>"string"==typeof e,isDate:r,isUndefined:e=>void 0===e,isNull:e=>null===e,isArray:o,isMap:i,isSet:l,isIterableObject:f,noop:()=>{},areDatesEqual:(e,t)=>e.getTime()===t.getTime(),setValueByPath:function(e,t=[],n,r){if(!o(t))throw new Error(`Diff path: "${t}" is not valid`);const{length:i}=t;if(0===i)return n;let l=e;for(let o=0;o<i;o+=1){const f=t[o];if(!l)throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);if(null==f)throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);o!==i-1?(l=l[f],r&&r(l)):l[f]=n}return e},deleteValueByPath:function(e,t){const n=t||[];if(0===n.length)return;let r=e;const{length:o}=n;for(let i=0;i<o;i+=1)if(i!==o-1){if(!r[n[i]])throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);r=r[n[i]]}else if(f(r))delete r[n[i]];else{const e=parseInt(n[i],10);for(;r.length>e;)r.pop()}return e}}}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.recursiveDiff=t():e.recursiveDiff=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){const{types:r,iterableTypes:o,errors:i}=n(1),l=n(2),f={[r.NUMBER]:l.isNumber,[r.BOOLEAN]:l.isBoolean,[r.STRING]:l.isString,[r.DATE]:l.isDate,[r.UNDEFINED]:l.isUndefined,[r.NULL]:l.isNull,[r.ARRAY]:l.isArray,[r.MAP]:l.isMap,[r.SET]:l.isSet,[r.ITERABLE_OBJECT]:l.isIterableObject},u={[r.DATE]:l.areDatesEqual};function a(e){const t=Object.keys(f);let n=r.DEFAULT;for(let r=0;r<t.length;r+=1)if(f[t[r]](e)){n=t[r];break}return n}function s(e,t,n,o){let i;return n===r.UNDEFINED&&o!==r.UNDEFINED?i="add":n!==r.UNDEFINED&&o===r.UNDEFINED?i="delete":!function(e,t,n,r){return n===r&&(u[n]?u[n](e,t):e===t)}(e,t,n,o)?i="update":l.noop(),i}function c(e,t,n,i,l){const f=a(e),u=a(t),p=i||[],d=l||[];if(function(e,t){return e===t&&o.indexOf(e)>=0}(f,u)){const o=function(e,t,n){let o;return n===r.ITERABLE_OBJECT?o=new Set(Object.keys(e).concat(Object.keys(t))):n===r.ARRAY&&(o=e.length>t.length?new Array(e.length):new Array(t.length),o=o.fill(0,0),o=o.map((e,t)=>t),o=new Set(o)),o}(e,t,f).values();let i=o.next().value;for(;null!=i;)c(e[i],t[i],n,p.concat(i),d),i=o.next().value}else{const r=s(e,t,f,u);null!=r&&d.push(function(e,t,n,r,o){const i={op:n,path:r};return"add"!==n&&"update"!==n||(i.val=t),o&&"add"!==n&&(i.oldVal=e),i}(e,t,r,i,n))}return d}const p={add:l.setValueByPath,update:l.setValueByPath,delete:l.deleteValueByPath};e.exports={getDiff:(e,t,n=!1)=>c(e,t,n),applyDiff:(e,t,n)=>function(e,t,n){if(!(t instanceof Array))throw new Error(i.INVALID_DIFF_FORMAT);let r=e;return t.forEach(e=>{const{op:t,val:o,path:l}=e;if(!p[t])throw new Error(i.INVALID_DIFF_OP);r=p[t](r,l,o,n)}),r}(e,t,n)}},function(e,t){const n={NUMBER:"NUMBER",BOOLEAN:"BOOLEAN",STRING:"STRING",NULL:"NULL",UNDEFINED:"UNDEFINED",DATE:"DATE",ARRAY:"ARRAY",MAP:"MAP",SET:"SET",ITERABLE_OBJECT:"ITERABLE_OBJECT",DEFAULT:"OBJECT"};e.exports={types:n,iterableTypes:[n.ITERABLE_OBJECT,n.MAP,n.ARRAY,n.SET],errors:{EMPTY_DIFF:"No diff object is provided, Nothing to apply",INVALID_DIFF_FORMAT:"Invalid diff format",INVALID_DIFF_OP:"Unsupported operation provided into diff object"}}},function(e,t){const n=e=>t=>t instanceof e,r=n(Date),o=n(Array),i=n(Map),l=n(Set),f=e=>"[object Object]"===Object.prototype.toString.call(e);e.exports={isNumber:e=>"number"==typeof e,isBoolean:e=>"boolean"==typeof e,isString:e=>"string"==typeof e,isDate:r,isUndefined:e=>void 0===e,isNull:e=>null===e,isArray:o,isMap:i,isSet:l,isIterableObject:f,noop:()=>{},areDatesEqual:(e,t)=>e.getTime()===t.getTime(),setValueByPath:function(e,t=[],n,r){if(!o(t))throw new Error(`Diff path: "${t}" is not valid`);const{length:i}=t;if(0===i)return n;let l=e;for(let o=0;o<i;o+=1){const f=t[o];if(!l)throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);if(null==f)throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);o!==i-1?(l=l[f],r&&r(l)):l[f]=n}return e},deleteValueByPath:function(e,t){const n=t||[];if(0===n.length)return;let r=e;const{length:o}=n;for(let i=0;i<o;i+=1)if(i!==o-1){if(!r[n[i]])throw new Error(`Invalid path: "${t}" for object: ${JSON.stringify(e,null,2)}`);r=r[n[i]]}else if(f(r))delete r[n[i]];else{const e=parseInt(n[i],10);for(;r.length>e;)r.pop()}return e}}}])}));

@@ -14,2 +14,3 @@ export as namespace rdiff;

val: any;
oldVal?: any;
} | {

@@ -19,5 +20,6 @@ op: 'delete';

val: any;
oldVal?: any;
}
export function getDiff(A: any, B: any): rdiffResult[];
export function getDiff(A: any, B: any, C?: Boolean): rdiffResult[];
export function applyDiff(A: any, B: rdiffResult[], C?: Function): any;
}
{
"name": "recursive-diff",
"version": "1.0.5",
"version": "1.0.6",
"description": "Find diff between any two variables where variables be any valid JavaScript data type like string, numeric, array or object",

@@ -5,0 +5,0 @@ "main": "src/recursive-diff.js",

@@ -75,2 +75,4 @@ [![NPM Version][npm-image]][npm-url]

> Notes: `getDiff` also takes a third optional boolen parameter, `keepOldValueInDiff` which if set to true, every diff value will have an additional property `oldValue` which will denote the old value before mutation.
- **`applyDiff (x, diff, visitorCallbackFn)`** `applyDiff` takes three arguments:

@@ -98,5 +100,5 @@ - x: original value,

`'dist/recursive-diff.min.js'` can be directly injected into a HTML page using the URL `https://unpkg.com/recursive-diff@1.0.4/dist/recursive-diff.min.js`. Once it is included into the HTML file, diff API is accessible using `window.recursiveDiff`. Example given below.
`'dist/recursive-diff.min.js'` can be directly injected into a HTML page using the URL `https://unpkg.com/recursive-diff@latest/dist/recursive-diff.min.js`. Once it is included into the HTML file, diff API is accessible using `window.recursiveDiff`. Example given below.
<script type="text" src="https://unpkg.com/recursive-diff@1.0.2/dist/recursive-diff.min.js"/>
<script type="text" src="https://unpkg.com/recursive-diff@latest/dist/recursive-diff.min.js"/>
<script type="text/javascript">

@@ -115,3 +117,3 @@ const ob1 = {a:1};

const y = [2, 3, 4];
const diff:rdiffResult[] = getDiff([1, 2], 3);
const diff:rdiffResult[] = getDiff(x, y);
console.log('diff', diff);

@@ -147,3 +149,3 @@ const final = applyDiff(x, diff);

b = [1, 30, 40];
delta = getDiff(a, b);
delta = getDiff(a, b, true); // third parameter : keepOldValInDiff, see output below
console.log(delta);

@@ -153,3 +155,3 @@ /** *

[
{ path: [1], op: 'update', val: 30 },
{ path: [1], op: 'update', val: 30, oldVal: 2 },
{ path: [2], op: 'add', val: 40 },

@@ -156,0 +158,0 @@ ]

@@ -44,24 +44,14 @@ const { types, iterableTypes, errors } = require('./config');

function compareValuesAndGetDiff(x, y, type1, type2, path, diff) {
function computeOp(x, y, type1, type2) {
let op;
if (type1 === types.UNDEFINED && type2 !== types.UNDEFINED) {
diff.push({
path,
op: 'add',
val: y,
});
op = 'add';
} else if (type1 !== types.UNDEFINED && type2 === types.UNDEFINED) {
diff.push({
path,
op: 'delete',
val: y,
});
op = 'delete';
} else if (!(areEqual(x, y, type1, type2))) {
diff.push({
path,
op: 'update',
val: y,
});
op = 'update';
} else {
utils.noop();
}
return op;
}

@@ -82,3 +72,17 @@

function getDiff(x, y, path, diff) {
function makeDiff(x, y, op, path, keepOldVal) {
const diffOb = {
op,
path,
};
if (op === 'add' || op === 'update') {
diffOb.val = y;
}
if (keepOldVal && op !== 'add') {
diffOb.oldVal = x;
}
return diffOb;
}
function privateGetDiff(x, y, keepOldVal, path, diff) {
const type1 = getType(x);

@@ -92,7 +96,10 @@ const type2 = getType(y);

while (key != null) {
getDiff(x[key], y[key], currPath.concat(key), currDiff);
privateGetDiff(x[key], y[key], keepOldVal, currPath.concat(key), currDiff);
key = iterator.next().value;
}
} else {
compareValuesAndGetDiff(x, y, type1, type2, path, currDiff);
const op = computeOp(x, y, type1, type2);
if (op != null) {
currDiff.push(makeDiff(x, y, op, path, keepOldVal));
}
}

@@ -102,3 +109,2 @@ return currDiff;

const opHandlers = {

@@ -110,3 +116,3 @@ add: utils.setValueByPath,

function applyDiff(x, diff, visitorCallback) {
function privateApplyDiff(x, diff, visitorCallback) {
if (!(diff instanceof Array)) throw new Error(errors.INVALID_DIFF_FORMAT);

@@ -125,4 +131,8 @@ let y = x;

module.exports = {
getDiff,
applyDiff,
getDiff(x, y, keepOldValInDiff = false) {
return privateGetDiff(x, y, keepOldValInDiff);
},
applyDiff(x, diff, visitorCallback) {
return privateApplyDiff(x, diff, visitorCallback);
},
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc