// Pure helpers for the in-game "check a word" panel: input sanitising and the gate on // when a check may be sent. Kept separate from Game.svelte so the constraints (the // variant alphabet, the length bounds, the answered-word cache and the cool-down // throttle) are unit-testable and stay in lockstep with the UI. /** The longest word that fits on a standard 15-cell board line. */ export const MAX_WORD_LEN = 15; /** The shortest word worth checking. */ export const MIN_WORD_LEN = 2; /** * sanitizeCheckWord upper-cases the raw input and keeps only characters of the active * variant's alphabet, capped at MAX_WORD_LEN — so the field can never hold something the * dictionary could not contain. */ export function sanitizeCheckWord(raw: string, alphabet: string[]): string { const allowed = new Set(alphabet); return Array.from(raw.toUpperCase()) .filter((ch) => allowed.has(ch)) .slice(0, MAX_WORD_LEN) .join(''); } /** * canCheckWord gates the Check action: the trimmed word must be of valid length, must not * have been answered already (cached), and must not fall inside the cool-down window. */ export function canCheckWord(word: string, alreadyChecked: boolean, cooling: boolean): boolean { const w = word.trim(); return w.length >= MIN_WORD_LEN && w.length <= MAX_WORD_LEN && !alreadyChecked && !cooling; }