Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

index.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict'
  2. var wrap = require('./wrap.js')
  3. module.exports = trough
  4. trough.wrap = wrap
  5. var slice = [].slice
  6. // Create new middleware.
  7. function trough() {
  8. var fns = []
  9. var middleware = {}
  10. middleware.run = run
  11. middleware.use = use
  12. return middleware
  13. // Run `fns`. Last argument must be a completion handler.
  14. function run() {
  15. var index = -1
  16. var input = slice.call(arguments, 0, -1)
  17. var done = arguments[arguments.length - 1]
  18. if (typeof done !== 'function') {
  19. throw new Error('Expected function as last argument, not ' + done)
  20. }
  21. next.apply(null, [null].concat(input))
  22. // Run the next `fn`, if any.
  23. function next(err) {
  24. var fn = fns[++index]
  25. var params = slice.call(arguments, 0)
  26. var values = params.slice(1)
  27. var length = input.length
  28. var pos = -1
  29. if (err) {
  30. done(err)
  31. return
  32. }
  33. // Copy non-nully input into values.
  34. while (++pos < length) {
  35. if (values[pos] === null || values[pos] === undefined) {
  36. values[pos] = input[pos]
  37. }
  38. }
  39. input = values
  40. // Next or done.
  41. if (fn) {
  42. wrap(fn, next).apply(null, input)
  43. } else {
  44. done.apply(null, [null].concat(input))
  45. }
  46. }
  47. }
  48. // Add `fn` to the list.
  49. function use(fn) {
  50. if (typeof fn !== 'function') {
  51. throw new Error('Expected `fn` to be a function, not ' + fn)
  52. }
  53. fns.push(fn)
  54. return middleware
  55. }
  56. }