obligate
v0.1.1
Published
Forces your functions to meet their obligations.
Readme
Synopsis
obligate is a library for defining obligations for functions to adhere to.
Features
Transparent
If an obligation is met, it returns its input. If it is not, it throws an ObligationError. This allows you to just inject obligations into your control flow and mimic pre-conditions and post-conditions, e.g. using promises:
fetchSomeData()
.then(obligate(somePredicate, 'Predicate returned false!'))
.then(doMoreStuff, handleError);Extensible
obligate doesn't care where you get your predicates from. You can pass it any function that returns true or false when passed input by the obligation.
If you just want to get started, try pred for the most common checks.
Error handling
The ObligationError thrown by failed obligations is an actual error type, so stack traces and instanceof checks will behave as expected.
Install
With NPM
npm install obligateFrom source
git clone https://github.com/pluma/obligate.git
cd obligate
npm install
make testAPI
obligate(predicate:Function, message:String):Function
Creates an obligation function that returns its input if the given predicate returns true when passed the input or throws an ObligationError with the given message if the predicate returns false.
new ObligationError(message)
Creates a new ObligationError instance with the given message. The new keyword is optional. You probably don't want to use this constructor directly.
Unlicense
This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.




