19 lines
497 B
JavaScript
Raw Normal View History

2023-10-25 14:27:07 -06:00
import { isPlainObject } from "is-plain-object";
function mergeDeep(defaults, options) {
const result = Object.assign({}, defaults);
Object.keys(options).forEach((key) => {
if (isPlainObject(options[key])) {
if (!(key in defaults))
Object.assign(result, { [key]: options[key] });
else
result[key] = mergeDeep(defaults[key], options[key]);
} else {
Object.assign(result, { [key]: options[key] });
}
});
return result;
2022-11-03 10:55:07 -06:00
}
2023-10-25 14:27:07 -06:00
export {
mergeDeep
};