Arity
!NPM versionnpm-imagenpm-url
!NPM downloadsdownloads-imagedownloads-url
!Build statustravis-imagetravis-url
!Test coveragecoveralls-imagecoveralls-urlSet a functions arity (the argument count) by proxying function calls.
P.S. If you need need to enforce arity and don't care about argument length or
this
, use nary
. It's magnitudes faster than using .apply
to proxy arguments.When would I use this?
It's unlikely you'll need to use this utility in everyday development. The reason I wrote it was for functional utilities and backward compatibility with user expectations. For example, many modules use function arity to decide how the function behaves (e.g. error middleware inexpress
, callbacks in mocha
).Installation
npm install util-arity --save
Usage
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