Gathering detailed insights and metrics for bcp-47-match
Gathering detailed insights and metrics for bcp-47-match
Gathering detailed insights and metrics for bcp-47-match
Gathering detailed insights and metrics for bcp-47-match
Match BCP 47 language tags with language ranges per RFC 4647
npm install bcp-47-match
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
32 Stars
43 Commits
1 Forks
2 Watchers
1 Branches
2 Contributors
Updated on Jun 07, 2025
Latest Version
2.0.3
Package Id
bcp-47-match@2.0.3
Unpacked Size
19.07 kB
Size
5.71 kB
File Count
5
NPM Version
8.19.2
Node Version
19.0.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Match BCP 47 language tags with language ranges per RFC 4647.
This package can match BCP 47 language tags with “language ranges” per
RFC 4647.
This is done by the :lang()
pseudo class in CSS, the Accept-Language
HTTP
header, and a few other places.
You can use this package if you want to choose a certain document based on language tags.
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
1npm install bcp-47-match
In Deno with esm.sh
:
1import * as bcp47Match from 'https://esm.sh/bcp-47-match@2'
In browsers with esm.sh
:
1<script type="module"> 2 import * as bcp47Match from 'https://esm.sh/bcp-47-match@2?bundle' 3</script>
1import {basicFilter, extendedFilter, lookup} from 'bcp-47-match' 2 3const tags = ['en-GB', 'de-CH', 'en', 'de'] 4 5console.log(basicFilter(tags, '*')) // => [ 'en-GB', 'de-CH', 'en', 'de' ] 6console.log(basicFilter(tags, 'en')) // => [ 'en-GB', 'en' ] 7console.log(basicFilter(tags, 'en-GB')) // => [ 'en-GB' ] 8console.log(basicFilter(tags, ['en-GB', 'en'])) // => [ 'en-GB', 'en' ] 9console.log(basicFilter(tags, 'jp')) // => [] 10 11console.log(extendedFilter(tags, '*')) // => [ 'en-GB', 'de-CH', 'en', 'de' ] 12console.log(extendedFilter(tags, 'en')) // => [ 'en-GB', 'en' ] 13console.log(extendedFilter(tags, 'en-GB')) // => [ 'en-GB' ] 14console.log(extendedFilter(tags, '*-GB')) // => [ 'en-GB' ] 15console.log(extendedFilter(tags, ['en-GB', 'en'])) // => [ 'en-GB', 'en' ] 16console.log(extendedFilter(tags, 'jp')) // => [] 17 18console.log(lookup(tags, 'en')) // => 'en' 19console.log(lookup(tags, 'en-GB')) // => 'en-GB' 20console.log(lookup(tags, ['en-GB', 'en'])) // => 'en-GB' 21console.log(lookup(tags, ['en', 'en-GB'])) // => 'en' 22console.log(lookup(tags, 'jp')) // => undefined
This package exports the identifier basicFilter
, extendedFilter
, and
lookup
.
There is no default export.
basicFilter(tags[, ranges='*'])
👉 Note: See Basic Filtering spec
Match language tags to a list of simple ranges. Searches for matches between the first range and all tags, and continues with further ranges. Returns a list of matching tags in the order they matched.
Basic Filter | * | de | de-CH | de-DE | de-*-DE | *-CH |
---|---|---|---|---|---|---|
de | ✔︎ | ✔︎ | ||||
de-CH | ✔︎ | ✔︎ | ✔︎ | |||
de-CH-1996 | ✔︎ | ✔︎ | ✔︎ | |||
de-DE | ✔︎ | ✔︎ | ✔︎ | |||
de-DE-1996 | ✔︎ | ✔︎ | ✔︎ | |||
de-DE-x-goethe | ✔︎ | ✔︎ | ✔︎ | |||
de-Deva | ✔︎ | ✔︎ | ||||
de-Deva-DE | ✔︎ | ✔︎ | ||||
de-Latf-DE | ✔︎ | ✔︎ | ||||
de-Latn-DE | ✔︎ | ✔︎ | ||||
de-Latn-DE-1996 | ✔︎ | ✔︎ | ||||
de-x-DE | ✔︎ | ✔︎ | ||||
en | ✔︎ | |||||
en-GB | ✔︎ | |||||
zh | ✔︎ | |||||
zh-Hans | ✔︎ | |||||
zh-Hant | ✔︎ |
tags
(string
or Array<string>
)
— list of BCP 47 tagsranges
(string
or Array<string>
, default: '*'
)
— list of RFC 4647
basic ranges
(aka, matching /^(\*|[a-z]{1,8}(-[a-z0-9]{1,8})*)$/i
)Possibly empty list of matching tags in the order they matched
(Array<string>
).
extendedFilter(tags[, ranges='*'])
👉 Note: See Extended Filtering spec
Match language tags to a list of extended ranges. Searches for matches between the first range and all tags, and continues with further ranges.
Extended Filter | * | de | de-CH | de-DE | de-*-DE | *-CH |
---|---|---|---|---|---|---|
de | ✔︎ | ✔︎ | ||||
de-CH | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-CH-1996 | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-DE | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-DE-1996 | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-DE-x-goethe | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-Deva | ✔︎ | ✔︎ | ||||
de-Deva-DE | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-Latf-DE | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-Latn-DE | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-Latn-DE-1996 | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ||
de-x-DE | ✔︎ | ✔︎ | ||||
en | ✔︎ | |||||
en-GB | ✔︎ | |||||
zh | ✔︎ | |||||
zh-Hans | ✔︎ | |||||
zh-Hant | ✔︎ |
tags
(string
or Array<string>
)
— list of BCP 47 tagsranges
(string
or Array<string>
, default: '*'
)
— list of RFC 4647 extended ranges
(aka, matching /^(\*|[a-z]{1,8})(-(\*|[a-z0-9]{1,8}))*$/i
)Possibly empty list of matching tags in the order they matched
(Array<string>
).
lookup(tags, ranges)
👉 Note: See Lookup spec
Find the best language tag that matches a list of ranges. Searches for a match between the first range and all tags, and continues with further ranges. Returns the first match, if any.
Lookup | * | de | de-CH | de-DE | de-*-DE | *-CH |
---|---|---|---|---|---|---|
de | ✔︎︎ | ✔︎︎ | ✔︎ | ✔︎ | ✔︎ | |
de-CH | ✔︎ | ✔︎ | ||||
de-CH-1996 | ✔︎ | |||||
de-DE | ✔︎ | ✔︎ | ||||
de-DE-1996 | ✔︎ | |||||
de-DE-x-goethe | ✔︎ | |||||
de-Deva | ✔︎ | |||||
de-Deva-DE | ✔︎ | |||||
de-Latf-DE | ✔︎ | |||||
de-Latn-DE | ✔︎ | |||||
de-Latn-DE-1996 | ✔︎ | |||||
de-x-DE | ✔︎ | |||||
en | ✔︎ | |||||
en-GB | ✔︎ | |||||
zh | ✔︎ | |||||
zh-Hans | ✔︎ | |||||
zh-Hant | ✔︎ |
tags
(string
or Array<string>
)
— list of BCP 47 tagsranges
(string
or Array<string>
)
— list of RFC 4647 basic ranges (but *
is ignored)First matching tag in tags
, undefined
otherwise (string?
).
This package is fully typed with TypeScript. It exports no additional types.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
This package is safe.
wooorm/bcp-47
— parse and serialize BCP 47 language tagswooorm/bcp-47-normalize
— normalize, canonicalize, and format BCP 47 tagswooorm/iso-3166
— ISO 3166 codeswooorm/iso-639-2
— ISO 639-2 codeswooorm/iso-639-3
— ISO 639-3 codeswooorm/iso-15924
— ISO 15924 codeswooorm/un-m49
— UN M49 codesYes please! See How to Contribute to Open Source.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More