{"name":"bcp-47-match","version":"1.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"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"}],"files":["index.js"],"dependencies":{},"devDependencies":{"browserify":"^16.0.0","chalk":"^2.4.1","nyc":"^12.0.0","prettier":"^1.11.0","remark-cli":"^5.0.0","remark-preset-wooorm":"^4.0.0","tape":"^4.0.0","tinyify":"^2.4.3","xo":"^0.21.0"},"scripts":{"format":"remark . -qfo && prettier --write '**/*.js' && xo --fix","build-bundle":"browserify index.js -s bcp47Match > bcp-47-match.js","build-mangle":"browserify index.js -s bcp47Match -p tinyify > bcp-47-match.min.js","build":"npm run build-bundle && npm run build-mangle","test-api":"node test","test-coverage":"nyc --reporter lcov tape test.js","test":"npm run format && npm run build && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"esnext":false},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"7f726bc9ed245b63c87b597952135d4d00981e3b","homepage":"https://github.com/wooorm/bcp-47-match#readme","_id":"bcp-47-match@1.0.0","_npmVersion":"6.2.0","_nodeVersion":"10.0.0","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"dist":{"integrity":"sha512-6rzWe2U70JHrYfBqBnhoeV7HykhmCQ6X2RrBcbpkyCwtNpkGadr3m3LF8ZLXpQ7qrsLCOm3eis2lsVemkLsvHg==","shasum":"24e1ffc4b6905177e299c21756b6c9f347fe573e","tarball":"http://registry-npm.ywwl.com/bcp-47-match/download/bcp-47-match-1.0.0.tgz","fileCount":4,"unpackedSize":15955,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbUl6lCRA9TVsSAnZWagAA//8P/1p7wkHhz9uaISziSmJ1\nG52l44X73qB3KzlH44gzDZWFZtMBqhu2uK/tiEzcsODkXmrf6fzA3xlzZvsM\nQZUvEZYyjNjcxpEphTkaU/pNaODHLRh6I/4vBvcfBnS9RGEi48DfoHujowE5\nc0p2ihRtpCVors8lyxJXEEeXAmFhXUqFyYfvYOqZgKTbArIToY92hDTq6tnf\nGeRWHLjEae86hLw7Cn1G+hoEIpMaWDuB93oFr76tIlhUXUUycxjEMmGfVlAa\nHp5Nw2XYzcTvm7kVuWVEg1db5Msoz4knZwES5DvcmrsUSdga9JAhrOXN+Ln/\nmGZjm7PJN6/l9cpDilCUbWRYyjSmurMfWxQJB63+js40UsGo/fwp7LxHk64u\nyBawiAMBgDYKPbJaBhCyDKpH7PDdQduODBzP7sTDKhUQ3OgPcyCYEE+nYahj\nxJBtJx7mf9t6hxry4uzBvB7v0aUm6tYbjnNrVUUhloyjRoPtecLOxPu4pziI\nbdxP8kBKaf7kxQnZj/y4IgSGckgJZB3rnA3yrcDRlEJ1BXFH+xLVNLPY2o6W\nKCb6zhIUCRrVYugxi4Qmi64OkpqEVVPNep/MWn6mWaYnH9iyWGvjeAIUDkAZ\nHt04t3w1sojz3vknsJz5luL2B6ZtD76HXK5r3hPXa4946ROK3Gna3LmInRFY\naXrG\r\n=AOfG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCB9Ee4IQGxUdgwgcxB1h7RsSKqIFnH8wOEkIs2Q/KpoAIhAI+vIBaEyUNHOmbDMXtvQEybvUOoSaKmf0luM34n4szH"}],"size":4496,"noattachment":false,"key":"/bcp-47-match/-/bcp-47-match-1.0.0.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bcp-47-match_1.0.0_1532124837544_0.3006539440057172"},"_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":1532124837628,"_cnpm_publish_time":1532124837628,"dist-tags":{"latest":"2.0.3"}}