Files
flights_web/src/shared/tbd.ts
T

27 lines
1.0 KiB
TypeScript

/**
* "Уточняется" fallback per TZ §4.1.23.
*
* When a field is null / undefined / empty string / whitespace, returns
* the localized "Уточняется" label. Otherwise returns the value as-is.
*
* NOTE: Only apply to fields TZ explicitly enumerates for this fallback
* (gate, terminal, aircraft type, bag belt, dispatch type, etc.). Don't
* use as a blanket fallback for all nullable fields — Angular reference
* uses dashes/absent rendering for fields not listed in §4.1.23.
*
* Styling: callers are responsible for applying the orange color class
* (`.tbd-text` or equivalent) when rendering the fallback string.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TFunction = (key: string, opts?: any) => string;
export function tbdOr<T>(
value: T | null | undefined,
t: TFunction,
): T | string {
if (value === null || value === undefined) return t("SHARED.TBD");
if (typeof value === "string" && value.trim() === "") return t("SHARED.TBD");
return value;
}