/** * Normalize an arbitrary user / LLM string into a stable SCREAMING_SNAKE * identifier, optionally resolving against a known-values map. * * The pipeline: strip diacritics → uppercase → collapse spaces and dashes * to `_` → drop everything outside `[A-Z_]` → squash runs of `_` → trim * leading/trailing `_`. * * normalizeIdentifier('Ajuste de Refeição') // 'AJUSTE_DE_REFEICAO' * normalizeIdentifier('código-de-barras') // 'CODIGO_DE_BARRAS' * normalizeIdentifier(' AJUSTE_DE_REFEICAO ') // 'AJUSTE_DE_REFEICAO' * * With a `map`, resolves the normalized form to an enum value (or null): * * const map = { AJUSTE_DE_REFEICAO: 'meal_adjust', OUTRO: 'other' }; * normalizeIdentifier('Ajuste de Refeição', { map }) // 'meal_adjust' * normalizeIdentifier('???', { map }) // null * * Use `fallback` to return a default instead of null on miss: * * normalizeIdentifier('???', { map, fallback: 'other' }) // 'other' * * Why this exists: aysu had two near-identical copies of this pipeline — * one for image-category routing (`util/category.ts:39`) and one for * text-classification (`ai/classifier.ts:37`). Writing it twice in one * project is the signal it should be framework material. */ export interface NormalizeIdentifierOptions { /** Known-values map applied after normalization. */ map?: Record; /** Value returned when `map` is set and the normalized form is not in it. */ fallback?: T; } /** * Normalize without a map: returns the SCREAMING_SNAKE form, or `''` when * the input collapses to empty (`null`, `undefined`, pure punctuation, * etc.). */ export declare function normalizeIdentifier(raw: string | null | undefined): string; /** * Normalize and resolve against a `map`, with a `fallback` that's always * returned on miss. Return type is `T` (never null) because `fallback` is * non-nullable here. */ export declare function normalizeIdentifier(raw: string | null | undefined, options: { map: Record; fallback: T; }): T; /** * Normalize and resolve against a `map` with no fallback. Returns the * mapped value or `null` on miss. */ export declare function normalizeIdentifier(raw: string | null | undefined, options: { map: Record; fallback?: undefined; }): T | null; //# sourceMappingURL=normalize_identifier.d.ts.map