1 | # iferr
|
2 |
|
3 | Higher-order functions for easier error handling.
|
4 |
|
5 | `if (err) return cb(err);` be gone!
|
6 |
|
7 | ## Install
|
8 | ```bash
|
9 | npm install iferr
|
10 | ```
|
11 |
|
12 | ## Use
|
13 |
|
14 | ### JavaScript/ES6 example
|
15 | ```js
|
16 | var iferr = require('iferr');
|
17 |
|
18 | function get_friends_count(id, cb) {
|
19 | User.load_user(id, iferr(cb, user =>
|
20 | user.load_friends(iferr(cb, friends =>
|
21 | cb(null, friends.length)
|
22 | ))
|
23 | ))
|
24 | }
|
25 | ```
|
26 |
|
27 | ### JavaScript/ES5 example
|
28 | ```js
|
29 | var iferr = require('iferr');
|
30 |
|
31 | function get_friends_count(id, cb) {
|
32 | User.load_user(id, iferr(cb, function(user) {
|
33 | user.load_friends(iferr(cb, function(friends) {
|
34 | cb(null, friends.length)
|
35 | }))
|
36 | }))
|
37 | }
|
38 | ```
|
39 |
|
40 | ### CoffeeScript example
|
41 | ```coffee
|
42 | iferr = require 'iferr'
|
43 |
|
44 | get_friends_count = (id, cb) ->
|
45 | User.load_user id, iferr cb, (user) ->
|
46 | user.load_friends iferr cb, (friends) ->
|
47 | cb null, friends.length
|
48 | ```
|
49 |
|
50 | (TODO: document tiferr, throwerr and printerr)
|
51 |
|
52 | ## License
|
53 | MIT
|