obligate is a library for defining obligations for functions to adhere to.
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:
obligate doesn't care where you get your predicates from. You can pass it any function that returns
false when passed input by the obligation.
If you just want to get started, try pred for the most common checks.
ObligationError thrown by failed obligations is an actual error type, so stack traces and
instanceof checks will behave as expected.
npm install obligate
git clone https://github.com/pluma/obligate.gitcd obligatenpm installmake test
obligation function that returns its input if the given
true when passed the input or throws an
ObligationError with the given
message if the predicate returns
Creates a new
ObligationError instance with the given
new keyword is optional. You probably don't want to use this constructor directly.