Keine Beschreibung

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var isExtendable = require('is-extendable');
  3. var forIn = require('for-in');
  4. function mixinDeep(target, objects) {
  5. var len = arguments.length, i = 0;
  6. while (++i < len) {
  7. var obj = arguments[i];
  8. if (isObject(obj)) {
  9. forIn(obj, copy, target);
  10. }
  11. }
  12. return target;
  13. }
  14. /**
  15. * Copy properties from the source object to the
  16. * target object.
  17. *
  18. * @param {*} `val`
  19. * @param {String} `key`
  20. */
  21. function copy(val, key) {
  22. if (key === '__proto__') {
  23. return;
  24. }
  25. var obj = this[key];
  26. if (isObject(val) && isObject(obj)) {
  27. mixinDeep(obj, val);
  28. } else {
  29. this[key] = val;
  30. }
  31. }
  32. /**
  33. * Returns true if `val` is an object or function.
  34. *
  35. * @param {any} val
  36. * @return {Boolean}
  37. */
  38. function isObject(val) {
  39. return isExtendable(val) && !Array.isArray(val);
  40. }
  41. /**
  42. * Expose `mixinDeep`
  43. */
  44. module.exports = mixinDeep;