Sin descripción

mutable.js 747B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var each = require('array-each');
  3. var slice = require('array-slice');
  4. var forOwn = require('for-own');
  5. var isObject = require('isobject');
  6. /**
  7. * Extends the `target` object with properties of one or
  8. * more additional `objects`
  9. *
  10. * @name .defaults
  11. * @param {Object} `target` The target object. Pass an empty object to shallow clone.
  12. * @param {Object} `objects`
  13. * @return {Object}
  14. * @api public
  15. */
  16. module.exports = function defaults(target, objects) {
  17. if (target == null) {
  18. return {};
  19. }
  20. each(slice(arguments, 1), function(obj) {
  21. if (isObject(obj)) {
  22. forOwn(obj, function(val, key) {
  23. if (target[key] == null) {
  24. target[key] = val;
  25. }
  26. });
  27. }
  28. });
  29. return target;
  30. };