Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
25 lines
955 B
Plaintext
25 lines
955 B
Plaintext
/**
|
|
* Very simple, but fast deepMerge implementation. Only deepMerges objects, not arrays and clones everything.
|
|
* Do not use this if your object contains any complex objects like React Components, or if you would like to combine Arrays.
|
|
* If you only have simple objects and need a fast deepMerge, this is the function for you.
|
|
*
|
|
* obj2 takes precedence over obj1 - thus if obj2 has a key that obj1 also has, obj2's value will be used.
|
|
*
|
|
* @param obj1 base object
|
|
* @param obj2 object to merge "into" obj1
|
|
*/export function deepMergeSimple(obj1, obj2) {
|
|
const output = {
|
|
...obj1
|
|
};
|
|
for (const key in obj2) {
|
|
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
if (typeof obj2[key] === 'object' && !Array.isArray(obj2[key]) && obj1[key]) {
|
|
output[key] = deepMergeSimple(obj1[key], obj2[key]);
|
|
} else {
|
|
output[key] = obj2[key];
|
|
}
|
|
}
|
|
}
|
|
return output;
|
|
}
|
|
//# sourceMappingURL=deepMerge.js.map |