import { didYouMean } from './suggestions.ts'; export type ModeName = Modes[number]; /** Preserve a literal mode tuple while documenting that it is a shared registry. */ export function defineModes(modes: Modes): Modes { return modes; } /** Return typed keys for registries whose object keys are their accepted modes. */ export function modeKeys>>( registry: Registry, ): readonly Extract[] { return Object.keys(registry) as Extract[]; } /** Resolve a mode case-insensitively while retaining its literal union type. */ export function resolveMode( value: string, modes: Modes, ): ModeName | undefined { const normalized = value.toLowerCase(); return modes.find((mode): mode is ModeName => mode === normalized); } export function quotedModeChoices(modes: readonly string[]): string { return modes.map((mode) => `'${mode}'`).join(', '); } /** Standard unknown-mode diagnostic shared by construction and directive commands. */ export function unknownModeMessage( subject: string, value: string, modes: readonly string[], ): string { const normalized = value.toLowerCase(); return `Unknown ${subject} '${normalized}'${didYouMean(normalized, modes)} — expected ${quotedModeChoices(modes)}`; }