@polgubau/utils
Version:
A collection of utility functions for TypeScript
23 lines • 761 B
JavaScript
// src/objects/merge-deep/merge-deep.ts
import { isObject } from "../../comparators/index.mjs";
import { cloneDeep } from "../clone-deps/clone-deep.mjs";
function mergeDeep(target, source) {
if (isObject(source) && Object.keys(source).length === 0) {
return cloneDeep({ ...target, ...source });
}
const output = { ...target, ...source };
if (isObject(source) && isObject(target)) {
for (const key in source) {
if (isObject(source[key]) && key in target && isObject(target[key])) {
output[key] = mergeDeep(target[key], source[key]);
} else {
output[key] = isObject(source[key]) ? cloneDeep(source[key]) : source[key];
}
}
}
return output;
}
export {
mergeDeep
};
//# sourceMappingURL=merge-deep.mjs.map