3 var wrap = require('./wrap.js')
5 module.exports = trough
11 // Create new middleware.
21 // Run `fns`. Last argument must be a completion handler.
24 var input = slice.call(arguments, 0, -1)
25 var done = arguments[arguments.length - 1]
27 if (typeof done !== 'function') {
28 throw new Error('Expected function as last argument, not ' + done)
31 next.apply(null, [null].concat(input))
33 // Run the next `fn`, if any.
36 var params = slice.call(arguments, 0)
37 var values = params.slice(1)
38 var length = input.length
46 // Copy non-nully input into values.
47 while (++pos < length) {
48 if (values[pos] === null || values[pos] === undefined) {
49 values[pos] = input[pos]
57 wrap(fn, next).apply(null, input)
59 done.apply(null, [null].concat(input))
64 // Add `fn` to the list.
66 if (typeof fn !== 'function') {
67 throw new Error('Expected `fn` to be a function, not ' + fn)