@jsverse/transloco-locale
Version:
The localization (l10n) library plugin for Transloco
44 lines (43 loc) • 1.68 kB
TypeScript
import { DateFormatOptions, Locale } from './transloco-locale.types';
export declare const ISO8601_DATE_REGEX: RegExp;
/**
* Checks if a given value is a valid BCP 47 language tag.
*
* Validation is delegated to `Intl.getCanonicalLocales`, which means all
* formats accepted by the platform are accepted here — including single
* subtags, case-insensitive region codes, and script subtags. This is
* intentionally more permissive than a hand-rolled regex so
* that values coming directly from `navigator.language` (e.g. `"de"` on
* Firefox or `"de-de"` on Safari) are treated as valid.
*
* @param value - The value to check.
* @returns `true` if `value` is a valid BCP 47 language tag, `false` otherwise.
*
* @example
* // Single primary language subtag (e.g. Firefox)
* isLocaleFormat('de') // true
*
* @example
* // Standard language-REGION tag
* isLocaleFormat('en-US') // true
*
* @example
* // Case-insensitive region (e.g. Safari)
* isLocaleFormat('de-de') // true
*
* @example
* // Script subtag
* isLocaleFormat('zh-Hant-TW') // true
*
* @example
* // Invalid tag
* isLocaleFormat('not valid') // false
* isLocaleFormat('') // false
* isLocaleFormat(null) // false
*/
export declare function isLocaleFormat(value: any): value is Locale;
export declare function localizeNumber(value: number | string, locale: Locale, options: Intl.NumberFormatOptions): string;
export declare function localizeDate(date: Date, locale: Locale, options: DateFormatOptions): string;
export declare function isDate(value: any): boolean;
export declare function toDate(value: any): Date;
export declare function isoStringToDate(match: RegExpMatchArray): Date;