async-handlers
Advanced tools
Comparing version 1.2.1 to 1.3.0
// Generated by CoffeeScript 1.9.3 | ||
(function() { | ||
module.exports = { | ||
constant: require('./constant'), | ||
exitOnError: require('./exit_on_error'), | ||
@@ -5,0 +6,0 @@ extract: require('./extract'), |
{ | ||
"name": "async-handlers", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Function factories for performing synchronous operations after asynchronous operations", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
# Asynchronous handlers | ||
Function factories for performing synchronous operations after asynchronous operations | ||
Function factories for performing synchronous operations after asynchronous operations. | ||
#### transform(fn, callback) | ||
Returns a function `(err, result)` that can be passed to an asynchronous function | ||
that will pass the error through or pass `(null, fn(result))` | ||
```js | ||
@@ -32,5 +26,15 @@ f1 = function (callback) { | ||
## Methods | ||
#### constant(value, callback) | ||
Returns a function with the signature `(err)`. | ||
When called with an error, passes it to the callback. | ||
Otherwise executes callback with `(null, value)`. | ||
#### exitOnError | ||
A function that when called with an error, prints the error in red to `stderr` and exits with status 1. | ||
Returns a function with the signature `(err)`. | ||
When called with an error, prints the error in red to `stderr` and exits with status 1. | ||
Otherwise does nothing. | ||
@@ -41,3 +45,21 @@ | ||
Returns a function `(err, result)` that can be passed to an asynchronous function | ||
that will pass the error through or pass `(null, result[key])` | ||
Returns a function with the signature `(err, result)`. | ||
When called with an error, passes it to the callback. | ||
Otherwise executes callback with `(null, result[key])`. | ||
#### prependToError(prefix, callback) | ||
Returns a function with the signature `(err, args...)`. | ||
When error is a string, prepends prefix to it if and passes it to the callback. | ||
When error is an object with a message property, prepends prefix to its message and passes it to the callback. | ||
Otherwise passes all arguments to the callback. | ||
_Note: the prefix will only be prepended if not already present._ | ||
#### transform(fn, callback) | ||
Returns a function with the signature `(err, result)`. | ||
When called with an error, passes it to the callback. | ||
Otherwise executes callback with `(null, fn(result))`. |
5091
9
97
64