mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
56
.internal/createRecurry.js
Normal file
56
.internal/createRecurry.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import isLaziable from './.internal/isLaziable.js';
|
||||
import setData from './.internal/setData.js';
|
||||
import setWrapToString from './.internal/setWrapToString.js';
|
||||
|
||||
/** Used to compose bitmasks for function metadata. */
|
||||
const WRAP_BIND_FLAG = 1;
|
||||
const WRAP_BIND_KEY_FLAG = 2;
|
||||
const WRAP_CURRY_BOUND_FLAG = 4;
|
||||
const WRAP_CURRY_FLAG = 8;
|
||||
const WRAP_PARTIAL_FLAG = 32;
|
||||
const WRAP_PARTIAL_RIGHT_FLAG = 64;
|
||||
|
||||
/**
|
||||
* Creates a function that wraps `func` to continue currying.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to wrap.
|
||||
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||||
* @param {Function} wrapFunc The function to create the `func` wrapper.
|
||||
* @param {*} placeholder The placeholder value.
|
||||
* @param {*} [thisArg] The `this` binding of `func`.
|
||||
* @param {Array} [partials] The arguments to prepend to those provided to
|
||||
* the new function.
|
||||
* @param {Array} [holders] The `partials` placeholder indexes.
|
||||
* @param {Array} [argPos] The argument positions of the new function.
|
||||
* @param {number} [ary] The arity cap of `func`.
|
||||
* @param {number} [arity] The arity of `func`.
|
||||
* @returns {Function} Returns the new wrapped function.
|
||||
*/
|
||||
function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
|
||||
const isCurry = bitmask & WRAP_CURRY_FLAG;
|
||||
const newHolders = isCurry ? holders : undefined;
|
||||
const newHoldersRight = isCurry ? undefined : holders;
|
||||
const newPartials = isCurry ? partials : undefined;
|
||||
const newPartialsRight = isCurry ? undefined : partials;
|
||||
|
||||
bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
|
||||
bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
|
||||
|
||||
if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
||||
bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
|
||||
}
|
||||
const newData = [
|
||||
func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
|
||||
newHoldersRight, argPos, ary, arity
|
||||
];
|
||||
|
||||
const result = wrapFunc(...newData);
|
||||
if (isLaziable(func)) {
|
||||
setData(result, newData);
|
||||
}
|
||||
result.placeholder = placeholder;
|
||||
return setWrapToString(result, func, bitmask);
|
||||
}
|
||||
|
||||
export default createRecurry;
|
||||
Reference in New Issue
Block a user