UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

46 lines (45 loc) 2.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const CONSTANTS_1 = require("./CONSTANTS"); const setData_1 = __importDefault(require("./setData")); const setWrapToString_1 = __importDefault(require("./setWrapToString")); const isLaziable_1 = __importDefault(require("./isLaziable")); /** * 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) { var isCurry = bitmask & CONSTANTS_1.WRAP_CURRY_FLAG, newHolders = isCurry ? holders : undefined, newHoldersRight = isCurry ? undefined : holders, newPartials = isCurry ? partials : undefined, newPartialsRight = isCurry ? undefined : partials; bitmask |= (isCurry ? CONSTANTS_1.WRAP_PARTIAL_FLAG : CONSTANTS_1.WRAP_PARTIAL_RIGHT_FLAG); bitmask &= ~(isCurry ? CONSTANTS_1.WRAP_PARTIAL_RIGHT_FLAG : CONSTANTS_1.WRAP_PARTIAL_FLAG); if (!(bitmask & CONSTANTS_1.WRAP_CURRY_BOUND_FLAG)) { bitmask &= ~(CONSTANTS_1.WRAP_BIND_FLAG | CONSTANTS_1.WRAP_BIND_KEY_FLAG); } var newData = [ func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, newHoldersRight, argPos, ary, arity ]; var result = wrapFunc.apply(undefined, newData); if ((0, isLaziable_1.default)(func)) { (0, setData_1.default)(result, newData); } result.placeholder = placeholder; return (0, setWrapToString_1.default)(result, func, bitmask); } exports.default = createRecurry;