Set the length of a function in JavaScript
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md Update README copy May 10, 2017
arity.d.ts
arity.js
package.json chore(package): update mocha to version 3.5.0 (#7) Aug 2, 2017
test.js

README.md

Arity

NPM version NPM downloads Build status Test coverage Greenkeeper badge

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 over .apply to proxy arguments.

Why would I use this?

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).

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

TypeScript

The typings for this project are available for node module resolution with TypeScript.

License

MIT