summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/node_modules/iferr/README.md
blob: 7a24462a88edc2e995838415b3fded722d4420cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# iferr

Higher-order functions for easier error handling.

`if (err) return cb(err);` be gone!

## Install
```bash
npm install iferr
```

## Use

### JavaScript/ES6 example
```js
var iferr = require('iferr');

function get_friends_count(id, cb) {
  User.load_user(id, iferr(cb, user =>
    user.load_friends(iferr(cb, friends =>
      cb(null, friends.length)
    ))
  ))
}
```

### JavaScript/ES5 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, throwerr and printerr)

## License
MIT