_updateWrapDetails.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var arrayEach = require('./_arrayEach'),
  2. arrayIncludes = require('./_arrayIncludes');
  3. /** Used to compose bitmasks for function metadata. */
  4. var WRAP_BIND_FLAG = 1,
  5. WRAP_BIND_KEY_FLAG = 2,
  6. WRAP_CURRY_FLAG = 8,
  7. WRAP_CURRY_RIGHT_FLAG = 16,
  8. WRAP_PARTIAL_FLAG = 32,
  9. WRAP_PARTIAL_RIGHT_FLAG = 64,
  10. WRAP_ARY_FLAG = 128,
  11. WRAP_REARG_FLAG = 256,
  12. WRAP_FLIP_FLAG = 512;
  13. /** Used to associate wrap methods with their bit flags. */
  14. var wrapFlags = [
  15. ['ary', WRAP_ARY_FLAG],
  16. ['bind', WRAP_BIND_FLAG],
  17. ['bindKey', WRAP_BIND_KEY_FLAG],
  18. ['curry', WRAP_CURRY_FLAG],
  19. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  20. ['flip', WRAP_FLIP_FLAG],
  21. ['partial', WRAP_PARTIAL_FLAG],
  22. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  23. ['rearg', WRAP_REARG_FLAG]
  24. ];
  25. /**
  26. * Updates wrapper `details` based on `bitmask` flags.
  27. *
  28. * @private
  29. * @returns {Array} details The details to modify.
  30. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  31. * @returns {Array} Returns `details`.
  32. */
  33. function updateWrapDetails(details, bitmask) {
  34. arrayEach(wrapFlags, function(pair) {
  35. var value = '_.' + pair[0];
  36. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  37. details.push(value);
  38. }
  39. });
  40. return details.sort();
  41. }
  42. module.exports = updateWrapDetails;