Socket
Socket
Sign inDemoInstall

accept-language

Package Overview
Dependencies
0
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    accept-language

HTTP Accept-Language parser for node


Version published
Weekly downloads
138K
decreased by-15.22%
Maintainers
1
Install size
7.22 kB
Created
Weekly downloads
 

Readme

Source

accept-language Build Status

NPM

accept-language parses HTTP Accept-Language header and returns a consumable array of language codes.

Installation:

npm install accept-language --save

Usage:

var acceptLanguage = require('accept-language');
var language = acceptLanguage.parse('en-GB,en;q=0.8,sv');

console.log(language);

Output:

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

Filter non-defined language codes:

var acceptLanguage = require('accept-language');
acceptLanguage.codes(['en', 'zh']);
var language = acceptLanguage.parse('en-GB,en;q=0.8,sv');

console.log(language);

Output:

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

Use default value:

var acceptLanguage = require('accept-language');
acceptLanguage.default({
    code : 'en',
    region : 'US'
    // No need to specify quality
});
acceptLanguage.codes(['en', 'zh']);
var language = acceptLanguage.parse('fr-CA');

console.log(language);

Output:

[
  {
    code: "en",
    region: "US",
    quality: 1.0
  }
];

The output is always sorted with the highest quality first.

Keywords

FAQs

Last updated on 24 Apr 2014

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