Home Reference Source

src/config/defaultsDeep.js

  1. 'use strict';
  2.  
  3. module.exports = function defaultsDeep(target, objects) {
  4. target = target || {};
  5.  
  6. function copy(target, current) {
  7. for (var key in current) {
  8. if (current.hasOwnProperty(key)) {
  9. var value = current[key]
  10. if (key === '__proto__') {
  11. continue;
  12. }
  13. var val = target[key];
  14. // add the missing property, or allow a null property to be updated
  15. if (val == null) {
  16. target[key] = value;
  17. } else if (typeof val === 'object' && val !== null && typeof value === 'object' && value !== null) {
  18. defaultsDeep(val, value);
  19. }
  20. }
  21. }
  22. }
  23.  
  24. var len = arguments.length, i = 0;
  25. while (i < len) {
  26. var obj = arguments[i++];
  27. if (obj) {
  28. copy(target, obj);
  29. }
  30. }
  31. return target;
  32. };