You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

  1. var baseRest = require('./_baseRest'),
  2. isIterateeCall = require('./_isIterateeCall');
  3. /**
  4. * Creates a function like `_.assign`.
  5. *
  6. * @private
  7. * @param {Function} assigner The function to assign values.
  8. * @returns {Function} Returns the new assigner function.
  9. */
  10. function createAssigner(assigner) {
  11. return baseRest(function(object, sources) {
  12. var index = -1,
  13. length = sources.length,
  14. customizer = length > 1 ? sources[length - 1] : undefined,
  15. guard = length > 2 ? sources[2] : undefined;
  16. customizer = (assigner.length > 3 && typeof customizer == 'function')
  17. ? (length--, customizer)
  18. : undefined;
  19. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  20. customizer = length < 3 ? undefined : customizer;
  21. length = 1;
  22. }
  23. object = Object(object);
  24. while (++index < length) {
  25. var source = sources[index];
  26. if (source) {
  27. assigner(object, source, index, customizer);
  28. }
  29. }
  30. return object;
  31. });
  32. }
  33. module.exports = createAssigner;