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.

inspect.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { isSpace } from '../util.js';
  2. const zeroWidth = {
  3. line: 0,
  4. start: 0,
  5. delimiter: 0,
  6. postDelimiter: 0,
  7. tag: 0,
  8. postTag: 0,
  9. name: 0,
  10. postName: 0,
  11. type: 0,
  12. postType: 0,
  13. description: 0,
  14. end: 0,
  15. lineEnd: 0,
  16. };
  17. const headers = { lineEnd: 'CR' };
  18. const fields = Object.keys(zeroWidth);
  19. const repr = (x) => (isSpace(x) ? `{${x.length}}` : x);
  20. const frame = (line) => '|' + line.join('|') + '|';
  21. const align = (width, tokens) => Object.keys(tokens).map((k) => repr(tokens[k]).padEnd(width[k]));
  22. export default function inspect({ source }) {
  23. var _a, _b;
  24. if (source.length === 0)
  25. return '';
  26. const width = Object.assign({}, zeroWidth);
  27. for (const f of fields)
  28. width[f] = ((_a = headers[f]) !== null && _a !== void 0 ? _a : f).length;
  29. for (const { number, tokens } of source) {
  30. width.line = Math.max(width.line, number.toString().length);
  31. for (const k in tokens)
  32. width[k] = Math.max(width[k], repr(tokens[k]).length);
  33. }
  34. const lines = [[], []];
  35. for (const f of fields)
  36. lines[0].push(((_b = headers[f]) !== null && _b !== void 0 ? _b : f).padEnd(width[f]));
  37. for (const f of fields)
  38. lines[1].push('-'.padEnd(width[f], '-'));
  39. for (const { number, tokens } of source) {
  40. const line = number.toString().padStart(width.line);
  41. lines.push([line, ...align(width, tokens)]);
  42. }
  43. return lines.map(frame).join('\n');
  44. }