@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
33 lines (30 loc) • 756 B
JavaScript
import { isObject } from './chunk-2JFFF2CE.mjs';
// src/mergeDeep.ts
function mergeDeep(target, ...sources) {
if (sources.length === 0) {
return target;
}
const source = sources.shift();
if (source === void 0) {
return target;
}
if (isObject(target) && isObject(source)) {
const sourceKeys = Object.keys(source);
for (const key of sourceKeys) {
if (isObject(source[key])) {
if (!target[key]) {
target[key] = {};
}
if (isObject(target[key])) {
mergeDeep(target[key], source[key]);
} else {
target[key] = source[key];
}
} else {
target[key] = source[key];
}
}
}
return mergeDeep(target, ...sources);
}
export { mergeDeep };