lwe-fonts.ts 703 B

123456789101112131415161718192021
  1. import type { LweFontNeed } from '@shared/types'
  2. // ` font family="Arial" status=compatible using="Liberation Sans" objects="Clock, Date"`
  3. const FONT_LINE_RE = /^\s*(font|emoji)\sfamily="(.*)"\sstatus=(installed|compatible|missing)\susing="(.*)"\sobjects="(.*)"\s*$/
  4. export function parseLweFontList(output: string): LweFontNeed[] {
  5. const needs: LweFontNeed[] = []
  6. for (const line of output.split('\n')) {
  7. const m = line.match(FONT_LINE_RE)
  8. if (m) {
  9. needs.push({
  10. kind: m[1] as LweFontNeed['kind'],
  11. family: m[2],
  12. status: m[3] as LweFontNeed['status'],
  13. using: m[4],
  14. objects: m[5].split(', ').filter(Boolean)
  15. })
  16. }
  17. }
  18. return needs
  19. }