0.1.0 • Published 11 years ago
garde v0.1.0
garde
Utility function for dealing with function arguments.
How to include
Node.js / Browserify
In your shell:
$ npm install --save gardeIn 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 1garde(<arity>, <f>)
Instead of checking f's arity, arity is used for comparison.
Testing/Building
Installing development dependencies
$ npm installRunning tests
$ npm testBuilding for the browser
$ npm run build
$ # for building on file change
$ npm run watchLicense
MIT license, see LICENSE.
0.1.0
11 years ago