UNPKG

448 Btext/coffeescriptView Raw
1isFunction = (obj) -> '[object Function]' is toString.call obj
2
3nop = (req, res, next) -> next()
4module.exports = (test, left, right = nop) ->
5 throw new Error 'test is not a function' unless isFunction test
6 throw new Error 'first middleware is not a function' unless isFunction left
7 throw new Error 'second middleware is not a function' unless isFunction right
8 (req, res, next) -> (if test req then left else right) req, res, next
9