garde

    0.1.0 • Public • Published

    garde

    npm version Travis CI Badge (master branch)

    Utility function for dealing with function arguments.

    How to include

    Node.js / Browserify

    In your shell:

    $ npm install --save garde
    

    In your javascript:

    var garde = require('garde')

    Browser ("classic" way)

    Just add a script tag with either garde.js or garde.min.js from this repos root directory. This makes the Cheiron variable globally available.

    typeof window.garde
    // --> 'function'

    Warning

    This module globally extends the prototype of Function with a method invoke which uses the evil eval! But I sorrily JS did not give me another way to call a function with an array of arguments without changing it's context.

    API

    garde(<f>)

    Returns a wrapper function for f which throws an Exception when the number of arguments passed does not equal f's arity.

    var add = function (a, b) {
      return a + b
    }
     
    console.log(add(1, 2))
    // --> 3
     
    console.log(add(1))
    // --> NaN
     
    var gAdd = garde(add)
     
    console.log(gAdd(1, 2))
    // --> 3
     
    console.log(gAdd(1))
    // Error: Function needs 2 arguments, got 1

    garde(<arity>, <f>)

    Instead of checking f's arity, arity is used for comparison.

    Testing/Building

    Installing development dependencies

    $ npm install
    

    Running tests

    $ npm test
    

    Building for the browser

    $ npm run build
    $ # for building on file change
    $ npm run watch
    

    License

    MIT license, see LICENSE.

    Install

    npm i garde

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • reg4in