parse-accepts
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Parse-Accepts

A tool to parse headers like Accept, Accept-Language, etc.

Install

npm install parse-accepts

Example

const { parse, parseValue } = require("parse-accepts");
 
var accept = "text/html, application/xhtml+xml, application/xml;q=0.7, */*;q=0.8",
    acceptLang = "zh-CN, zh;q=0.8, en-US;q=0.5, en;q=0.3";
 
console.log(parse(accept));
// [ { value: 'text/html', quality: 1 },
//   { value: 'application/xhtml+xml', quality: 1 },
//   { value: '*/*', quality: 0.8 },
//   { value: 'application/xml', quality: 0.7 } ]
 
console.log(parseValue(accept));
// [ 'text/html', 'application/xhtml+xml', '*/*', 'application/xml' ]
 
console.log(parse(acceptLang));
// [ { value: 'zh-CN', quality: 1 },
//   { value: 'zh', quality: 0.8 },
//   { value: 'en-US', quality: 0.5 },
//   { value: 'en', quality: 0.3 } ]
 
console.log(parseValue(acceptLang));
// [ 'zh-CN', 'zh', 'en-US', 'en' ]

The sequence of the returning array will be ordered by their qualities.

Readme

Keywords

Package Sidebar

Install

npm i parse-accepts

Weekly Downloads

12

Version

0.1.1

License

MIT

Unpacked Size

4.91 kB

Total Files

7

Last publish

Collaborators

  • ayonli