Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/thlorenz/assert-cb
- Owner: thlorenz
- License: mit
- Created: 2014-11-04T08:41:56.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-04T09:33:30.000Z (about 10 years ago)
- Last Synced: 2024-12-10T08:26:54.293Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 137 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
Returns:
the given condition
Type
boolean*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT