开发者社区> 镜像站> NPM> assert-cb
assert-cb
Assert that calls a function with an error instead of throwing it if the assert fails.
Last updated 6 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install assert-cb 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.1.0                                ...           latest (6 years ago)

1 Versions

  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)