JSPM

  • Created
  • Published
  • Downloads 208999
  • Score
    100M100P100Q226381F
  • License MIT

Parse the HTTP Accept-Language header

Package Exports

  • accept-language

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (accept-language) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

accept-language Build Status

NPM

accept-language is an Node package that 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
  }
];

The output is always sorted with the highest quality first.