You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

accept-language-parser

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accept-language-parser

Parse the accept-language header from a HTTP request

1.1.0
Source
npm
Version published
Weekly downloads
518K
13.3%
Maintainers
3
Weekly downloads
 
Created

What is accept-language-parser?

The accept-language-parser npm package is used to parse the Accept-Language header from HTTP requests. This header is used by browsers to indicate the user's language preferences. The package helps in extracting and interpreting these preferences, making it easier to serve content in the user's preferred language.

What are 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 as an array of objects.

const acceptLanguageParser = require('accept-language-parser');
const header = 'en-GB,en;q=0.9,fr;q=0.8,de;q=0.7';
const languages = acceptLanguageParser.parse(header);
console.log(languages);

Get Best Language Match

This feature allows you to find the best match for the user's language preferences from a list of supported languages. The code sample demonstrates how to use the 'pick' method to get the best matching language from the supported languages.

const acceptLanguageParser = require('accept-language-parser');
const header = 'en-GB,en;q=0.9,fr;q=0.8,de;q=0.7';
const supportedLanguages = ['en', 'fr', 'de'];
const bestMatch = acceptLanguageParser.pick(supportedLanguages, header);
console.log(bestMatch);

Other packages similar to accept-language-parser

Keywords

accept-language

FAQs

Package last updated on 16 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts