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.

align.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { Markers } from '../primitives.js';
  13. import { rewireSource } from '../util.js';
  14. const zeroWidth = {
  15. start: 0,
  16. tag: 0,
  17. type: 0,
  18. name: 0,
  19. };
  20. const getWidth = (w, { tokens: t }) => ({
  21. start: t.delimiter === Markers.start ? t.start.length : w.start,
  22. tag: Math.max(w.tag, t.tag.length),
  23. type: Math.max(w.type, t.type.length),
  24. name: Math.max(w.name, t.name.length),
  25. });
  26. const space = (len) => ''.padStart(len, ' ');
  27. export default function align() {
  28. let intoTags = false;
  29. let w;
  30. function update(line) {
  31. const tokens = Object.assign({}, line.tokens);
  32. if (tokens.tag !== '')
  33. intoTags = true;
  34. const isEmpty = tokens.tag === '' &&
  35. tokens.name === '' &&
  36. tokens.type === '' &&
  37. tokens.description === '';
  38. // dangling '*/'
  39. if (tokens.end === Markers.end && isEmpty) {
  40. tokens.start = space(w.start + 1);
  41. return Object.assign(Object.assign({}, line), { tokens });
  42. }
  43. switch (tokens.delimiter) {
  44. case Markers.start:
  45. tokens.start = space(w.start);
  46. break;
  47. case Markers.delim:
  48. tokens.start = space(w.start + 1);
  49. break;
  50. default:
  51. tokens.delimiter = '';
  52. tokens.start = space(w.start + 2); // compensate delimiter
  53. }
  54. if (!intoTags) {
  55. tokens.postDelimiter = tokens.description === '' ? '' : ' ';
  56. return Object.assign(Object.assign({}, line), { tokens });
  57. }
  58. const nothingAfter = {
  59. delim: false,
  60. tag: false,
  61. type: false,
  62. name: false,
  63. };
  64. if (tokens.description === '') {
  65. nothingAfter.name = true;
  66. tokens.postName = '';
  67. if (tokens.name === '') {
  68. nothingAfter.type = true;
  69. tokens.postType = '';
  70. if (tokens.type === '') {
  71. nothingAfter.tag = true;
  72. tokens.postTag = '';
  73. if (tokens.tag === '') {
  74. nothingAfter.delim = true;
  75. }
  76. }
  77. }
  78. }
  79. tokens.postDelimiter = nothingAfter.delim ? '' : ' ';
  80. if (!nothingAfter.tag)
  81. tokens.postTag = space(w.tag - tokens.tag.length + 1);
  82. if (!nothingAfter.type)
  83. tokens.postType = space(w.type - tokens.type.length + 1);
  84. if (!nothingAfter.name)
  85. tokens.postName = space(w.name - tokens.name.length + 1);
  86. return Object.assign(Object.assign({}, line), { tokens });
  87. }
  88. return (_a) => {
  89. var { source } = _a, fields = __rest(_a, ["source"]);
  90. w = source.reduce(getWidth, Object.assign({}, zeroWidth));
  91. return rewireSource(Object.assign(Object.assign({}, fields), { source: source.map(update) }));
  92. };
  93. }