UNPKG

resolve-accept-language

Version:

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

30 lines (29 loc) 1.26 kB
/** An object representing an HTTP `Accept-Language` header directive. */ type Directive = { /** The ISO 639-1 alpha-2 language code. */ languageCode: string; /** The ISO 3166-1 alpha-2 country code. */ countryCode?: string; /** The locale identifier using the BCP 47 `language`-`country` in case-normalized format. */ locale?: string; /** The quality factor (default is 1; values can range from 0 to 1 with up to 3 decimals). */ quality: number; }; /** A directive object including the position in its HTTP header. */ type IndexedDirective = Directive & { /** This is the position of the directive in the HTTP header. */ headerPosition: number; }; /** A directive object including the position in its HTTP header and the locale. */ export type IndexedDirectiveWithLocale = IndexedDirective & { locale: string; }; /** * Get a list of directives from an HTTP `Accept-Language` header. * * @param acceptLanguageHeader - The value of an HTTP request `Accept-Language` header (also known as a "language priority list"). * * @returns A list of `IndexedDirective` objects sorted by quality and header position. */ export declare const getDirectives: (acceptLanguageHeader: string) => IndexedDirective[]; export {};