{"name":"bcp-47-match","version":"2.0.1","description":"Match BCP 47 language tags with language ranges per RFC 4647","license":"MIT","keywords":["bcp","47","bcp47","bcp-47","language","tag","match","matching","check","rfc","4647"],"repository":{"type":"git","url":"git+https://github.com/wooorm/bcp-47-match.git"},"bugs":{"url":"https://github.com/wooorm/bcp-47-match/issues"},"funding":{"type":"github","url":"https://github.com/sponsors/wooorm"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","devDependencies":{"@types/tape":"^4.0.0","c8":"^7.0.0","chalk":"^4.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.46.0"},"scripts":{"prepublishOnly":"npm run build && npm run format","build":"rimraf \"*.d.ts\" && tsc && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm",["gfm",{"tablePipeAlign":false}],["lint-table-pipe-alignment",false]]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"94c31cb95f2ed22a37714bd978952de19a2a1d13","homepage":"https://github.com/wooorm/bcp-47-match#readme","_id":"bcp-47-match@2.0.1","_nodeVersion":"17.0.1","_npmVersion":"8.1.0","dist":{"integrity":"sha512-+8o7axFDN/h8xATDM87FhnU1eod87dX0eZz1+cW3gggcicBqrmkZc33KBPWoE49qt5Asi5OhcxSOMOzp3opTfg==","shasum":"aa8e045386dd4356be07b1fd79d614c108459f4e","tarball":"http://registry-npm.ywwl.com/bcp-47-match/download/bcp-47-match-2.0.1.tgz","fileCount":5,"unpackedSize":18359,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2kg6CRA9TVsSAnZWagAAdGwP/RLNSmeaN3m7+FzJu2ad\nSJX6bLyFvs1Lc73DNuN07RloaF3qz1Y0i/dmIGm2piOilSv8lfeJFPOxlT5M\nH8vqVDEaLAS7EOizVW5DO+tU5c1nxMkPIehYIan/6MQn44WBlL7cWV/6XsHX\nDRBW/naxFbVEa22tsCWVIU5igBa47BBkHphLwIEyWnmPlEoF3vl+rDVoK/sD\nz/jrUa3fu6hUlR8a9rpNh+pnqgyOdo37Kl9JyfhjsON8RpJGALtGv52Sg9zE\nJGzXQNCG1A5NGbO+YBF5aAOdx9ACyC5Fq0WXLIW97pnRj5b/p/8hzFOiRL7/\nQ0b6DZF+Tsbw6AxaqJE993ehki/5VsJLSUoUDUnfch5As63qaJCZR+03mQWw\nJDy56OVDFLVhStulhq63Rx7M3b2YvFHEqV2Fg9dpEbkaiQRNnoVPJAMVgl1z\nF33Ck0W37vUZvxmfYaCwzUR9e+beolY/rJkerAE+qvT9SGyFvP+x3fbTffbn\nRxHdnHPEn4UQ0chozb5/RyOg4f+UcxJosvVn0941BoWegv0gnm1o6E+HXAfb\n+9aMRhzYzSjxda0fHkoFvP5yyebW9un67GJXF3HEkAeSipNTmCsMzx8BZ99/\nbNAy8sL+rXRfljTdXFyfvQolDEss5Qujf9xeIEaT8jtk9TNZqmZiSwXlMns3\nfBkv\r\n=myCb\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFjIeNuSkk208FuPa5w1x32qxAFLL4uTPtWgE+vocr5VAiAYam+KXu8tBFs1+ZdFcYnpcNskNcsV54KH79C64/fbOw=="}],"size":5666,"noattachment":false,"key":"/bcp-47-match/-/bcp-47-match-2.0.1.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bcp-47-match_2.0.1_1636037724616_0.9162208532704388"},"_hasShrinkwrap":false,"readme":"<!--lint disable no-html-->\n\n# bcp-47-match\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nMatch BCP 47 language tags with language ranges per RFC 4647.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`basicFilter(tags[, ranges='*'])`](#basicfiltertags-ranges)\n    *   [`extendedFilter(tags[, ranges='*'])`](#extendedfiltertags-ranges)\n    *   [`lookup(tags, ranges)`](#lookuptags-ranges)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package can match [BCP 47][spec] language tags with “language ranges” per\n[RFC 4647][match].\nThis is done by the `:lang()` pseudo class in CSS, the `Accept-Language` HTTP\nheader, and a few other places.\n\n## When should I use this?\n\nYou can use this package if you want to choose a certain document based on\nlanguage tags.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install bcp-47-match\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport * as bcp47Match from 'https://esm.sh/bcp-47-match@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import * as bcp47Match from 'https://esm.sh/bcp-47-match@2?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {basicFilter, extendedFilter, lookup} from 'bcp-47-match'\n\nconst tags = ['en-GB', 'de-CH', 'en', 'de']\n\nconsole.log(basicFilter(tags, '*')) // => [ 'en-GB', 'de-CH', 'en', 'de' ]\nconsole.log(basicFilter(tags, 'en')) // => [ 'en-GB', 'en' ]\nconsole.log(basicFilter(tags, 'en-GB')) // => [ 'en-GB' ]\nconsole.log(basicFilter(tags, ['en-GB', 'en'])) // => [ 'en-GB', 'en' ]\nconsole.log(basicFilter(tags, 'jp')) // => []\n\nconsole.log(extendedFilter(tags, '*')) // => [ 'en-GB', 'de-CH', 'en', 'de' ]\nconsole.log(extendedFilter(tags, 'en')) // => [ 'en-GB', 'en' ]\nconsole.log(extendedFilter(tags, 'en-GB')) // => [ 'en-GB' ]\nconsole.log(extendedFilter(tags, '*-GB')) // => [ 'en-GB' ]\nconsole.log(extendedFilter(tags, ['en-GB', 'en'])) // => [ 'en-GB', 'en' ]\nconsole.log(extendedFilter(tags, 'jp')) // => []\n\nconsole.log(lookup(tags, 'en')) // => 'en'\nconsole.log(lookup(tags, 'en-GB')) // => 'en-GB'\nconsole.log(lookup(tags, ['en-GB', 'en'])) // => 'en-GB'\nconsole.log(lookup(tags, ['en', 'en-GB'])) // => 'en'\nconsole.log(lookup(tags, 'jp')) // => undefined\n```\n\n## API\n\nThis package exports the identifier `basicFilter`, `extendedFilter`, and\n`lookup`.\nThere is no default export.\n\n### `basicFilter(tags[, ranges='*'])`\n\n> 👉 **Note**: See\n> [Basic Filtering spec](https://tools.ietf.org/html/rfc4647#section-3.3.1)\n\nMatch language tags to a list of simple ranges.\nSearches for matches between the first range and all tags, and continues\nwith further ranges.\nReturns a list of matching tags in the order they matched.\n\n<details><summary>View matching table</summary>\n\n| Basic Filter | `*` | `de` | `de-CH` | `de-DE` | `de-*-DE` | `*-CH` |\n| - | - | - | - | - | - | - |\n| `de` | ✔︎ | ✔︎ | | | | |\n| `de-CH` | ✔︎ | ✔︎ | ✔︎ | | | |\n| `de-CH-1996` | ✔︎ | ✔︎ | ✔︎ | | | |\n| `de-DE` | ✔︎ | ✔︎ | | ✔︎ | | |\n| `de-DE-1996` | ✔︎ | ✔︎ | | ✔︎ | | |\n| `de-DE-x-goethe` | ✔︎ | ✔︎ | | ✔︎ | | |\n| `de-Deva` | ✔︎ | ✔︎ | | | | |\n| `de-Deva-DE` | ✔︎ | ✔︎ | | | | |\n| `de-Latf-DE` | ✔︎ | ✔︎ | | | | |\n| `de-Latn-DE` | ✔︎ | ✔︎ | | | | |\n| `de-Latn-DE-1996` | ✔︎ | ✔︎ | | | | |\n| `de-x-DE` | ✔︎ | ✔︎ | | | | |\n| `en` | ✔︎ | | | | | |\n| `en-GB` | ✔︎ | | | | | |\n| `zh` | ✔︎ | | | | | |\n| `zh-Hans` | ✔︎ | | | | | |\n| `zh-Hant` | ✔︎ | | | | | |\n\n</details>\n\n###### Parameters\n\n*   `tags` (`string` or `Array<string>`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array<string>`, default: `'*'`)\n    — list of RFC 4647\n    [basic ranges][basic-range]\n    (aka, matching `/^(\\*|[a-z]{1,8}(-[a-z0-9]{1,8})*)$/i`)\n\n###### Returns\n\nPossibly empty list of matching tags in the order they matched\n(`Array<string>`).\n\n### `extendedFilter(tags[, ranges='*'])`\n\n> 👉 **Note**: See\n> [Extended Filtering spec](https://tools.ietf.org/html/rfc4647#section-3.3.2)\n\nMatch language tags to a list of extended ranges.\nSearches for matches between the first range and all tags, and continues\nwith further ranges.\n\n<details><summary>View matching table</summary>\n\n| Extended Filter | `*` | `de` | `de-CH` | `de-DE` | `de-*-DE` | `*-CH` |\n| - | - | - | - | - | - | - |\n| `de` | ✔︎ | ✔︎ | | | | |\n| `de-CH` | ✔︎ | ✔︎ | ✔︎ | | | ✔︎ |\n| `de-CH-1996` | ✔︎ | ✔︎ | ✔︎ | | | ✔︎ |\n| `de-DE` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-DE-1996` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-DE-x-goethe` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-Deva` | ✔︎ | ✔︎ | | | | |\n| `de-Deva-DE` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-Latf-DE` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-Latn-DE` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-Latn-DE-1996` | ✔︎ | ✔︎ | | ✔︎ | ✔︎ | |\n| `de-x-DE` | ✔︎ | ✔︎ | | | | |\n| `en` | ✔︎ | | | | | |\n| `en-GB` | ✔︎ | | | | | |\n| `zh` | ✔︎ | | | | | |\n| `zh-Hans` | ✔︎ | | | | | |\n| `zh-Hant` | ✔︎ | | | | | |\n\n</details>\n\n###### Parameters\n\n*   `tags` (`string` or `Array<string>`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array<string>`, default: `'*'`)\n    — list of RFC 4647 [extended ranges][extended-range]\n    (aka, matching `/^(\\*|[a-z]{1,8})(-(\\*|[a-z0-9]{1,8}))*$/i`)\n\n###### Returns\n\nPossibly empty list of matching tags in the order they matched\n(`Array<string>`).\n\n### `lookup(tags, ranges)`\n\n> 👉 **Note**: See\n> [Lookup spec](https://tools.ietf.org/html/rfc4647#section-3.4)\n\nFind the best language tag that matches a list of ranges.\nSearches for a match between the first range and all tags, and continues\nwith further ranges.\nReturns the first match, if any.\n\n<details><summary>View matching table</summary>\n\n| Lookup | `*` | `de` | `de-CH` | `de-DE` | `de-*-DE` | `*-CH` |\n| - | - | - | - | - | - | - |\n| `de` | | ✔︎︎ | ✔︎︎ | ✔︎ | ✔︎ | ✔︎ |\n| `de-CH` | | | ✔︎ | | | ✔︎ |\n| `de-CH-1996` | | | | | | ✔︎ |\n| `de-DE` | | | | ✔︎ | | ✔︎ |\n| `de-DE-1996` | | | | | | ✔︎ |\n| `de-DE-x-goethe` | | | | | | ✔︎ |\n| `de-Deva` | | | | | | ✔︎ |\n| `de-Deva-DE` | | | | | | ✔︎ |\n| `de-Latf-DE` | | | | | | ✔︎ |\n| `de-Latn-DE` | | | | | | ✔︎ |\n| `de-Latn-DE-1996` | | | | | | ✔︎ |\n| `de-x-DE` | | | | | | ✔︎ |\n| `en` | | | | | | ✔︎ |\n| `en-GB` | | | | | | ✔︎ |\n| `zh` | | | | | | ✔︎ |\n| `zh-Hans` | | | | | | ✔︎ |\n| `zh-Hant` | | | | | | ✔︎ |\n\n</details>\n\n###### Parameters\n\n*   `tags` (`string` or `Array<string>`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array<string>`)\n    — list of RFC 4647 basic ranges (but `*` is ignored)\n\n###### Returns\n\nFirst matching tag in `tags`, `undefined` otherwise (`string?`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 14.14+ and 16.0+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe.\n\n## Related\n\n*   [`wooorm/bcp-47`](https://github.com/wooorm/bcp-47)\n    — parse and serialize BCP 47 language tags\n*   [`wooorm/bcp-47-normalize`](https://github.com/wooorm/bcp-47-normalize)\n    — normalize, canonicalize, and format BCP 47 tags\n*   [`wooorm/iso-3166`](https://github.com/wooorm/iso-3166)\n    — ISO 3166 codes\n*   [`wooorm/iso-639-2`](https://github.com/wooorm/iso-639-2)\n    — ISO 639-2 codes\n*   [`wooorm/iso-639-3`](https://github.com/wooorm/iso-639-3)\n    — ISO 639-3 codes\n*   [`wooorm/iso-15924`](https://github.com/wooorm/iso-15924)\n    — ISO 15924 codes\n*   [`wooorm/un-m49`](https://github.com/wooorm/un-m49)\n    — UN M49 codes\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/wooorm/bcp-47-match/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/bcp-47-match/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/bcp-47-match.svg\n\n[coverage]: https://codecov.io/github/wooorm/bcp-47-match\n\n[downloads-badge]: https://img.shields.io/npm/dm/bcp-47-match.svg\n\n[downloads]: https://www.npmjs.com/package/bcp-47-match\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/bcp-47-match.svg\n\n[size]: https://bundlephobia.com/result?p=bcp-47-match\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[spec]: https://tools.ietf.org/html/bcp47\n\n[match]: https://tools.ietf.org/html/rfc4647\n\n[basic-range]: https://tools.ietf.org/html/rfc4647#section-2.1\n\n[extended-range]: https://tools.ietf.org/html/rfc4647#section-2.2\n","publish_time":1636037724780,"_cnpm_publish_time":1636037724780,"dist-tags":{"latest":"2.0.3"}}