Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

accept-language

Package Overview
Dependencies
Maintainers
0
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accept-language

Accept-Language parser for nodejs

  • 3.0.20
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
186K
increased by5.68%
Maintainers
0
Weekly downloads
 
Created

What is accept-language?

The 'accept-language' npm package is a utility for parsing and handling the 'Accept-Language' HTTP header. It helps in determining the preferred language(s) of the user based on the header values, which is useful for internationalization (i18n) and localization (l10n) in web applications.

What are accept-language's main functionalities?

Parsing Accept-Language Header

This feature allows you to parse the 'Accept-Language' header and get an array of language codes with their respective quality values.

const acceptLanguage = require('accept-language');

const header = 'en-US,en;q=0.9,fr;q=0.8,de;q=0.7';
const languages = acceptLanguage.parse(header);
console.log(languages); // Output: [ { code: 'en-US', quality: 1 }, { code: 'en', quality: 0.9 }, { code: 'fr', quality: 0.8 }, { code: 'de', quality: 0.7 } ]

Getting Best Language Match

This feature allows you to determine the best matching language from a list of supported languages based on the 'Accept-Language' header.

const acceptLanguage = require('accept-language');

acceptLanguage.languages(['en', 'fr', 'de']);
const header = 'en-US,en;q=0.9,fr;q=0.8,de;q=0.7';
const bestMatch = acceptLanguage.get(header);
console.log(bestMatch); // Output: 'en'

Setting Default Language

This feature allows you to set a default language that will be used if none of the languages in the 'Accept-Language' header match the supported languages.

const acceptLanguage = require('accept-language');

acceptLanguage.defaultLanguage = 'en';
const header = 'es-ES,es;q=0.9';
const bestMatch = acceptLanguage.get(header);
console.log(bestMatch); // Output: 'en'

Other packages similar to accept-language

Keywords

FAQs

Package last updated on 11 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc