UNPKG

ppd-utils

Version:
20 lines (18 loc) 616 B
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;