0.1.1 • Published 5 years ago

@kredati/ludus-assert v0.1.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
5 years ago

ludus-prelude: assert

A basic functional assertion framework

Install

npm i @kredati/ludus-assert 

API

assert

assert :: [predicate: nullary, message: string] -> (ok | failure) assert returns either a failure or an ok with the message attached. It returns a failure with if the predicate thunk/nullary function returns a falsy value or a failure, or if it throws an error. It returns an ok otherwise (no errors, truthy value).

conform

conform :: [predicate: unary, value: any, message: string] -> (value | failure) conform passes the value to the unary predicate. Returns the value for a truthy result, and returns a failure bearing the message with a falsy one, a failure, or a thrown error.

ok

ok :: [message: string] -> ok ok returns an ok result with the message attached. The ok result is largely an internal affair of assert.

is_ok

is_ok :: [value: any] -> bool is_ok does what it says on the tin: returns true if the value is an ok; returns false otherwise.

AssertionError

AssertionError :: [message: string] -> AssertionError Returns an AssertionError with the message attached.