{"name":"bcp-47-match","version":"2.0.0","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":"^9.0.0","remark-preset-wooorm":"^8.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.38.0"},"scripts":{"prepack":"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 test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js","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,"rules":{"import/no-mutable-exports":"off","no-var":"off","prefer-arrow-callback":"off"}},"remarkConfig":{"plugins":["preset-wooorm",["gfm",{"tablePipeAlign":false}],["lint-table-pipe-alignment",false]]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true},"gitHead":"1f4efb75bf89e51a5c5d757adb3893701eb00bde","homepage":"https://github.com/wooorm/bcp-47-match#readme","_id":"bcp-47-match@2.0.0","_nodeVersion":"15.11.0","_npmVersion":"7.6.2","dist":{"integrity":"sha512-B3/f3fqIdWLUQE/iFIahFmDKB6X2U7RcugRcdEj2Ntju13zrewCSqnEwG92iUUKfkZ6I+UMtT2NCBwLCvXBOmg==","shasum":"d0481051d51608cb5f5d7f75f5f5668e273dc469","tarball":"http://registry-npm.ywwl.com/bcp-47-match/download/bcp-47-match-2.0.0.tgz","fileCount":5,"unpackedSize":16946,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgZZznCRA9TVsSAnZWagAAQUYQAKItsKfc1oVjfobpf1KZ\nDwwTpHSxa6LzM+jq7Mom9uAU1VFev6SIz0ijPG5lZ7OqDscQDAwY7I32MMC7\nzkh8hZ/YS7MJaRf12R0nGVnzo3Do38mNL5MKLEYOHstUrFdAlGTAelKAdf8d\n3mbK6JQN/WX7THvH7UrVNNd399z4Yqex/z9ivwnj6+VG0Rq33+vnlimEl6nA\nQ6tPWKrF18UgomZTRmtSlROMIV5Zu/p7R+5tnOuHjYHeDsvG3vj+4tYAdUJ2\n5AcVlbjYslgbQ6mz8o3r+vcjUVStBWqEy4vl32dg1ALOQsoGzOjrbH0hcoPy\nNoEyT56DR9PA8hNJmQ8Zt/c+YMruWGcUdV0hSdXTh2K+S1+Fn13YkqVV6PH+\nI2KeyY+tch7rlDtm3FoTvSbIonwyzLOLe85xEYKu14hnLS58Q6TjcnVNTdcz\n8y9trZSR4lEZqktJuete7MwakdNtGwytW5kAiOriV6HifI2UPzNpeAMv6Cl6\nmwe2yYCKCujUNpmlLykV0NVEGx1j4h1CuqXCJROP30JBZiuFrzparxRIb4/P\nUvYWs9JHSftTsi/4f9iMgK7Q2ljLvqmVBIMJGgfWZsOZSY5KzQIWTc0z+xEB\nbF4Ph0T7SBsKyF3IXRsJKhdP6HT1TSxZFF4BWIBgih/CQJWibxO6ZzAPKwSt\nhuna\r\n=0Qlt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGM35MJpQzX+IRQVbwxGT8PaQvShbjQuJb8Ia15STRFoAiEA+qjx5OxutIQG75YAYuVyfoo1YDYrMj50x54iyqG1IP8="}],"size":5236,"noattachment":false,"key":"/bcp-47-match/-/bcp-47-match-2.0.0.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.0_1617272038610_0.8150288982946172"},"_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":1617272038758,"_cnpm_publish_time":1617272038758,"dist-tags":{"latest":"2.0.3"}}