@domql/utils
Advanced tools
Comparing version 2.3.91 to 2.3.92
@@ -29,2 +29,4 @@ "use strict"; | ||
diff: () => diff, | ||
diffArrays: () => diffArrays, | ||
diffObjects: () => diffObjects, | ||
exec: () => exec, | ||
@@ -249,18 +251,43 @@ flattenRecursive: () => flattenRecursive, | ||
}; | ||
const diff = (obj, original, cache) => { | ||
const changes = cache || {}; | ||
for (const e in obj) { | ||
const diffObjects = (original, objToDiff, cache) => { | ||
for (const e in objToDiff) { | ||
if (e === "ref") | ||
continue; | ||
const originalProp = original[e]; | ||
const objProp = obj[e]; | ||
if ((0, import_types.isObjectLike)(originalProp) && (0, import_types.isObjectLike)(objProp)) { | ||
changes[e] = {}; | ||
diff(originalProp, objProp, changes[e]); | ||
} else if (objProp !== void 0) { | ||
changes[e] = objProp; | ||
const objToDiffProp = objToDiff[e]; | ||
if ((0, import_types.isObject)(originalProp) && (0, import_types.isObject)(objToDiffProp)) { | ||
cache[e] = {}; | ||
diff(originalProp, objToDiffProp, cache[e]); | ||
} else if (objToDiffProp !== void 0) { | ||
cache[e] = objToDiffProp; | ||
} | ||
} | ||
return changes; | ||
return cache; | ||
}; | ||
const diffArrays = (original, objToDiff, cache) => { | ||
if (original.length !== objToDiff.length) { | ||
cache = objToDiff; | ||
} else { | ||
const diffArr = []; | ||
for (let i = 0; i < original.length; i++) { | ||
const diffObj = diff(original[i], objToDiff[i]); | ||
if (Object.keys(diffObj).length > 0) { | ||
diffArr.push(diffObj); | ||
} | ||
} | ||
if (diffArr.length > 0) { | ||
cache = diffArr; | ||
} | ||
} | ||
return cache; | ||
}; | ||
const diff = (original, objToDiff, cache = {}) => { | ||
if ((0, import_types.isArray)(original) && (0, import_types.isArray)(objToDiff)) { | ||
cache = []; | ||
diffArrays(original, objToDiff, cache); | ||
} else { | ||
diffObjects(original, objToDiff, cache); | ||
} | ||
return cache; | ||
}; | ||
const overwriteObj = (params, obj) => { | ||
@@ -267,0 +294,0 @@ const changes = {}; |
@@ -232,18 +232,48 @@ 'use strict' | ||
export const diff = (obj, original, cache) => { | ||
const changes = cache || {} | ||
for (const e in obj) { | ||
export const diffObjects = (original, objToDiff, cache) => { | ||
for (const e in objToDiff) { | ||
if (e === 'ref') continue | ||
const originalProp = original[e] | ||
const objProp = obj[e] | ||
if (isObjectLike(originalProp) && isObjectLike(objProp)) { | ||
changes[e] = {} | ||
diff(originalProp, objProp, changes[e]) | ||
} else if (objProp !== undefined) { | ||
changes[e] = objProp | ||
const objToDiffProp = objToDiff[e] | ||
if (isObject(originalProp) && isObject(objToDiffProp)) { | ||
cache[e] = {} | ||
diff(originalProp, objToDiffProp, cache[e]) | ||
} else if (objToDiffProp !== undefined) { | ||
cache[e] = objToDiffProp | ||
} | ||
} | ||
return changes | ||
return cache | ||
} | ||
export const diffArrays = (original, objToDiff, cache) => { | ||
if (original.length !== objToDiff.length) { | ||
cache = objToDiff | ||
} else { | ||
const diffArr = [] | ||
for (let i = 0; i < original.length; i++) { | ||
const diffObj = diff(original[i], objToDiff[i]) | ||
if (Object.keys(diffObj).length > 0) { | ||
diffArr.push(diffObj) | ||
} | ||
} | ||
if (diffArr.length > 0) { | ||
cache = diffArr | ||
} | ||
} | ||
return cache | ||
} | ||
export const diff = (original, objToDiff, cache = {}) => { | ||
if (isArray(original) && isArray(objToDiff)) { | ||
cache = [] | ||
diffArrays(original, objToDiff, cache) | ||
} else { | ||
diffObjects(original, objToDiff, cache) | ||
} | ||
return cache | ||
} | ||
/** | ||
@@ -268,3 +298,3 @@ * Overwrites object properties with another | ||
/** | ||
* Overwrites DEEPly object properties with another | ||
* Overwrites DEEPLY object properties with another | ||
*/ | ||
@@ -271,0 +301,0 @@ export const overwriteDeep = (params, obj) => { |
{ | ||
"name": "@domql/utils", | ||
"version": "2.3.91", | ||
"version": "2.3.92", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "type": "module", | ||
}, | ||
"gitHead": "8a3dee2d0d71ad50ddcc09c47281cbb634c3f0bf" | ||
"gitHead": "dc86022df601a498fca8c9af5be9e40dcf36ddbf" | ||
} |
36424
1117