Force a functions arity in JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
package-lock.json
package.json
tsconfig.json
tslint.json

README.md

Nary

NPM version NPM downloads Build status Test coverage

Enforce function arity in JavaScript.

Installation

npm install nary --save

Usage

import { nary, nullary, unary, binary, ternary, quaternary } from 'nary'

nullary(fn).length; //=> 0
unary(fn).length; //=> 1
binary(fn).length; //=> 2
ternary(fn).length; //=> 3
quaternary(fn).length; //=> 4
nary(5, fn).length; //=> 5

// This example fails because `parseInt` accepts an optional second argument as
// the radix. This can wreak havoc in unexpected situations.
[1, 2, 3, 4, 5].map(parseInt); //=> [1, NaN, NaN, NaN, NaN]

// Using `unary`, the function will only accept a single argument.
[1, 2, 3, 4, 5].map(unary(parseInt)); //=> [1, 2, 3, 4, 5]

TypeScript

This project is written using TypeScript and publishes the definitions directly to NPM.

License

Apache 2.0