Comparing version 0.1.1 to 0.1.2
@@ -7,2 +7,5 @@ // Generated by CoffeeScript 1.7.1 | ||
iferr = function(fail, succ) { | ||
if (succ == null) { | ||
succ = noop; | ||
} | ||
return function() { | ||
@@ -37,3 +40,3 @@ var a, err; | ||
throwerr = function(succ) { | ||
return iferr(throwr, succ || noop); | ||
return iferr(throwr, succ); | ||
}; | ||
@@ -40,0 +43,0 @@ |
{ | ||
"name": "iferr", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Higher-order functions for easier error handling", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,4 +0,40 @@ | ||
iferr | ||
===== | ||
# iferr | ||
Higher-order functions for easier error handling | ||
Higher-order functions for easier error handling. | ||
`if (err) return cb(err);` be gone! | ||
## Install | ||
```bash | ||
npm install iferr | ||
``` | ||
## Use | ||
### JavaScript example | ||
```js | ||
var iferr = require('iferr'); | ||
function get_friends_count(id, cb) { | ||
User.load_user(id, iferr(cb, function(user) { | ||
user.load_friends(iferr(cb, function(friends) { | ||
cb(null, friends.length); | ||
})); | ||
})); | ||
} | ||
``` | ||
### CoffeeScript example | ||
```coffee | ||
iferr = require 'iferr' | ||
get_friends_count = (id, cb) -> | ||
User.load_user id, iferr cb, (user) -> | ||
user.load_friends iferr cb, (friends) -> | ||
cb null, friends.length | ||
``` | ||
(TODO: document tiferr and throwerr) | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
5126
42
41