Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thlorenz/assert-cb

Assert that calls a function with an error instead of throwing it if the assert fails.
https://github.com/thlorenz/assert-cb

Last synced: 13 days ago
JSON representation

Assert that calls a function with an error instead of throwing it if the assert fails.

Awesome Lists containing this project

README

        

# assert-cb [![build status](https://secure.travis-ci.org/thlorenz/assert-cb.png)](http://travis-ci.org/thlorenz/assert-cb)

Assert that calls a function with an error instead of throwing it if the assert fails.

```js
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](https://github.com/thlorenz/docme)*

## License

MIT