Comparing version 1.2.0 to 1.3.0
@@ -5,2 +5,3 @@ interface Difference { | ||
value?: any; | ||
oldValue?: any; | ||
} | ||
@@ -7,0 +8,0 @@ interface Options { |
@@ -10,5 +10,6 @@ const t = true; | ||
let diffs = []; | ||
const isObjArray = Array.isArray(obj); | ||
for (const key in obj) { | ||
const objKey = obj[key]; | ||
const path = Array.isArray(obj) ? +key : key; | ||
const path = isObjArray ? +key : key; | ||
if (!(key in newObj)) { | ||
@@ -18,2 +19,3 @@ diffs.push({ | ||
path: [path], | ||
oldValue: obj[key], | ||
}); | ||
@@ -58,5 +60,7 @@ continue; | ||
value: newObjKey, | ||
oldValue: objKey, | ||
}); | ||
} | ||
} | ||
const isNewObjArray = Array.isArray(newObj); | ||
for (const key in newObj) { | ||
@@ -66,3 +70,3 @@ if (!(key in obj)) { | ||
type: "CREATE", | ||
path: [Array.isArray(newObj) ? +key : key], | ||
path: [isNewObjArray ? +key : key], | ||
value: newObj[key], | ||
@@ -69,0 +73,0 @@ }); |
{ | ||
"name": "microdiff", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Small, fast, zero dependency deep object and array comparison", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
@@ -55,3 +55,4 @@ <div align="center"> | ||
Each element in the paths is a key to the next property a level deeper until you get to the property changed, and it is string or a number, depending on whether the object is an Array or Object (Objects with number keys will still be strings). | ||
The `value` property exists in types `CREATE` and `CHANGE`, and it contains the value of the property added/changed. | ||
The `value` property exists in types `CREATE` and `CHANGE`, and it contains the value of the property added/changed/deleted. | ||
The `oldValue` property exists in the type `CHANGE` and `REMOVE`, and it contains the old value of the property. | ||
@@ -58,0 +59,0 @@ # Cycles support |
Sorry, the diff of this file is not supported yet
8845
160
83