arity-of

1.0.2 • Public • Published

arity-of

Build Status Dependencies Status npm Coverage Status Install Size Known Vulnerabilities

An NPM library that exposes max arity and other metadata for JS functions

This package implements the es-shim API interface. It works in an ES6-supported environment and complies with the spec (TODO this is a lie. Write a proposal).

Concepts

"Arity" refers to the number of parameters a function declares.

function (a, b, c) {} declares 3 parameters so has a minimum and maximum arity of 3.

function (a, b = 0, ...rest) {} declares 3 parameters. It has a minimum arity of 1 since there is no default value for a. It has a maximum arity of 3 since that is the number declared. It uses a rest parameter ...rest so it can actually take additional parameters.

Installation

npm install arity-of

Usage

const arityOf = require('arity-of');
 
function myFunction(a, b = 0, [c, d], ...e) {
  // ...
}
 
myFunction.length;   // Minimum arity
 
const {
  max,               // Maximum arity (including any ...restParamater) 
  usesRest,          // True if there is a ...restParameter.
= arityOf(myFunction);

Readme

Keywords

Package Sidebar

Install

npm i arity-of

Weekly Downloads

2

Version

1.0.2

License

Apache-2.0

Unpacked Size

24.8 kB

Total Files

6

Last publish

Collaborators

  • mikesamuel