UNPKG

mocoolka-function

Version:

Function lib for function.

30 lines 1.29 kB
Object.defineProperty(exports, "__esModule", { value: true }); var create_1 = require("../create"); var getName_1 = require("../getName"); /** * Returns a new function which is equivalent to the given function, * except that the new function's length property is equal to given length. * This does not limit the function to using that number of arguments. * It's only effect is on the reported length. * @since v0.1.0 * @keywords wrap * @param {number} length -The function parameter's number * @param {Function} fn - The function be wrap * @param {boolean} isNew - True register new Function * @return {Function} New function */ var arity = function (length, fn, isNew) { if (isNew === void 0) { isNew = false; } /* istanbul ignore next */ length = length < 0 ? 0 : length; var parameters = new Array(length); for (var i = 0; i < length; ++i) { parameters[i] = 'a' + i; } var params = parameters.join(); var code = isNew ? "return function (" + params + ") { return new fn( " + params + "); };" : "return function (" + params + ") { return fn.apply(this, arguments); };"; return create_1.default(getName_1.default(fn), ['fn'], code)(fn); }; exports.default = arity; //# sourceMappingURL=arity.js.map