Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@escapace/accept-language-parser
Advanced tools
Parses the accept-language header from an HTTP request and produces an array of language objects sorted by quality.
Parses the accept-language header from an HTTP request and produces an array of language objects sorted by quality.
npm install @escapace/accept-language-parser
import { parse } from '@escapace/accept-language-parser'
const languages = 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.
import { pick } from '@escapace/accept-language-parser'
const language = 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'
The options
supports the loose
flag which allows partial matching on supported languages.
For example:
pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8', {
loose: true,
})
Would return:
'fr'
In loose mode the order of supportedLanguagesArray
matters, as it is the first partially matching language that is returned. It means that if you want to pick more specific langauges first, you should list it first as well.
For example:
;['fr-CA', 'fr']
FAQs
Parses the accept-language header from an HTTP request and produces an array of language objects sorted by quality.
The npm package @escapace/accept-language-parser receives a total of 623 weekly downloads. As such, @escapace/accept-language-parser popularity was classified as not popular.
We found that @escapace/accept-language-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.