assert-cb
Assert that calls a function with an error instead of throwing it if the assert fails.
var assert = require('assert-cb')
function doStuff(opts, cb) {
if (!assert(opts.day, 'need to provide day', cb)) return;
if (!assert(opts.hour, 'need to provide hour', cb)) return;
// determine result
[..]
cb(null, res);
}
Installation
npm install assert-cb
-
(condition, msg, cb) → {boolean}
assert-cb -
Assert that calls the callback if the given condition is false. Passes the given condition through to the caller to allow branching depending on its value.
Parameters:
Name Type Description condition
boolean if false callback is invoked with an error
msg
string the error message
cb
function invoked only if the condition is false
Returns:
the given condition
- Type
- boolean
generated with docme
License
MIT