UNPKG

@botonic/react

Version:

Build Chatbots using React

27 lines (26 loc) 1.21 kB
/** * Normalizes a locale string to a valid format. * Keeps letter-based region codes (e.g., 'en-GB', 'es-ES') but strips * numeric UN M.49 region codes (e.g., 'es-419' -> 'es'). * Handles both dash and underscore separators. * @example * normalizeLocale('en-GB') // 'en-GB' (letter region preserved) * normalizeLocale('es-419') // 'es' (numeric region stripped) * normalizeLocale('zh-Hans-CN') // 'zh-CN' (script stripped, letter region preserved) * normalizeLocale('en_US') // 'en-US' (underscore normalized) */ export declare function normalizeLocale(locale?: string): string; /** * Gets the country code from a time zone string. * @param timeZone - IANA time zone string (e.g., 'Europe/Madrid') * @returns ISO 3166-1 alpha-2 country code (e.g., 'ES') or undefined if not found * @example * getCountryFromTimeZone('Europe/Madrid') // 'ES' * getCountryFromTimeZone('America/New_York') // 'US' */ export declare function getCountryFromTimeZone(timeZone?: string): string | undefined; /** * Mapping of IANA time zones to ISO 3166-1 alpha-2 country codes. * Used to infer a user's country from their browser's time zone. */ export declare const timeZoneToCountryCode: Record<string, string>;