ppd-utils
Version:
utils
20 lines (18 loc) • 616 B
JavaScript
const { isObject } = require("./type");
function merge(target, source) {
let output = Object.assign({}, target || source);
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!(key in target))
Object.assign(output, { [key]: source[key] });
else
output[key] = merge(target[key], source[key]);
} else {
Object.assign(output, { [key]: source[key] });
}
});
}
return output;
}
module.exports = merge;