object-merge-advanced
Advanced tools
Comparing version
/** | ||
* @name object-merge-advanced | ||
* @fileoverview Recursively, deeply merge of anything (objects, arrays, strings or nested thereof), which weighs contents by type hierarchy to ensure the maximum content is retained | ||
* @version 13.0.5 | ||
* @version 13.0.6 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -18,29 +18,27 @@ * @license MIT | ||
var version$1 = "13.0.5"; | ||
var version$1 = "13.0.6"; | ||
const defaults$1 = { | ||
arrayVsArrayAllMustBeFound: "any", | ||
caseSensitive: true | ||
arrayVsArrayAllMustBeFound: "any", | ||
caseSensitive: true, | ||
}; | ||
function includesWithGlob(originalInput, stringToFind, originalOpts) { | ||
if (!originalInput.length || !stringToFind.length) { | ||
return false; | ||
} | ||
const opts = { ...defaults$1, | ||
...originalOpts | ||
}; | ||
const input = typeof originalInput === "string" ? [originalInput] : Array.from(originalInput); | ||
if (typeof stringToFind === "string") { | ||
return input.some(val => isMatch(val, stringToFind, { | ||
caseSensitive: opts.caseSensitive | ||
})); | ||
} | ||
if (opts.arrayVsArrayAllMustBeFound === "any") { | ||
return stringToFind.some(stringToFindVal => input.some(val => isMatch(val, stringToFindVal, { | ||
caseSensitive: opts.caseSensitive | ||
if (!originalInput.length || !stringToFind.length) { | ||
return false; | ||
} | ||
const opts = { ...defaults$1, ...originalOpts }; | ||
const input = typeof originalInput === "string" | ||
? [originalInput] | ||
: Array.from(originalInput); | ||
if (typeof stringToFind === "string") { | ||
return input.some((val) => isMatch(val, stringToFind, { caseSensitive: opts.caseSensitive })); | ||
} | ||
if (opts.arrayVsArrayAllMustBeFound === "any") { | ||
return stringToFind.some((stringToFindVal) => input.some((val) => isMatch(val, stringToFindVal, { | ||
caseSensitive: opts.caseSensitive, | ||
}))); | ||
} | ||
return stringToFind.every((stringToFindVal) => input.some((val) => isMatch(val, stringToFindVal, { | ||
caseSensitive: opts.caseSensitive, | ||
}))); | ||
} | ||
return stringToFind.every(stringToFindVal => input.some(val => isMatch(val, stringToFindVal, { | ||
caseSensitive: opts.caseSensitive | ||
}))); | ||
} | ||
@@ -50,499 +48,522 @@ | ||
function isStr(something) { | ||
return typeof something === "string"; | ||
return typeof something === "string"; | ||
} | ||
function isNum(something) { | ||
return typeof something === "number"; | ||
return typeof something === "number"; | ||
} | ||
function isBool(something) { | ||
return typeof something === "boolean"; | ||
return typeof something === "boolean"; | ||
} | ||
const isArr = Array.isArray; | ||
function arrayContainsStr(arr) { | ||
return !!arr && arr.some(val => typeof val === "string"); | ||
return !!arr && arr.some((val) => typeof val === "string"); | ||
} | ||
function equalOrSubsetKeys(obj1, obj2) { | ||
return Object.keys(obj1).length === 0 || Object.keys(obj2).length === 0 || Object.keys(obj1).every(val => Object.keys(obj2).includes(val)) || Object.keys(obj2).every(val => Object.keys(obj1).includes(val)); | ||
return (Object.keys(obj1).length === 0 || | ||
Object.keys(obj2).length === 0 || | ||
Object.keys(obj1).every((val) => Object.keys(obj2).includes(val)) || | ||
Object.keys(obj2).every((val) => Object.keys(obj1).includes(val))); | ||
} | ||
function getType(something) { | ||
if (something === null) { | ||
return "null"; | ||
} | ||
if (isDate(something)) { | ||
return "date"; | ||
} | ||
if (isObj(something)) { | ||
return "object"; | ||
} | ||
if (isArr(something)) { | ||
return "array"; | ||
} | ||
return typeof something; | ||
if (something === null) { | ||
return "null"; | ||
} | ||
if (isDate(something)) { | ||
return "date"; | ||
} | ||
if (isObj(something)) { | ||
return "object"; | ||
} | ||
if (isArr(something)) { | ||
return "array"; | ||
} | ||
return typeof something; | ||
} | ||
const defaults = { | ||
cb: null, | ||
mergeObjectsOnlyWhenKeysetMatches: true, | ||
ignoreKeys: [], | ||
hardMergeKeys: [], | ||
hardArrayConcatKeys: [], | ||
mergeArraysContainingStringsToBeEmpty: false, | ||
oneToManyArrayObjectMerge: false, | ||
hardMergeEverything: false, | ||
hardArrayConcat: false, | ||
ignoreEverything: false, | ||
concatInsteadOfMerging: true, | ||
dedupeStringsInArrayValues: false, | ||
mergeBoolsUsingOrNotAnd: true, | ||
useNullAsExplicitFalse: false | ||
cb: null, | ||
mergeObjectsOnlyWhenKeysetMatches: true, | ||
ignoreKeys: [], | ||
hardMergeKeys: [], | ||
hardArrayConcatKeys: [], | ||
mergeArraysContainingStringsToBeEmpty: false, | ||
oneToManyArrayObjectMerge: false, | ||
hardMergeEverything: false, | ||
hardArrayConcat: false, | ||
ignoreEverything: false, | ||
concatInsteadOfMerging: true, | ||
dedupeStringsInArrayValues: false, | ||
mergeBoolsUsingOrNotAnd: true, | ||
useNullAsExplicitFalse: false, | ||
}; | ||
function mergeAdvanced(infoObj, input1orig, input2orig, originalOpts) { | ||
const opts = { ...defaults, | ||
...originalOpts | ||
}; | ||
if (typeof opts.ignoreKeys === "string") { | ||
opts.ignoreKeys = [opts.ignoreKeys]; | ||
} | ||
if (typeof opts.hardMergeKeys === "string") { | ||
opts.hardMergeKeys = [opts.hardMergeKeys]; | ||
} | ||
if (opts.hardMergeKeys.includes("*")) { | ||
opts.hardMergeEverything = true; | ||
} | ||
if (opts.ignoreKeys.includes("*")) { | ||
opts.ignoreEverything = true; | ||
} | ||
let currPath; | ||
if (opts.useNullAsExplicitFalse && (input1orig === null || input2orig === null)) { | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(input1orig, input2orig, null, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
const opts = { ...defaults, ...originalOpts }; | ||
if (typeof opts.ignoreKeys === "string") { | ||
opts.ignoreKeys = [opts.ignoreKeys]; | ||
} | ||
return null; | ||
} | ||
let i1 = isArr(input1orig) || isObj(input1orig) ? clone(input1orig) : input1orig; | ||
const i2 = isArr(input2orig) || isObj(input2orig) ? clone(input2orig) : input2orig; | ||
let uniRes; | ||
if (opts.ignoreEverything) { | ||
uniRes = i1; | ||
} else if (opts.hardMergeEverything) { | ||
uniRes = i2; | ||
} | ||
const uni = opts.hardMergeEverything || opts.ignoreEverything; | ||
if (isArr(i1)) { | ||
if (nonEmpty(i1)) { | ||
if (isArr(i2) && nonEmpty(i2)) { | ||
if (opts.mergeArraysContainingStringsToBeEmpty && (arrayContainsStr(i1) || arrayContainsStr(i2))) { | ||
const currentResult = uni ? uniRes : []; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
if (typeof opts.hardMergeKeys === "string") { | ||
opts.hardMergeKeys = [opts.hardMergeKeys]; | ||
} | ||
if (opts.hardMergeKeys.includes("*")) { | ||
opts.hardMergeEverything = true; | ||
} | ||
if (opts.ignoreKeys.includes("*")) { | ||
opts.ignoreEverything = true; | ||
} | ||
let currPath; | ||
if (opts.useNullAsExplicitFalse && | ||
(input1orig === null || input2orig === null)) { | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(input1orig, input2orig, null, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (opts.hardArrayConcat) { | ||
const currentResult = uni ? uniRes : i1.concat(i2); | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
return null; | ||
} | ||
let i1 = isArr(input1orig) || isObj(input1orig) ? clone(input1orig) : input1orig; | ||
const i2 = isArr(input2orig) || isObj(input2orig) ? clone(input2orig) : input2orig; | ||
let uniRes; | ||
if (opts.ignoreEverything) { | ||
uniRes = i1; | ||
} | ||
else if (opts.hardMergeEverything) { | ||
uniRes = i2; | ||
} | ||
const uni = opts.hardMergeEverything || opts.ignoreEverything; | ||
if (isArr(i1)) { | ||
if (nonEmpty(i1)) { | ||
if (isArr(i2) && nonEmpty(i2)) { | ||
if (opts.mergeArraysContainingStringsToBeEmpty && | ||
(arrayContainsStr(i1) || arrayContainsStr(i2))) { | ||
const currentResult = uni ? uniRes : []; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (opts.hardArrayConcat) { | ||
const currentResult = uni ? uniRes : i1.concat(i2); | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
let temp = []; | ||
for (let index = 0, len = Math.max(i1.length, i2.length); index < len; index++) { | ||
currPath = | ||
infoObj.path && infoObj.path.length | ||
? `${infoObj.path}.${index}` | ||
: `${index}`; | ||
if (isObj(i1[index]) && | ||
isObj(i2[index]) && | ||
((opts.mergeObjectsOnlyWhenKeysetMatches && | ||
equalOrSubsetKeys(i1[index], i2[index])) || | ||
!opts.mergeObjectsOnlyWhenKeysetMatches)) { | ||
temp.push(mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[index], i2[index], opts)); | ||
} | ||
else if (opts.oneToManyArrayObjectMerge && | ||
(i1.length === 1 || i2.length === 1) | ||
) { | ||
temp.push(i1.length === 1 | ||
? mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[0], i2[index], opts) | ||
: mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[index], i2[0], opts)); | ||
} | ||
else if (opts.concatInsteadOfMerging) { | ||
if (index < i1.length) { | ||
temp.push(i1[index]); | ||
} | ||
if (index < i2.length) { | ||
temp.push(i2[index]); | ||
} | ||
} | ||
else { | ||
if (index < i1.length) { | ||
temp.push(i1[index]); | ||
} | ||
if (index < i2.length && !lodashIncludes(i1, i2[index])) { | ||
temp.push(i2[index]); | ||
} | ||
} | ||
} | ||
if (opts.dedupeStringsInArrayValues && temp.every((el) => isStr(el))) { | ||
temp = uniq(temp).sort(); | ||
} | ||
i1 = clone(temp); | ||
} | ||
else { | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
} | ||
let temp = []; | ||
for (let index = 0, len = Math.max(i1.length, i2.length); index < len; index++) { | ||
currPath = infoObj.path && infoObj.path.length ? `${infoObj.path}.${index}` : `${index}`; | ||
if (isObj(i1[index]) && isObj(i2[index]) && (opts.mergeObjectsOnlyWhenKeysetMatches && equalOrSubsetKeys(i1[index], i2[index]) || !opts.mergeObjectsOnlyWhenKeysetMatches)) { | ||
temp.push(mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[index], i2[index], opts)); | ||
} else if (opts.oneToManyArrayObjectMerge && (i1.length === 1 || i2.length === 1) | ||
) { | ||
temp.push(i1.length === 1 ? mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[0], i2[index], opts) : mergeAdvanced({ | ||
path: currPath, | ||
key: infoObj.key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[index], i2[0], opts)); | ||
} else if (opts.concatInsteadOfMerging) { | ||
if (index < i1.length) { | ||
temp.push(i1[index]); | ||
else { | ||
if (nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (index < i2.length) { | ||
temp.push(i2[index]); | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
} else { | ||
if (index < i1.length) { | ||
temp.push(i1[index]); | ||
return currentResult; | ||
} | ||
} | ||
else if (isObj(i1)) { | ||
if (nonEmpty(i1)) { | ||
if (isArr(i2)) { | ||
if (nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (index < i2.length && !lodashIncludes(i1, i2[index])) { | ||
temp.push(i2[index]); | ||
if (isObj(i2)) { | ||
Object.keys(i2).forEach((key) => { | ||
currPath = | ||
infoObj.path && infoObj.path.length | ||
? `${infoObj.path}.${key}` | ||
: `${key}`; | ||
if (i1.hasOwnProperty(key)) { | ||
if (includesWithGlob(key, opts.ignoreKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[key], i2[key], { ...opts, ignoreEverything: true }); | ||
} | ||
else if (includesWithGlob(key, opts.hardMergeKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[key], i2[key], { ...opts, hardMergeEverything: true }); | ||
} | ||
else if (includesWithGlob(key, opts.hardArrayConcatKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)], | ||
}, i1[key], i2[key], { ...opts, hardArrayConcat: true }); | ||
} | ||
else { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1[key]), getType(i2[key])], | ||
}, i1[key], i2[key], opts); | ||
} | ||
} | ||
else { | ||
i1[key] = i2[key]; | ||
} | ||
}); | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return i1; | ||
} | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (opts.dedupeStringsInArrayValues && temp.every(el => isStr(el))) { | ||
temp = uniq(temp).sort(); | ||
if (isArr(i2) || isObj(i2) || nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
i1 = clone(temp); | ||
} else { | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
} else { | ||
if (nonEmpty(i2)) { | ||
} | ||
else if (isDate(i1)) { | ||
if (isFinite(i1)) { | ||
if (isDate(i2)) { | ||
if (isFinite(i2)) { | ||
const currentResult = uni ? uniRes : i1 > i2 ? i1 : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i2 ? i2 : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (isDate(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
} else if (isObj(i1)) { | ||
if (nonEmpty(i1)) { | ||
if (isArr(i2)) { | ||
if (nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
else if (isStr(i1)) { | ||
if (nonEmpty(i1)) { | ||
if ((isArr(i2) || isObj(i2) || isStr(i2)) && nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (i2 != null && !isBool(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
return currentResult; | ||
} | ||
else if (isNum(i1)) { | ||
if (nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: currPath, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (isObj(i2)) { | ||
Object.keys(i2).forEach(key => { | ||
currPath = infoObj.path && infoObj.path.length ? `${infoObj.path}.${key}` : `${key}`; | ||
if (i1.hasOwnProperty(key)) { | ||
if (includesWithGlob(key, opts.ignoreKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[key], i2[key], { ...opts, | ||
ignoreEverything: true | ||
}); | ||
} else if (includesWithGlob(key, opts.hardMergeKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[key], i2[key], { ...opts, | ||
hardMergeEverything: true | ||
}); | ||
} else if (includesWithGlob(key, opts.hardArrayConcatKeys)) { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1), getType(i2)] | ||
}, i1[key], i2[key], { ...opts, | ||
hardArrayConcat: true | ||
}); | ||
} else { | ||
i1[key] = mergeAdvanced({ | ||
path: currPath, | ||
key, | ||
type: [getType(i1[key]), getType(i2[key])] | ||
}, i1[key], i2[key], opts); | ||
} | ||
else if (isBool(i1)) { | ||
if (isBool(i2)) { | ||
if (opts.mergeBoolsUsingOrNotAnd) { | ||
const currentResult = uni ? uniRes : i1 || i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
} else { | ||
i1[key] = i2[key]; | ||
} | ||
}); | ||
const currentResult = uni ? uniRes : i1 && i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (i2 != null) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return i1; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (isArr(i2) || isObj(i2) || nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else if (isDate(i1)) { | ||
if (isFinite(i1)) { | ||
if (isDate(i2)) { | ||
if (isFinite(i2)) { | ||
const currentResult = uni ? uniRes : i1 > i2 ? i1 : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
return currentResult; | ||
} | ||
else if (i1 === null) { | ||
if (i2 != null) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i2 ? i2 : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (isDate(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else if (isStr(i1)) { | ||
if (nonEmpty(i1)) { | ||
if ((isArr(i2) || isObj(i2) || isStr(i2)) && nonEmpty(i2)) { | ||
else { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (i2 != null && !isBool(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else if (isNum(i1)) { | ||
if (nonEmpty(i2)) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else if (isBool(i1)) { | ||
if (isBool(i2)) { | ||
if (opts.mergeBoolsUsingOrNotAnd) { | ||
const currentResult = uni ? uniRes : i1 || i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1 && i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
type: infoObj.type, | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
if (i2 != null) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else if (i1 === null) { | ||
if (i2 != null) { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} else { | ||
const currentResult = uni ? uniRes : i2; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
const currentResult = uni ? uniRes : i1; | ||
if (typeof opts.cb === "function") { | ||
return opts.cb(clone(input1orig), clone(input2orig), currentResult, { | ||
path: infoObj.path, | ||
key: infoObj.key, | ||
type: infoObj.type | ||
}); | ||
} | ||
return currentResult; | ||
} | ||
function externalApi(input1orig, input2orig, originalOpts) { | ||
if (!arguments.length) { | ||
throw new TypeError("object-merge-advanced/mergeAdvanced(): [THROW_ID_01] Both inputs are missing"); | ||
} | ||
return mergeAdvanced({ | ||
key: null, | ||
path: "", | ||
type: [getType(input1orig), getType(input2orig)] | ||
}, input1orig, input2orig, originalOpts); | ||
if (!arguments.length) { | ||
throw new TypeError("object-merge-advanced/mergeAdvanced(): [THROW_ID_01] Both inputs are missing"); | ||
} | ||
return mergeAdvanced({ key: null, path: "", type: [getType(input1orig), getType(input2orig)] }, input1orig, input2orig, originalOpts); | ||
} | ||
export { defaults, externalApi as mergeAdvanced, version }; |
/** | ||
* @name object-merge-advanced | ||
* @fileoverview Recursively, deeply merge of anything (objects, arrays, strings or nested thereof), which weighs contents by type hierarchy to ensure the maximum content is retained | ||
* @version 13.0.5 | ||
* @version 13.0.6 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -14,6 +14,6 @@ * @license MIT | ||
* @fileoverview Is the input (plain object, array, string or whatever) not empty? | ||
* @version 4.0.5 | ||
* @version 4.0.6 | ||
* @author Roy Revelt, Codsen Ltd | ||
* @license MIT | ||
* {@link https://codsen.com/os/util-nonempty/} | ||
*/function Pt(t){return null!=t&&(Array.isArray(t)||"string"==typeof t?!!t.length:mt(t)?!!Object.keys(t).length:"number"==typeof t)}function It(t){return"string"==typeof t}function Bt(t){return"boolean"==typeof t}const Ct=Array.isArray;function Nt(t){return!!t&&t.some((t=>"string"==typeof t))}function Rt(t,e){return 0===Object.keys(t).length||0===Object.keys(e).length||Object.keys(t).every((t=>Object.keys(e).includes(t)))||Object.keys(e).every((e=>Object.keys(t).includes(e)))}function Ut(t){return null===t?"null":xt(t)?"date":mt(t)?"object":Ct(t)?"array":typeof t}const Dt={cb:null,mergeObjectsOnlyWhenKeysetMatches:!0,ignoreKeys:[],hardMergeKeys:[],hardArrayConcatKeys:[],mergeArraysContainingStringsToBeEmpty:!1,oneToManyArrayObjectMerge:!1,hardMergeEverything:!1,hardArrayConcat:!1,ignoreEverything:!1,concatInsteadOfMerging:!0,dedupeStringsInArrayValues:!1,mergeBoolsUsingOrNotAnd:!0,useNullAsExplicitFalse:!1};function Vt(t,e,n,o){const c={...Dt,...o};let u;if("string"==typeof c.ignoreKeys&&(c.ignoreKeys=[c.ignoreKeys]),"string"==typeof c.hardMergeKeys&&(c.hardMergeKeys=[c.hardMergeKeys]),c.hardMergeKeys.includes("*")&&(c.hardMergeEverything=!0),c.ignoreKeys.includes("*")&&(c.ignoreEverything=!0),c.useNullAsExplicitFalse&&(null===e||null===n))return"function"==typeof c.cb?c.cb(e,n,null,{path:t.path,key:t.key,type:t.type}):null;let i=Ct(e)||mt(e)?r(e):e;const a=Ct(n)||mt(n)?r(n):n;let f;c.ignoreEverything?f=i:c.hardMergeEverything&&(f=a);const s=c.hardMergeEverything||c.ignoreEverything;if(!Ct(i)){if(mt(i)){if(Pt(i)){if(Ct(a)){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(mt(a)){Object.keys(a).forEach((e=>{u=t.path&&t.path.length?`${t.path}.${e}`:`${e}`,i[e]=i.hasOwnProperty(e)?Kt(e,c.ignoreKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,ignoreEverything:!0}):Kt(e,c.hardMergeKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,hardMergeEverything:!0}):Kt(e,c.hardArrayConcatKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,hardArrayConcat:!0}):Vt({path:u,key:e,type:[Ut(i[e]),Ut(a[e])]},i[e],a[e],c):a[e]}));const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):i}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(Ct(a)||mt(a)||Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(xt(i)){if(isFinite(i)){if(xt(a)){if(isFinite(a)){const o=s?f:i>a?i:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:a||i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(xt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(It(i)){if(Pt(i)){if((Ct(a)||mt(a)||It(a))&&Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null!=a&&!Bt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if("number"==typeof i){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(Bt(i)){if(Bt(a)){if(c.mergeBoolsUsingOrNotAnd){const o=s?f:i||a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i&&a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null!=a){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null===i){if(null!=a){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}{const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}}if(!Pt(i)){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(!Ct(a)||!Pt(a)){const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}{if(c.mergeArraysContainingStringsToBeEmpty&&(Nt(i)||Nt(a))){const o=s?f:[];return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(c.hardArrayConcat){const o=s?f:i.concat(a);return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}let o=[];for(let e=0,n=Math.max(i.length,a.length);e<n;e++)u=t.path&&t.path.length?`${t.path}.${e}`:`${e}`,mt(i[e])&&mt(a[e])&&(c.mergeObjectsOnlyWhenKeysetMatches&&Rt(i[e],a[e])||!c.mergeObjectsOnlyWhenKeysetMatches)?o.push(Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[e],a[e],c)):!c.oneToManyArrayObjectMerge||1!==i.length&&1!==a.length?c.concatInsteadOfMerging?(e<i.length&&o.push(i[e]),e<a.length&&o.push(a[e])):(e<i.length&&o.push(i[e]),e<a.length&&!B(i,a[e])&&o.push(a[e])):o.push(1===i.length?Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[0],a[e],c):Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[e],a[0],c));c.dedupeStringsInArrayValues&&o.every((t=>It(t)))&&(o=vt(o).sort()),i=r(o)}const p=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),p,{path:t.path,key:t.key,type:t.type}):p}t.defaults=Dt,t.mergeAdvanced=function(t,e,n){if(!arguments.length)throw new TypeError("object-merge-advanced/mergeAdvanced(): [THROW_ID_01] Both inputs are missing");return Vt({key:null,path:"",type:[Ut(t),Ut(e)]},t,e,n)},t.version="13.0.5",Object.defineProperty(t,"__esModule",{value:!0})})); | ||
*/function Pt(t){return null!=t&&(Array.isArray(t)||"string"==typeof t?!!t.length:mt(t)?!!Object.keys(t).length:"number"==typeof t)}function It(t){return"string"==typeof t}function Bt(t){return"boolean"==typeof t}const Ct=Array.isArray;function Nt(t){return!!t&&t.some((t=>"string"==typeof t))}function Rt(t,e){return 0===Object.keys(t).length||0===Object.keys(e).length||Object.keys(t).every((t=>Object.keys(e).includes(t)))||Object.keys(e).every((e=>Object.keys(t).includes(e)))}function Ut(t){return null===t?"null":xt(t)?"date":mt(t)?"object":Ct(t)?"array":typeof t}const Dt={cb:null,mergeObjectsOnlyWhenKeysetMatches:!0,ignoreKeys:[],hardMergeKeys:[],hardArrayConcatKeys:[],mergeArraysContainingStringsToBeEmpty:!1,oneToManyArrayObjectMerge:!1,hardMergeEverything:!1,hardArrayConcat:!1,ignoreEverything:!1,concatInsteadOfMerging:!0,dedupeStringsInArrayValues:!1,mergeBoolsUsingOrNotAnd:!0,useNullAsExplicitFalse:!1};function Vt(t,e,n,o){const c={...Dt,...o};let u;if("string"==typeof c.ignoreKeys&&(c.ignoreKeys=[c.ignoreKeys]),"string"==typeof c.hardMergeKeys&&(c.hardMergeKeys=[c.hardMergeKeys]),c.hardMergeKeys.includes("*")&&(c.hardMergeEverything=!0),c.ignoreKeys.includes("*")&&(c.ignoreEverything=!0),c.useNullAsExplicitFalse&&(null===e||null===n))return"function"==typeof c.cb?c.cb(e,n,null,{path:t.path,key:t.key,type:t.type}):null;let i=Ct(e)||mt(e)?r(e):e;const a=Ct(n)||mt(n)?r(n):n;let f;c.ignoreEverything?f=i:c.hardMergeEverything&&(f=a);const s=c.hardMergeEverything||c.ignoreEverything;if(!Ct(i)){if(mt(i)){if(Pt(i)){if(Ct(a)){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(mt(a)){Object.keys(a).forEach((e=>{u=t.path&&t.path.length?`${t.path}.${e}`:`${e}`,i[e]=i.hasOwnProperty(e)?Kt(e,c.ignoreKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,ignoreEverything:!0}):Kt(e,c.hardMergeKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,hardMergeEverything:!0}):Kt(e,c.hardArrayConcatKeys)?Vt({path:u,key:e,type:[Ut(i),Ut(a)]},i[e],a[e],{...c,hardArrayConcat:!0}):Vt({path:u,key:e,type:[Ut(i[e]),Ut(a[e])]},i[e],a[e],c):a[e]}));const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):i}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(Ct(a)||mt(a)||Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(xt(i)){if(isFinite(i)){if(xt(a)){if(isFinite(a)){const o=s?f:i>a?i:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:a||i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(xt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(It(i)){if(Pt(i)){if((Ct(a)||mt(a)||It(a))&&Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null!=a&&!Bt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if("number"==typeof i){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(Bt(i)){if(Bt(a)){if(c.mergeBoolsUsingOrNotAnd){const o=s?f:i||a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i&&a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null!=a){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}if(null===i){if(null!=a){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}{const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:t.path,key:t.key,type:t.type}):o}}if(!Pt(i)){if(Pt(a)){const o=s?f:a;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(!Ct(a)||!Pt(a)){const o=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}{if(c.mergeArraysContainingStringsToBeEmpty&&(Nt(i)||Nt(a))){const o=s?f:[];return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}if(c.hardArrayConcat){const o=s?f:i.concat(a);return"function"==typeof c.cb?c.cb(r(e),r(n),o,{path:u,key:t.key,type:t.type}):o}let o=[];for(let e=0,n=Math.max(i.length,a.length);e<n;e++)u=t.path&&t.path.length?`${t.path}.${e}`:`${e}`,mt(i[e])&&mt(a[e])&&(c.mergeObjectsOnlyWhenKeysetMatches&&Rt(i[e],a[e])||!c.mergeObjectsOnlyWhenKeysetMatches)?o.push(Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[e],a[e],c)):!c.oneToManyArrayObjectMerge||1!==i.length&&1!==a.length?c.concatInsteadOfMerging?(e<i.length&&o.push(i[e]),e<a.length&&o.push(a[e])):(e<i.length&&o.push(i[e]),e<a.length&&!B(i,a[e])&&o.push(a[e])):o.push(1===i.length?Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[0],a[e],c):Vt({path:u,key:t.key,type:[Ut(i),Ut(a)]},i[e],a[0],c));c.dedupeStringsInArrayValues&&o.every((t=>It(t)))&&(o=vt(o).sort()),i=r(o)}const p=s?f:i;return"function"==typeof c.cb?c.cb(r(e),r(n),p,{path:t.path,key:t.key,type:t.type}):p}t.defaults=Dt,t.mergeAdvanced=function(t,e,n){if(!arguments.length)throw new TypeError("object-merge-advanced/mergeAdvanced(): [THROW_ID_01] Both inputs are missing");return Vt({key:null,path:"",type:[Ut(t),Ut(e)]},t,e,n)},t.version="13.0.6",Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "object-merge-advanced", | ||
"version": "13.0.5", | ||
"version": "13.0.6", | ||
"description": "Recursively, deeply merge of anything (objects, arrays, strings or nested thereof), which weighs contents by type hierarchy to ensure the maximum content is retained", | ||
@@ -35,9 +35,8 @@ "keywords": [ | ||
"build": "rollup -c", | ||
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov", | ||
"clean_cov": "../../scripts/leaveCoverageTotalOnly.js", | ||
"build:esbuild": "node '../../scripts/esbuild.js'", | ||
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'", | ||
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent", | ||
"clean_types": "../../scripts/cleanTypes.js", | ||
"dev": "rollup -c --dev", | ||
"devunittest": "npm run dev && tap --only -R 'base'", | ||
"esbuild": "node '../../scripts/esbuild.js'", | ||
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'", | ||
"format": "npm run lect && npm run prettier && npm run lint", | ||
@@ -51,13 +50,10 @@ "lect": "lect", | ||
"pretest": "npm run build", | ||
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format", | ||
"test": "npm run test:ci && npm run perf", | ||
"test:ci": "npm run unittest && npm run test:examples && npm run format", | ||
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier", | ||
"tsc": "tsc", | ||
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf" | ||
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit" | ||
}, | ||
"tap": { | ||
"check-coverage": false, | ||
"coverage-report": [ | ||
"json-summary", | ||
"text" | ||
], | ||
"node-arg": [ | ||
@@ -89,3 +85,3 @@ "--no-warnings", | ||
"dependencies": { | ||
"@babel/runtime": "^7.16.0", | ||
"@babel/runtime": "^7.16.3", | ||
"lodash.clonedeep": "^4.5.0", | ||
@@ -97,3 +93,3 @@ "lodash.includes": "^4.3.0", | ||
"matcher": "^5.0.0", | ||
"util-nonempty": "^4.0.5" | ||
"util-nonempty": "^4.0.6" | ||
}, | ||
@@ -109,4 +105,4 @@ "devDependencies": { | ||
"@babel/plugin-proposal-optional-chaining": "^7.16.0", | ||
"@babel/plugin-transform-runtime": "^7.16.0", | ||
"@babel/preset-env": "^7.16.0", | ||
"@babel/plugin-transform-runtime": "^7.16.4", | ||
"@babel/preset-env": "^7.16.4", | ||
"@babel/preset-typescript": "^7.16.0", | ||
@@ -126,12 +122,12 @@ "@babel/register": "^7.16.0", | ||
"@types/lodash.uniq": "^4.5.6", | ||
"@types/node": "^16.11.6", | ||
"@types/node": "^16.11.9", | ||
"@types/tap": "^15.0.5", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"@typescript-eslint/eslint-plugin": "^5.4.0", | ||
"@typescript-eslint/parser": "^5.4.0", | ||
"core-js": "^3.19.1", | ||
"cross-env": "^7.0.3", | ||
"deep-equal": "^2.0.5", | ||
"eslint": "^8.2.0", | ||
"lect": "^0.18.5", | ||
"rollup": "^2.59.0", | ||
"eslint": "^8.3.0", | ||
"lect": "^0.18.6", | ||
"rollup": "^2.60.0", | ||
"rollup-plugin-ascii": "^0.0.3", | ||
@@ -142,9 +138,9 @@ "rollup-plugin-banner": "^0.2.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"tap": "^15.0.10", | ||
"tap": "^15.1.2", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.4" | ||
"typescript": "^4.5.2" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
} | ||
} |
70131
6.07%739
2.92%Updated
Updated