Intl.LocaleMatcher ponyfill providing comprehensive locale matching algorithms with support for 'lookup' and 'best fit' strategies
94
Build a utility that parses and applies user locale preferences from locale strings with Unicode extensions to formatting configuration objects.
Your utility should:
en-US-u-ca-buddhist-nu-thai-hc-h12)The utility should handle:
en-US)en-US-u-ca-gregory)The returned configuration should have this structure:
{
locale: string, // The original locale identifier
calendar: string | null, // Resolved calendar system (e.g., 'buddhist', 'gregory')
numberingSystem: string | null, // Resolved numbering system (e.g., 'thai', 'latn')
hourCycle: string | null // Resolved hour cycle (e.g., 'h12', 'h23')
}@generates
export interface LocaleConfig {
locale: string;
calendar: string | null;
numberingSystem: string | null;
hourCycle: string | null;
}
export interface UserOptions {
calendar?: string;
numberingSystem?: string;
hourCycle?: string;
}
/**
* Parse a locale string with Unicode extensions and merge with user options
*
* @param localeString - A BCP 47 locale identifier that may include Unicode extensions
* @param options - Optional user preferences that override extension values
* @returns Configuration object with resolved locale and extension values
*/
export function parseLocalePreferences(
localeString: string,
options?: UserOptions
): LocaleConfig;Provides Unicode locale extension parsing and processing capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-formatjs--intl-localematcherdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10