MCPcopy Create free account
hub / github.com/microsoft/data-formulator / normalizeOption

Function normalizeOption

src/app/clarification.ts:18–30  ·  view source on GitHub ↗

Resolve an option's user-visible label. * Accepts a bare string or a `{label, label_code?}` dict; returns null * if no usable label can be produced. The `label_code` is a backend i18n * key consumed by `translateBackend`; we don't keep it on the normalized * output because nothing downstream

(raw: any)

Source from the content-addressed store, hash-verified

16 * key consumed by `translateBackend`; we don't keep it on the normalized
17 * output because nothing downstream reads it. */
18function normalizeOption(raw: any): ClarificationOption | null {
19 if (typeof raw === 'string') {
20 const label = raw.trim();
21 return label ? { label } : null;
22 }
23 if (!raw || typeof raw !== 'object') return null;
24
25 const label = translateBackend(
26 String(raw.label || ''),
27 typeof raw.label_code === 'string' ? raw.label_code : undefined,
28 ).trim();
29 return label ? { label } : null;
30}
31
32/** Resolve a question's translated text + its options. The `*_code` /
33 * `text_params` keys are i18n inputs only — they're not preserved on the

Callers 1

normalizeQuestionFunction · 0.85

Calls 1

translateBackendFunction · 0.90

Tested by

no test coverage detected