Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nary with all npm packages installed. Try it out:

var nary = require("nary")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nary v2.0.0

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free