# intl-parse-accept-language

> Returns an array of `locale` strings, sorted by quality, given the string from an HTTP `Accept-Language` header.

Latest version **1.0.0** (published 2022-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install intl-parse-accept-language
pnpm add intl-parse-accept-language
yarn add intl-parse-accept-language
bun add intl-parse-accept-language
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-24 |
| First published | 2022-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Donavon West |
| Maintainers | donavon |
| Keywords | accept-language, parser, parse, header, headers, http |

## Links

- npm: https://www.npmjs.com/package/intl-parse-accept-language
- npm.io page: https://npm.io/package/intl-parse-accept-language

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-03-24
- 0.0.0 — 2022-03-24

## README

# intl-parse-accept-language

Returns an array of `locale` strings, sorted by quality, given the string from an HTTP `Accept-Language` header.

- Returned value is compatible with the `locales` argument of `Intl.DateTimeFormat`
- Written in TypeScript and fully typed
- 100% test coverage

## Example

```ts
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']
```

## Configuration

`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`.                                                                                                  |

## Pro Tip

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:

```ts
import { parseAcceptLanguage } from 'intl-parse-accept-language';

const locales = parseAcceptLanguage('en-US,foo-BAR', {
  validate: Intl.DateTimeFormat.supportedLocalesOf,
});
// => ['en-US']
```

## Getting Started

Install the library with your package manager of choice, e.g.:

```
npm i intl-parse-accept-language
```

or

```
yarn add intl-parse-accept-language
```

## Other works

- [parse-accept-language](https://npm.im/parse-accept-language)
- [accept-language-parser](https://npm.im/accept-language-parser)

## License

&copy; 2022 Donavon West. Released under [MIT license](./LICENSE).

---
_Source: https://npm.io/package/intl-parse-accept-language · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
