tools for dealing with functions in JavaScript
JavaScript
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

node-functions Build Status

Copyright (C) 2011 by Maciej Małecki
MIT License (see LICENSE file)

node-functions is a library for dealing with functions in JavaScript.

Usage

var assert = require('assert'),
    functions = require('functions');

// `functions.returns`
var get42 = functions.returns(42);
// get42 always returns `42`
assert.equal(get42(), 42);

// `functions.throws`
var throwMeAnError = functions.throws(new Error());
// throwMeAnError will always throw an Error when called
assert.throws(throwMeAnError, Error);

// `functions.throwsIfError`
var throwIfError = functions.throwsIfError();
// throwIfError will always throw first parameter it gets if it's truthy
assert.throws(function () { throwIfError(new Error()); });
assert.doesNotThrow(function () { throwsIfError(0); });

functions.noop(); // this call does nothing

Installation

npm install functions