What is @types/accept-language-parser?
@types/accept-language-parser provides TypeScript type definitions for the accept-language-parser package, which is used to parse the Accept-Language header from HTTP requests. This package helps in determining the preferred languages of a user based on their browser settings.
What are @types/accept-language-parser's main functionalities?
Parse Accept-Language Header
This feature allows you to parse the Accept-Language header from an HTTP request. The code sample demonstrates how to parse a given Accept-Language header string and output the parsed languages.
const acceptLanguageParser = require('accept-language-parser');
const header = 'en-GB,en;q=0.8,fr;q=0.7';
const languages = acceptLanguageParser.parse(header);
console.log(languages);
Get Best Match
This feature allows you to determine the best match from a list of supported languages based on the Accept-Language header. The code sample shows how to find the best match from a list of supported languages.
const acceptLanguageParser = require('accept-language-parser');
const header = 'en-GB,en;q=0.8,fr;q=0.7';
const supportedLanguages = ['en', 'fr'];
const bestMatch = acceptLanguageParser.pick(supportedLanguages, header);
console.log(bestMatch);
Other packages similar to @types/accept-language-parser
negotiator
The negotiator package provides content negotiation utilities for HTTP servers. It can parse Accept, Accept-Charset, Accept-Encoding, and Accept-Language headers. Compared to accept-language-parser, negotiator offers a broader range of content negotiation features.
locale
The locale package is used to determine the user's locale based on the Accept-Language header. It provides similar functionality to accept-language-parser but focuses more on locale determination rather than just language parsing.
Installation
npm install --save @types/accept-language-parser
Summary
This package contains type definitions for accept-language-parser (https://github.com/opentable/accept-language-parser).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/accept-language-parser.
export function parse(acceptLanguage?: string): Language[];
export function pick<T extends string>(
supportedLanguages: T[],
acceptLanguage: string | Language[],
options?: PickOptions,
): T | null;
export interface Language {
code: string;
script?: string | null | undefined;
region?: string | undefined;
quality: number;
}
export interface PickOptions {
loose?: boolean | undefined;
}
Additional Details
- Last updated: Tue, 17 Oct 2023 21:12:30 GMT
- Dependencies: none
Credits
These definitions were written by Niklas Wulf, and Wooram Jun.