_composeArgs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Built-in method references for those with the same name as other `lodash` methods. */
  2. var nativeMax = Math.max;
  3. /**
  4. * Creates an array that is the composition of partially applied arguments,
  5. * placeholders, and provided arguments into a single array of arguments.
  6. *
  7. * @private
  8. * @param {Array} args The provided arguments.
  9. * @param {Array} partials The arguments to prepend to those provided.
  10. * @param {Array} holders The `partials` placeholder indexes.
  11. * @params {boolean} [isCurried] Specify composing for a curried function.
  12. * @returns {Array} Returns the new array of composed arguments.
  13. */
  14. function composeArgs(args, partials, holders, isCurried) {
  15. var argsIndex = -1,
  16. argsLength = args.length,
  17. holdersLength = holders.length,
  18. leftIndex = -1,
  19. leftLength = partials.length,
  20. rangeLength = nativeMax(argsLength - holdersLength, 0),
  21. result = Array(leftLength + rangeLength),
  22. isUncurried = !isCurried;
  23. while (++leftIndex < leftLength) {
  24. result[leftIndex] = partials[leftIndex];
  25. }
  26. while (++argsIndex < holdersLength) {
  27. if (isUncurried || argsIndex < argsLength) {
  28. result[holders[argsIndex]] = args[argsIndex];
  29. }
  30. }
  31. while (rangeLength--) {
  32. result[leftIndex++] = args[argsIndex++];
  33. }
  34. return result;
  35. }
  36. module.exports = composeArgs;