async-if-else
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "async-if-else", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "'conditional if to async control flow'", | ||
@@ -5,0 +5,0 @@ "repository": { |
101
README.md
@@ -36,2 +36,22 @@ # async-if-else | ||
function emailExists(user, callback) { | ||
user.find(user.email, function(err, dbUser){ | ||
if (err) | ||
return callback(error); | ||
if(!dbUser) | ||
return callback(null, false); // does not exist, predicate will be false | ||
callback(null, true); | ||
}); | ||
} | ||
function updateAccount(user, callback) { | ||
user.update( ..., callback); | ||
} | ||
function importFromLegacyByEmail(user, callback) { | ||
remoteClient.get(user, callback); | ||
} | ||
async.waterfall([ | ||
@@ -67,4 +87,85 @@ async.constant({email: 'thiago@email.com', dogs: 2, money: 0, fun: 100 }), | ||
], handler); | ||
``` | ||
## API | ||
* [`initializer`](#initializer) | ||
* [`if`](#if) | ||
* [`else`](#else) | ||
* [`ifNot`](#ifNot) | ||
* [`unless`](#unless) | ||
```javascript | ||
async.if() | ||
async.if().else() | ||
async.ifNot() | ||
async.ifNot().else() | ||
async.unless() | ||
async.unless().else() | ||
``` | ||
<a name="initializer" /> | ||
### initializer | ||
To get start with async-if-else you need to provide an object. | ||
```javascript | ||
var conditionals = require('async-if-else')({}); | ||
``` | ||
```javascript | ||
var async = require('async-if-else')(require('async')); | ||
``` | ||
<a name="if" /> | ||
### if | ||
**if** function receives the predicate and the expression. | ||
async.if(predicateFn, expressionFn) | ||
* predicateFn must validate the argument received from waterfall chain | ||
```javascript | ||
function predicateFn(arg1 [, arg2 ...], callback) {} | ||
``` | ||
callback signature is callback(error, truthyValue|falsyValue); | ||
if you pass an error on first parameter the async.waterfall will skip below steps and goes directly to async.waterfall's callback function. | ||
* expressionFn will execute when predicate is thruthy. | ||
```javascript | ||
function expressionFn(arg1 [,arg2...], asyncWaterfallCallback) | ||
``` | ||
<a name="else" /> | ||
### else | ||
**else** receives only an elseExpressionFn | ||
async.if(predicateFn, expressionFn).else(elseExpressionFn); | ||
* elseExpressionFn is executed when the if predicate is falsy or ifNot predicate is truthy. | ||
```javascript | ||
function elseExpressionFn(arg1 [,arg2...], asyncWaterfallCallback) | ||
``` | ||
<a name="ifNot" /> | ||
### ifNot | ||
**ifNot** works as the opposite of **If** | ||
receives exactly the same arguments | ||
async.ifNot(predicateFn, expressionFn) | ||
you could use with else as well | ||
async.ifNot(predicateFn, expressionFn).else(elseExpressionFn) | ||
<a name="unless" /> | ||
### unless | ||
just an alias to [`ifNot`](#ifNot). | ||
#### Hey, did you found an issue? | ||
@@ -71,0 +172,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15953
179