You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
675 B

4 years ago
  1. # iferr
  2. Higher-order functions for easier error handling.
  3. `if (err) return cb(err);` be gone!
  4. ## Install
  5. ```bash
  6. npm install iferr
  7. ```
  8. ## Use
  9. ### JavaScript example
  10. ```js
  11. var iferr = require('iferr');
  12. function get_friends_count(id, cb) {
  13. User.load_user(id, iferr(cb, function(user) {
  14. user.load_friends(iferr(cb, function(friends) {
  15. cb(null, friends.length);
  16. }));
  17. }));
  18. }
  19. ```
  20. ### CoffeeScript example
  21. ```coffee
  22. iferr = require 'iferr'
  23. get_friends_count = (id, cb) ->
  24. User.load_user id, iferr cb, (user) ->
  25. user.load_friends iferr cb, (friends) ->
  26. cb null, friends.length
  27. ```
  28. (TODO: document tiferr, throwerr and printerr)
  29. ## License
  30. MIT