node package manager

nary

Enforce function arity in JavaScript

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