Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.md « iferr « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0940763fa94137aa2e3ba04ce30813984bda89df (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
# iferr

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, throwerr and printerr)

## License
MIT