Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    narypublic

    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

    install

    npm i nary

    Downloadslast 7 days

    1

    version

    2.0.0

    license

    Apache-2.0

    repository

    github.com

    last publish

    collaborators

    • avatar