merge-deep.js 538 B

12345678910111213141516
  1. import isPlainObject from "is-plain-object";
  2. export function mergeDeep(defaults, options) {
  3. const result = Object.assign({}, defaults);
  4. Object.keys(options).forEach((key) => {
  5. if (isPlainObject(options[key])) {
  6. if (!(key in defaults))
  7. Object.assign(result, { [key]: options[key] });
  8. else
  9. result[key] = mergeDeep(defaults[key], options[key]);
  10. }
  11. else {
  12. Object.assign(result, { [key]: options[key] });
  13. }
  14. });
  15. return result;
  16. }