Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Arity

NPM version NPM downloads Build status Test coverage

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.

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

About

Set the length of a function in JavaScript

Resources

License

Sponsor this project

 
Learn more about GitHub Sponsors
You can’t perform that action at this time.