┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ // Headline figures as 3?5 block digits - every cell a real glyph. │
│ import { checkGrid, len } from "../../lib/ascii"; │
│ │
│ export interface Props { │
│ value: string | number; │
│ /** Caption under the digits. */ │
│ label?: string; │
│ } │
│ │
│ // prettier-ignore │
│ const DIGITS: Record<string, string[]> = { │
│ "0": ["███", "█ █", "█ █", "█ █", "███"], │
│ "1": [" █", " █", " █", " █", " █"], │
│ "2": ["███", " █", "███", "█ ", "███"], │
│ "3": ["███", " █", "███", " █", "███"], │
│ "4": ["█ █", "█ █", "███", " █", " █"], │
│ "5": ["███", "█ ", "███", " █", "███"], │
│ "6": ["███", "█ ", "███", "█ █", "███"], │
│ "7": ["███", " █", " █", " █", " █"], │
│ "8": ["███", "█ █", "███", "█ █", "███"], │
│ "9": ["███", "█ █", "███", " █", "███"], │
│ ".": [" ", " ", " ", " ", "█"], │
│ ",": [" ", " ", " ", "█", "█"], │
│ "-": [" ", " ", "███", " ", " "], │
│ " ": [" ", " ", " ", " ", " "], │
│ }; │
│ │
│ export const BIG_ROWS = 5; │
│ │
│ export function buildBigNumber(value: string | number, width: number): string { │
│ const chars = [...String(value)]; │
│ const rows = Array.from({ length: BIG_ROWS }, () => ""); │
│ for (const [i, c] of chars.entries()) { │
│ const glyph = DIGITS[c]; │
│ if (!glyph) throw new Error(`[ascii] big number has no glyph for "${c}"`); │
│ for (let r = 0; r < BIG_ROWS; r++) { │
│ rows[r] += (i > 0 ? " " : "") + glyph[r]; │
│ } │
│ } │
│ return rows.map((r) => checkGrid(r.trimEnd(), width, "big number")).join("\n"); │
│ } │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ // Headline figures as 3?5 block digits - ev │
│ ery cell a real glyph. │
│ import { checkGrid, len } from "../../lib/as │
│ cii"; │
│ │
│ export interface Props { │
│ value: string | number; │
│ /** Caption under the digits. */ │
│ label?: string; │
│ } │
│ │
│ // prettier-ignore │
│ const DIGITS: Record<string, string[]> = { │
│ "0": ["███", "█ █", "█ █", "█ █", "███"], │
│ "1": [" █", " █", " █", " █", " █"], │
│ "2": ["███", " █", "███", "█ ", "███"], │
│ "3": ["███", " █", "███", " █", "███"], │
│ "4": ["█ █", "█ █", "███", " █", " █"], │
│ "5": ["███", "█ ", "███", " █", "███"], │
│ "6": ["███", "█ ", "███", "█ █", "███"], │
│ "7": ["███", " █", " █", " █", " █"], │
│ "8": ["███", "█ █", "███", "█ █", "███"], │
│ "9": ["███", "█ █", "███", " █", "███"], │
│ ".": [" ", " ", " ", " ", "█"], │
│ ",": [" ", " ", " ", "█", "█"], │
│ "-": [" ", " ", "███", " ", " "], │
│ " ": [" ", " ", " ", " ", " "], │
│ }; │
│ │
│ export const BIG_ROWS = 5; │
│ │
│ export function buildBigNumber(value: string │
│ | number, width: number): string { │
│ const chars = [...String(value)]; │
│ const rows = Array.from({ length: BIG_ROWS │
│ }, () => ""); │
│ for (const [i, c] of chars.entries()) { │
│ const glyph = DIGITS[c]; │
│ if (!glyph) throw new Error(`[ascii] big │
│ number has no glyph for "${c}"`); │
│ for (let r = 0; r < BIG_ROWS; r++) { │
│ rows[r] += (i > 0 ? " " : "") + glyph[ │
│ r]; │
│ } │
│ } │
│ return rows.map((r) => checkGrid(r.trimEnd │
│ (), width, "big number")).join("\n"); │
│ } │
└──────────────────────────────────────────────┘