UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

34 lines (33 loc) 884 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.nthArg = void 0; // @ts-nocheck const nth_1 = __importDefault(require("./nth")); /** * Creates a function that gets the argument at index `n`. If `n` is negative, * the nth argument from the end is returned. * * @since 5.10.0 * @category Util * @param n The index of the argument to return. * @returns {Function} Returns the new pass-thru function. * @example * * ```js * const func = nthArg(1) * func('a', 'b', 'c', 'd') * // => 'b' * * const func = nthArg(-2) * func('a', 'b', 'c', 'd') * // => 'c' * ``` */ function nthArg(n = 0) { return (...args) => (0, nth_1.default)(args, n); } exports.nthArg = nthArg; exports.default = nthArg;