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.

convert.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict'
  2. module.exports = convert
  3. function convert(test) {
  4. if (test == null) {
  5. return ok
  6. }
  7. if (typeof test === 'string') {
  8. return typeFactory(test)
  9. }
  10. if (typeof test === 'object') {
  11. return 'length' in test ? anyFactory(test) : allFactory(test)
  12. }
  13. if (typeof test === 'function') {
  14. return test
  15. }
  16. throw new Error('Expected function, string, or object as test')
  17. }
  18. // Utility assert each property in `test` is represented in `node`, and each
  19. // values are strictly equal.
  20. function allFactory(test) {
  21. return all
  22. function all(node) {
  23. var key
  24. for (key in test) {
  25. if (node[key] !== test[key]) return false
  26. }
  27. return true
  28. }
  29. }
  30. function anyFactory(tests) {
  31. var checks = []
  32. var index = -1
  33. while (++index < tests.length) {
  34. checks[index] = convert(tests[index])
  35. }
  36. return any
  37. function any() {
  38. var index = -1
  39. while (++index < checks.length) {
  40. if (checks[index].apply(this, arguments)) {
  41. return true
  42. }
  43. }
  44. return false
  45. }
  46. }
  47. // Utility to convert a string into a function which checks a given node’s type
  48. // for said string.
  49. function typeFactory(test) {
  50. return type
  51. function type(node) {
  52. return Boolean(node && node.type === test)
  53. }
  54. }
  55. // Utility to return true.
  56. function ok() {
  57. return true
  58. }