mirror of
https://github.com/diligencia/semantic-branch-version.git
synced 2024-11-24 07:13:50 +08:00
17 lines
538 B
JavaScript
17 lines
538 B
JavaScript
|
import isPlainObject from "is-plain-object";
|
||
|
export 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;
|
||
|
}
|