Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
intl-parse-accept-language
Advanced tools
Returns an array of `locale` strings, sorted by quality, given the string from an HTTP `Accept-Language` header.
Returns an array of locale
strings, sorted by quality, given the string from an HTTP Accept-Language
header.
locales
argument of Intl.DateTimeFormat
import { parseAcceptLanguage } from 'intl-parse-accept-language';
const locales = acceptLanguage('en-US,es;q=0.6,en;q=0.8,*;q=0.1');
// => ['en-US', 'en', 'es']
parseAcceptLanguage
accepts an optional configuration object as the second argument
option | description |
---|---|
validate | A validate callback that is called for each locale . If the locale is valid, return the locale as a string. Otherwise return undefined , null , or an empty Array. Should the callback throw an error, the error will be caught and the locale will be ignored. |
ignoreWildcard | A boolean that if set to true , the wildcard locale * will be returned in the array. If set to false , the wildcard locale * will be ignored. Defaults to true . |
If you're using the locales
array to do date formatting, you may want to use Intl.DateTimeFormat.supportedLocalesOf
as the validate
callback. This way only locales that are valid for date formatting will be returned.
For example:
import { parseAcceptLanguage } from 'intl-parse-accept-language';
const locales = parseAcceptLanguage('en-US,foo-BAR', {
validate: Intl.DateTimeFormat.supportedLocalesOf,
});
// => ['en-US']
Install the library with your package manager of choice, e.g.:
npm i intl-parse-accept-language
or
yarn add intl-parse-accept-language
© 2022 Donavon West. Released under MIT license.
FAQs
Returns an array of `locale` strings, sorted by quality, given the string from an HTTP `Accept-Language` header.
The npm package intl-parse-accept-language receives a total of 47,649 weekly downloads. As such, intl-parse-accept-language popularity was classified as popular.
We found that intl-parse-accept-language demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.