nary
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

Package Sidebar

Install

npm i nary

Weekly Downloads

1

Version

2.0.0

License

Apache-2.0

Last publish

Collaborators

  • blakeembrey