import fs from 'node:fs'; export interface Brand { id: string; title: string; category: string; aliases: string[]; } /** Archify's built-in brand marks, read from brand-marks/catalog.json. */ export function loadBrandCatalog(file: string): Brand[] { const catalog = JSON.parse(fs.readFileSync(file, 'utf8')) as { marks?: Partial[] }; return (catalog.marks ?? []) .filter((mark): mark is Partial & { id: string } => typeof mark.id === 'string') .map((mark) => ({ id: mark.id, title: mark.title ?? mark.id, category: mark.category ?? '', aliases: mark.aliases ?? [] })); } export interface BrandValue { /** What has been typed of the value so far. */ typed: string; } /** * Whether the text before the cursor ends inside a `brand` value: * `brand: post` or `{ id: db, brand: "post` in YAML, `"brand": "post` in JSON. */ export function brandValueAt(linePrefix: string, format: 'yaml' | 'json'): BrandValue | undefined { const match = format === 'yaml' ? /(?:^|[\s{,])brand:\s*["']?([\w.-]*)$/.exec(linePrefix) : /"brand"\s*:\s*"([\w.-]*)$/.exec(linePrefix); return match ? { typed: match[1] } : undefined; }