assert-cb

0.1.0 • Public • Published

assert-cb build status

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

assert-cb(condition, msg, cb) → {boolean}

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

Source:
Returns:

the given condition

Type
boolean

generated with docme

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i assert-cb

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • thlorenz