UNPKG

resolve-accept-language

Version:

Resolve the preferred locale based on the value of an `Accept-Language` HTTP header.

43 lines (42 loc) 1.78 kB
/** Class to manage a locale identifier using the BCP 47 `language`-`country` format. */ export declare class Locale { /** The ISO 639-1 alpha-2 language code. */ readonly languageCode: string; /** The ISO 3166-1 alpha-2 country code. */ readonly countryCode: string; /** The locale identifier using the BCP 47 `language`-`country` case-normalized format. */ readonly identifier: string; /** * Create a new `Locale` object. * * @param identifier - A locale identifier using the BCP 47 `language`-`country` format (case insensitive). * * @throws An error if the `identifier` format is invalid. */ constructor(identifier: string); } export declare class LocaleList { /** A set of ISO 639-1 alpha-2 language codes. */ readonly languages: Set<string>; /** A set of ISO 3166-1 alpha-2 country codes. */ readonly countries: Set<string>; /** A set of locale identifiers using the BCP 47 `language`-`country` case-normalized format. */ readonly locales: Set<string>; /** A list of locale objects. */ readonly objects: Locale[]; /** * Create a list of locale identifiers. * * @param locales - An set of unique locale identifiers using the BCP 47 `language`-`country` format (case insensitive). * * @throws Will throw an error if one of the locale's format is invalid. */ constructor(locales: Set<string>); } /** * Is a given string a locale identifier following the BCP 47 `language`-`country` format. * * @param identifier - A potential locale identify to verify. * @param caseNormalized - Should we verify if the identifier is using the case-normalized format? */ export declare const isLocale: (identifier: string, caseNormalized?: boolean) => boolean;