8
0

createAssigner.js 983 B

12345678910111213141516171819202122232425262728293031323334
  1. import isIterateeCall from './isIterateeCall';
  2. import rest from '../rest';
  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 rest(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 = typeof customizer == 'function' ? (length--, customizer) : undefined;
  17. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  18. customizer = length < 3 ? undefined : customizer;
  19. length = 1;
  20. }
  21. object = Object(object);
  22. while (++index < length) {
  23. var source = sources[index];
  24. if (source) {
  25. assigner(object, source, index, customizer);
  26. }
  27. }
  28. return object;
  29. });
  30. }
  31. export default createAssigner;