{"id":15429522,"url":"https://github.com/wooorm/bcp-47-match","last_synced_at":"2025-08-01T19:31:48.368Z","repository":{"id":32754066,"uuid":"141761944","full_name":"wooorm/bcp-47-match","owner":"wooorm","description":"Match BCP 47 language tags with language ranges per RFC 4647","archived":false,"fork":false,"pushed_at":"2022-11-15T11:44:35.000Z","size":79,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-27T06:52:06.274Z","etag":null,"topics":["bcp","bcp-47","code","i18n","language","range","rfc-4647","tag"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"wooorm"}},"created_at":"2018-07-20T22:05:52.000Z","updated_at":"2025-07-17T04:39:21.000Z","dependencies_parsed_at":"2023-01-14T22:07:50.780Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/bcp-47-match","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/wooorm/bcp-47-match","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbcp-47-match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbcp-47-match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbcp-47-match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbcp-47-match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/bcp-47-match/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbcp-47-match/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268285654,"owners_count":24225773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bcp","bcp-47","code","i18n","language","range","rfc-4647","tag"],"created_at":"2024-10-01T18:11:22.814Z","updated_at":"2025-08-01T19:31:48.337Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"readme":"\u003c!--lint disable no-html--\u003e\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\u003cscript type=\"module\"\u003e\n  import * as bcp47Match from 'https://esm.sh/bcp-47-match@2?bundle'\n\u003c/script\u003e\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, '*')) // =\u003e [ 'en-GB', 'de-CH', 'en', 'de' ]\nconsole.log(basicFilter(tags, 'en')) // =\u003e [ 'en-GB', 'en' ]\nconsole.log(basicFilter(tags, 'en-GB')) // =\u003e [ 'en-GB' ]\nconsole.log(basicFilter(tags, ['en-GB', 'en'])) // =\u003e [ 'en-GB', 'en' ]\nconsole.log(basicFilter(tags, 'jp')) // =\u003e []\n\nconsole.log(extendedFilter(tags, '*')) // =\u003e [ 'en-GB', 'de-CH', 'en', 'de' ]\nconsole.log(extendedFilter(tags, 'en')) // =\u003e [ 'en-GB', 'en' ]\nconsole.log(extendedFilter(tags, 'en-GB')) // =\u003e [ 'en-GB' ]\nconsole.log(extendedFilter(tags, '*-GB')) // =\u003e [ 'en-GB' ]\nconsole.log(extendedFilter(tags, ['en-GB', 'en'])) // =\u003e [ 'en-GB', 'en' ]\nconsole.log(extendedFilter(tags, 'jp')) // =\u003e []\n\nconsole.log(lookup(tags, 'en')) // =\u003e 'en'\nconsole.log(lookup(tags, 'en-GB')) // =\u003e 'en-GB'\nconsole.log(lookup(tags, ['en-GB', 'en'])) // =\u003e 'en-GB'\nconsole.log(lookup(tags, ['en', 'en-GB'])) // =\u003e 'en'\nconsole.log(lookup(tags, 'jp')) // =\u003e 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\u003e 👉 **Note**: See\n\u003e [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\u003cdetails\u003e\u003csummary\u003eView matching table\u003c/summary\u003e\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\u003c/details\u003e\n\n###### Parameters\n\n*   `tags` (`string` or `Array\u003cstring\u003e`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array\u003cstring\u003e`, 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\u003cstring\u003e`).\n\n### `extendedFilter(tags[, ranges='*'])`\n\n\u003e 👉 **Note**: See\n\u003e [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\u003cdetails\u003e\u003csummary\u003eView matching table\u003c/summary\u003e\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\u003c/details\u003e\n\n###### Parameters\n\n*   `tags` (`string` or `Array\u003cstring\u003e`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array\u003cstring\u003e`, 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\u003cstring\u003e`).\n\n### `lookup(tags, ranges)`\n\n\u003e 👉 **Note**: See\n\u003e [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\u003cdetails\u003e\u003csummary\u003eView matching table\u003c/summary\u003e\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\u003c/details\u003e\n\n###### Parameters\n\n*   `tags` (`string` or `Array\u003cstring\u003e`)\n    — list of BCP 47 tags\n*   `ranges` (`string` or `Array\u003cstring\u003e`)\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\u003c!-- Definitions --\u003e\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fbcp-47-match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fbcp-47-match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fbcp-47-match/lists"}