index.js 642 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var isObject = require('is-extendable');
  3. var forIn = require('for-in');
  4. function mixin(target, objects) {
  5. if (!isObject(target)) {
  6. throw new TypeError('mixin-object expects the first argument to be an object.');
  7. }
  8. var len = arguments.length, i = 0;
  9. while (++i < len) {
  10. var obj = arguments[i];
  11. if (isObject(obj)) {
  12. forIn(obj, copy, target);
  13. }
  14. }
  15. return target;
  16. }
  17. /**
  18. * copy properties from the source object to the
  19. * target object.
  20. *
  21. * @param {*} `value`
  22. * @param {String} `key`
  23. */
  24. function copy(value, key) {
  25. this[key] = value;
  26. }
  27. /**
  28. * Expose `mixin`
  29. */
  30. module.exports = mixin;