Set a functions arity (the argument count) by proxying function calls.
P.S. If you don't care about this
and want to receive the exact arity of function arguments, use nary
. It uses function invocation (faster!) over .apply
to proxy arguments.
You probably won't. The reason it needs to exist is for functional utilities and backward compatibility with user expectations. Many modules use function arity to decide how the function should behave (e.g. middleware in express
or callbacks in mocha
).
npm install util-arity --save
var fn = function () {};
var arity = require('util-arity');
var oneArg = arity(1, fn);
var twoArgs = arity(2, fn);
var threeArgs = arity(3, fn);
oneArgs.length; //=> 1
twoArgs.length; //=> 2
threeArgs.length; //=> 3
The typings for this project are available for node module resolution with TypeScript.
MIT