Socket
Socket
Sign inDemoInstall

accept-language-parser

Package Overview
Dependencies
0
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    accept-language-parser

Parse the accept-language header from a HTTP request


Version published
Maintainers
4
Install size
13.2 kB
Created

Readme

Source

accept-language-parser

Build Status NPM version Dependencies

Parses the accept-language header from an HTTP request and produces an array of language objects sorted by quality.

dependencies: none

installation:

npm install accept-language-parser

parse usage:

var parser = require('accept-language-parser');

var languages = parser.parse('en-GB,en;q=0.8');

console.log(languages);

Output will be:

[
  {
    code: "en",
    region: "GB",
    quality: 1.0
  },
  {
    code: "en",
    region: undefined,
    quality: 0.8
  }
];

Output is always sorted in quality order from highest -> lowest. as per the http spec, omitting the quality value implies 1.0.

pick usage:

var parser = require('accept-language-parser');

var language = parser.pick(['fr-CA', 'fr-FR', 'fr'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8');

console.log(language);

Output will be:

"fr-CA"

Running tests

npm install
grunt test

Keywords

FAQs

Last updated on 09 Aug 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc