7
7
8
8
Normalize, canonicalize, and format [ BCP 47] [ spec ] tags.
9
9
10
- ## Install
10
+ ## Contents
11
+
12
+ * [ What is this?] ( #what-is-this )
13
+ * [ When should I use this?] ( #when-should-i-use-this )
14
+ * [ Install] ( #install )
15
+ * [ Use] ( #use )
16
+ * [ API] ( #api )
17
+ * [ ` bcp47Normalize(tag[, options]) ` ] ( #bcp47normalizetag-options )
18
+ * [ Types] ( #types )
19
+ * [ Compatibility] ( #compatibility )
20
+ * [ Security] ( #security )
21
+ * [ Related] ( #related )
22
+ * [ Contribute] ( #contribute )
23
+ * [ License] ( #license )
24
+
25
+ ## What is this?
26
+
27
+ This package takes BCP 47 tags and makes them uniform.
28
+ It removes unneeded info (` en-us ` -> ` en ` ) and replaces deprecated,
29
+ overlong, and otherwise unpreferred values with preferred values
30
+ (` en-bu ` -> ` en-MM ` ).
31
+ It works by applying [ Unicode CLDR suggestions] [ alias ] .
32
+
33
+ ## When should I use this?
34
+
35
+ You can use this package when dealing with user-provided language tags and want
36
+ to normalize and clean them.
11
37
12
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
13
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
38
+ ## Install
14
39
15
- [ npm] [ ] :
40
+ This package is [ ESM only] [ esm ] .
41
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
16
42
17
43
``` sh
18
44
npm install bcp-47-normalize
19
45
```
20
46
47
+ In Deno with [ Skypack] [ ] :
48
+
49
+ ``` js
50
+ import {bcp47Normalize } from ' https://cdn.skypack.dev/bcp-47-normalize@2?dts'
51
+ ```
52
+
53
+ In browsers with [ Skypack] [ ] :
54
+
55
+ ``` html
56
+ <script type =" module" >
57
+ import {bcp47Normalize } from ' https://cdn.skypack.dev/bcp-47-normalize@2?min'
58
+ </script >
59
+ ```
60
+
21
61
## Use
22
62
23
63
``` js
@@ -56,51 +96,73 @@ zh-hans-cn -> zh
56
96
57
97
## API
58
98
59
- This package exports the following identifiers : ` bcp47Normalize ` .
99
+ This package exports the following identifier : ` bcp47Normalize ` .
60
100
There is no default export.
61
101
62
102
### ` bcp47Normalize(tag[, options]) `
63
103
64
104
Normalize the given BCP 47 tag according to [ Unicode CLDR suggestions] [ alias ] .
65
105
66
- ###### ` options.forgiving `
106
+ ###### Parameters
67
107
68
- Passed to ` bcp-47 ` as [ ` options.forgiving ` ] [ forgiving ] .
108
+ * ` tag ` (` string ` )
109
+ — BCP 47 tag
110
+ * ` options.forgiving ` (` boolean ` , default: ` false ` )
111
+ — passed to ` bcp-47 ` as [ ` options.forgiving ` ] [ forgiving ]
112
+ * ` options.warning ` (` Function? ` , default: ` undefined ` )
113
+ — passed to ` bcp-47 ` as [ ` options.warning ` ] [ warning ]
69
114
70
- ###### ` options. warning`
115
+ One additional warning is given:
71
116
72
- Passed to ` bcp-47 ` as [ ` options.warning ` ] [ warning ] .
117
+ | code | reason |
118
+ | :--- | :--------------------------------------------------------- |
119
+ | 7 | Deprecated region ` CURRENT ` , expected one of ` SUGGESTIONS ` |
73
120
74
- One additional warning is given:
121
+ This warning is only given if the region cannot be automatically fixed (when
122
+ regions split into multiple regions).
75
123
76
- | code | reason |
77
- | :--- | :--------------------------------------------------------- |
78
- | 7 | Deprecated region ` CURRENT ` , expected one of ` SUGGESTIONS ` |
124
+ ###### Returns
79
125
80
- This warning is only given if the region cannot be automatically fixed (when
81
- regions split into multiple regions).
126
+ Normal, canonical, and pretty [ BCP 47] [ spec ] tag (` string ` ).
82
127
83
- ###### Returns
128
+ ## Types
84
129
85
- ` string ` — Normal, canonical, and pretty [ BCP 47] [ spec ] tag.
130
+ This package is fully typed with [ TypeScript] [ ] .
131
+ It exports additional ` Options ` and ` Warning ` types that model their respective
132
+ interfaces.
133
+
134
+ ## Compatibility
135
+
136
+ This package is at least compatible with all maintained versions of Node.js.
137
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
138
+ It also works in Deno and modern browsers.
139
+
140
+ ## Security
141
+
142
+ This package is safe.
86
143
87
144
## Related
88
145
89
- * [ ` bcp-47 ` ] ( https://github.com/wooorm/bcp-47-match )
90
- — Parse and stringify BCP 47 language tags
91
- * [ ` bcp-47-match ` ] ( https://github.com/wooorm/bcp-47-match )
92
- — Match BCP 47 language tags with language ranges per RFC 4647
93
- * [ ` iso-3166 ` ] ( https://github.com/wooorm/iso-3166 )
146
+ * [ ` wooorm/ bcp-47` ] ( https://github.com/wooorm/bcp-47-match )
147
+ — parse and stringify BCP 47 language tags
148
+ * [ ` wooorm/ bcp-47-match` ] ( https://github.com/wooorm/bcp-47-match )
149
+ — match BCP 47 language tags with language ranges per RFC 4647
150
+ * [ ` wooorm/ iso-3166` ] ( https://github.com/wooorm/iso-3166 )
94
151
— ISO 3166 codes
95
- * [ ` iso-639-2 ` ] ( https://github.com/wooorm/iso-639-2 )
152
+ * [ ` wooorm/ iso-639-2` ] ( https://github.com/wooorm/iso-639-2 )
96
153
— ISO 639-2 codes
97
- * [ ` iso-639-3 ` ] ( https://github.com/wooorm/iso-639-3 )
154
+ * [ ` wooorm/ iso-639-3` ] ( https://github.com/wooorm/iso-639-3 )
98
155
— ISO 639-3 codes
99
- * [ ` iso-15924 ` ] ( https://github.com/wooorm/iso-15924 )
156
+ * [ ` wooorm/ iso-15924` ] ( https://github.com/wooorm/iso-15924 )
100
157
— ISO 15924 codes
101
- * [ ` un-m49 ` ] ( https://github.com/wooorm/un-m49 )
158
+ * [ ` wooorm/ un-m49` ] ( https://github.com/wooorm/un-m49 )
102
159
— UN M49 codes
103
160
161
+ ## Contribute
162
+
163
+ Yes please!
164
+ See [ How to Contribute to Open Source] [ contribute ] .
165
+
104
166
## License
105
167
106
168
[ MIT] [ license ] © [ Titus Wormer] [ author ]
@@ -125,13 +187,21 @@ regions split into multiple regions).
125
187
126
188
[ npm ] : https://docs.npmjs.com/cli/install
127
189
190
+ [ skypack ] : https://www.skypack.dev
191
+
128
192
[ license ] : license
129
193
130
194
[ author ] : https://wooorm.com
131
195
132
- [ spec ] : https://tools.ietf.org/html/bcp47
196
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
197
+
198
+ [ typescript ] : https://www.typescriptlang.org
199
+
200
+ [ contribute ] : https://opensource.guide/how-to-contribute/
201
+
202
+ [ spec ] : https://tools.ietf.org/rfc/bcp/bcp47.html
133
203
134
- [ alias ] : https://github.com/unicode-org/cldr/blob/4b1225ead2ca9bc7a969a271b9931f137040d2bf /common/supplemental/supplementalMetadata.xml#L32
204
+ [ alias ] : https://github.com/unicode-org/cldr/blob/142b327 /common/supplemental/supplementalMetadata.xml#L32
135
205
136
206
[ forgiving ] : https://github.com/wooorm/bcp-47#optionsforgiving
137
207
0 commit comments