@fgv/ts-bcp47 5.0.0-21 → 5.0.0-23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/data/bcp/overrides.json +0 -20
- package/src/data/iana/language-subtags.json +0 -57439
- package/src/data/iana/language-tag-extensions.json +0 -38
- package/src/data/unsd/m49.json +0 -3723
- package/src/index.ts +0 -29
- package/src/packlets/bcp47/bcp47Subtags/converters.ts +0 -33
- package/src/packlets/bcp47/bcp47Subtags/index.ts +0 -27
- package/src/packlets/bcp47/bcp47Subtags/model.ts +0 -46
- package/src/packlets/bcp47/bcp47Subtags/validate.ts +0 -55
- package/src/packlets/bcp47/common.ts +0 -85
- package/src/packlets/bcp47/helpers.ts +0 -117
- package/src/packlets/bcp47/index.ts +0 -38
- package/src/packlets/bcp47/languageRegistryData.ts +0 -304
- package/src/packlets/bcp47/languageTag.ts +0 -467
- package/src/packlets/bcp47/languageTagParser.ts +0 -307
- package/src/packlets/bcp47/match/chooser.ts +0 -164
- package/src/packlets/bcp47/match/common.ts +0 -57
- package/src/packlets/bcp47/match/index.ts +0 -26
- package/src/packlets/bcp47/match/similarity.ts +0 -243
- package/src/packlets/bcp47/normalization/baseNormalizer.ts +0 -146
- package/src/packlets/bcp47/normalization/canonicalNormalizer.ts +0 -102
- package/src/packlets/bcp47/normalization/common.ts +0 -84
- package/src/packlets/bcp47/normalization/index.ts +0 -27
- package/src/packlets/bcp47/normalization/normalizeTag.ts +0 -116
- package/src/packlets/bcp47/normalization/preferredTagNormalizer.ts +0 -213
- package/src/packlets/bcp47/overrides/converters.ts +0 -58
- package/src/packlets/bcp47/overrides/defaultRegistries.ts +0 -40
- package/src/packlets/bcp47/overrides/index.ts +0 -25
- package/src/packlets/bcp47/overrides/model.ts +0 -33
- package/src/packlets/bcp47/overrides/overridesRegistry.ts +0 -104
- package/src/packlets/bcp47/validation/baseValidator.ts +0 -132
- package/src/packlets/bcp47/validation/common.ts +0 -86
- package/src/packlets/bcp47/validation/index.ts +0 -29
- package/src/packlets/bcp47/validation/isCanonical.ts +0 -103
- package/src/packlets/bcp47/validation/isInPreferredForm.ts +0 -53
- package/src/packlets/bcp47/validation/isStrictlyValid.ts +0 -117
- package/src/packlets/bcp47/validation/isValid.ts +0 -122
- package/src/packlets/bcp47/validation/isWellFormed.ts +0 -102
- package/src/packlets/bcp47/validation/validateTag.ts +0 -175
- package/src/packlets/iana/common/converters.ts +0 -67
- package/src/packlets/iana/common/model.ts +0 -56
- package/src/packlets/iana/common/registeredItems.ts +0 -145
- package/src/packlets/iana/common/utils.ts +0 -32
- package/src/packlets/iana/common/validate.ts +0 -64
- package/src/packlets/iana/converters.ts +0 -26
- package/src/packlets/iana/defaultRegistries.ts +0 -40
- package/src/packlets/iana/index.ts +0 -33
- package/src/packlets/iana/jar/converters.ts +0 -26
- package/src/packlets/iana/jar/index.ts +0 -27
- package/src/packlets/iana/jar/jarConverters.ts +0 -70
- package/src/packlets/iana/jar/jarModel.ts +0 -34
- package/src/packlets/iana/jar/language-subtags/converters.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/index.ts +0 -27
- package/src/packlets/iana/jar/language-subtags/model.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/registry/converters.ts +0 -40
- package/src/packlets/iana/jar/language-subtags/registry/index.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/registry/model.ts +0 -171
- package/src/packlets/iana/jar/language-subtags/tags/converters.ts +0 -120
- package/src/packlets/iana/jar/language-subtags/tags/index.ts +0 -28
- package/src/packlets/iana/jar/language-subtags/tags/model.ts +0 -71
- package/src/packlets/iana/jar/language-subtags/tags/tagValidation.ts +0 -67
- package/src/packlets/iana/jar/language-subtags/tags/validate.ts +0 -106
- package/src/packlets/iana/jar/model.ts +0 -26
- package/src/packlets/iana/language-subtags/common.ts +0 -46
- package/src/packlets/iana/language-subtags/converters.ts +0 -226
- package/src/packlets/iana/language-subtags/index.ts +0 -30
- package/src/packlets/iana/language-subtags/jarConverters.ts +0 -269
- package/src/packlets/iana/language-subtags/model.ts +0 -213
- package/src/packlets/iana/language-subtags/scope.ts +0 -222
- package/src/packlets/iana/language-subtags/subtagRegistry.ts +0 -136
- package/src/packlets/iana/language-subtags/validate.ts +0 -23
- package/src/packlets/iana/language-tag-extensions/converters.ts +0 -71
- package/src/packlets/iana/language-tag-extensions/extensionsRegistry.ts +0 -92
- package/src/packlets/iana/language-tag-extensions/extensionsScope.ts +0 -60
- package/src/packlets/iana/language-tag-extensions/index.ts +0 -29
- package/src/packlets/iana/language-tag-extensions/jarConverters.ts +0 -91
- package/src/packlets/iana/language-tag-extensions/model.ts +0 -67
- package/src/packlets/iana/language-tag-extensions/validate.ts +0 -36
- package/src/packlets/iana/languageRegistries.ts +0 -57
- package/src/packlets/iana/model.ts +0 -26
- package/src/packlets/iana/validate.ts +0 -23
- package/src/packlets/unsd/areas.ts +0 -105
- package/src/packlets/unsd/common.ts +0 -79
- package/src/packlets/unsd/csv/converters.ts +0 -82
- package/src/packlets/unsd/csv/index.ts +0 -26
- package/src/packlets/unsd/csv/model.ts +0 -44
- package/src/packlets/unsd/defaultRegistries.ts +0 -40
- package/src/packlets/unsd/index.ts +0 -28
- package/src/packlets/unsd/regionCodes.ts +0 -144
- package/src/packlets/unsd/regions.ts +0 -95
- package/src/packlets/utils/index.ts +0 -24
- package/src/packlets/utils/jsonHelpers.ts +0 -25
- package/src/packlets/utils/public.ts +0 -28
- package/src/packlets/utils/validationHelpers.ts +0 -180
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import * as Iana from '../iana';
|
|
24
|
-
|
|
25
|
-
import { IExtensionSubtagValue, ISubtags, subtagsToString } from './common';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Represents a single extlang subtag with corresponding registry data,
|
|
29
|
-
* if present.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export interface IRegisteredExtLangValue {
|
|
33
|
-
/**
|
|
34
|
-
* A {@link Iana.LanguageSubtags.ExtLangSubtag | extlang subtag} from
|
|
35
|
-
* the original language tag.
|
|
36
|
-
*/
|
|
37
|
-
subtag: Iana.LanguageSubtags.ExtLangSubtag;
|
|
38
|
-
/**
|
|
39
|
-
* The {@link Iana.LanguageSubtag.Model.RegisteredExtLang | IANA subtag registry entry}
|
|
40
|
-
* for this subtag, or `undefined` if the subtag is not registered.
|
|
41
|
-
*/
|
|
42
|
-
registry?: Iana.LanguageSubtags.Model.IRegisteredExtLang;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Represents a single variant subtag with corresponding registry data,
|
|
47
|
-
* if present.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export interface IRegisteredVariantValue {
|
|
51
|
-
/**
|
|
52
|
-
* A {@link Iana.LanguageSubtags.VariantSubtag | variant subtag} from
|
|
53
|
-
* the original language tag.
|
|
54
|
-
*/
|
|
55
|
-
subtag: Iana.LanguageSubtags.VariantSubtag;
|
|
56
|
-
/**
|
|
57
|
-
* The {@link Iana.LanguageSubtag.Model.RegisteredVariant | IANA subtag registry entry}
|
|
58
|
-
* for this subtag, or `undefined` if the subtag is not registered.
|
|
59
|
-
*/
|
|
60
|
-
registry?: Iana.LanguageSubtags.Model.IRegisteredVariant;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Represents a single extension subtag with corresponding registry data,
|
|
65
|
-
* if present.
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
export interface IRegisteredExtensionValue extends IExtensionSubtagValue {
|
|
69
|
-
/**
|
|
70
|
-
* The language extensions registry entry for the associated subtag,
|
|
71
|
-
* or `undefined` if the extension is not registered.
|
|
72
|
-
*/
|
|
73
|
-
registry?: Iana.LanguageTagExtensions.Model.ILanguageTagExtension;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Returns all of the data in the IANA language subtags registry for
|
|
78
|
-
* a set of supplied {@link Bcp47.Subtags | subtags}.
|
|
79
|
-
* @public
|
|
80
|
-
*/
|
|
81
|
-
export class LanguageRegistryData {
|
|
82
|
-
/**
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
protected _iana: Iana.LanguageRegistries;
|
|
86
|
-
/**
|
|
87
|
-
* @internal
|
|
88
|
-
*/
|
|
89
|
-
protected _subtags: ISubtags;
|
|
90
|
-
/**
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
protected _primaryLanguage?: Iana.LanguageSubtags.Model.IRegisteredLanguage | false;
|
|
94
|
-
/**
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
protected _extlangs?: IRegisteredExtLangValue[] | false;
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
protected _script?: Iana.LanguageSubtags.Model.IRegisteredScript | false;
|
|
102
|
-
/**
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
105
|
-
protected _effectiveScript?: Iana.LanguageSubtags.Model.IRegisteredScript | false;
|
|
106
|
-
/**
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
protected _region?: Iana.LanguageSubtags.Model.IRegisteredRegion | false;
|
|
110
|
-
/**
|
|
111
|
-
* @internal
|
|
112
|
-
*/
|
|
113
|
-
protected _variants?: IRegisteredVariantValue[] | false;
|
|
114
|
-
/**
|
|
115
|
-
* @internal
|
|
116
|
-
*/
|
|
117
|
-
protected _extensions?: IRegisteredExtensionValue[] | false;
|
|
118
|
-
/**
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
|
-
protected _grandfathered?: Iana.LanguageSubtags.Model.IRegisteredGrandfatheredTag | false;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Constructs a new {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
125
|
-
* from a supplied {@link Bcp47.Subtags | subtags} and {@link Iana.LanguageRegistries | language registries}.
|
|
126
|
-
* @public
|
|
127
|
-
*/
|
|
128
|
-
public constructor(subtags: ISubtags, iana: Iana.LanguageRegistries) {
|
|
129
|
-
this._iana = iana;
|
|
130
|
-
this._subtags = subtags;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Registry data associated with the primary language subtag of the language tag from
|
|
135
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
136
|
-
* was constructed, or `undefined` if the primary language is missing or invalid.
|
|
137
|
-
* @public
|
|
138
|
-
*/
|
|
139
|
-
public get primaryLanguage(): Iana.LanguageSubtags.Model.IRegisteredLanguage | undefined {
|
|
140
|
-
if (this._primaryLanguage === undefined) {
|
|
141
|
-
this._primaryLanguage = this._iana.subtags.languages.tryGet(this._subtags.primaryLanguage) ?? false;
|
|
142
|
-
}
|
|
143
|
-
return this._primaryLanguage ? this._primaryLanguage : undefined;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Registry data associated with the extlang subtag of the language tag from
|
|
148
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
149
|
-
* was constructed, or `undefined` if extlang is missing or invalid.
|
|
150
|
-
* @public
|
|
151
|
-
*/
|
|
152
|
-
public get extlangs(): IRegisteredExtLangValue[] | undefined {
|
|
153
|
-
if (this._extlangs === undefined) {
|
|
154
|
-
if (this._subtags.extlangs !== undefined) {
|
|
155
|
-
this._extlangs = this._subtags.extlangs.map((e) => {
|
|
156
|
-
return {
|
|
157
|
-
subtag: e,
|
|
158
|
-
registry: this._iana.subtags.extlangs.tryGet(e)
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (!this._subtags.extlangs || this._subtags.extlangs.length === 0) {
|
|
163
|
-
this._extlangs = false;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return this._extlangs ? this._extlangs : undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Registry data associated with the script of the language tag from
|
|
171
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
172
|
-
* was constructed, or `undefined` if the script cannot be determined.
|
|
173
|
-
*
|
|
174
|
-
* @public
|
|
175
|
-
*/
|
|
176
|
-
public get script(): Iana.LanguageSubtags.Model.IRegisteredScript | undefined {
|
|
177
|
-
if (this._script === undefined) {
|
|
178
|
-
if (this._subtags.script) {
|
|
179
|
-
this._script = this._iana.subtags.scripts.tryGet(this._subtags.script);
|
|
180
|
-
}
|
|
181
|
-
if (!this._script) {
|
|
182
|
-
this._script = false;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return this._script ? this._script : undefined;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Registry data associated with the script of the language tag from
|
|
190
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
191
|
-
* was constructed, or `undefined` if the script cannot be determined.
|
|
192
|
-
*
|
|
193
|
-
* Note that effectiveScript will default to the registry `Suppress-Script` value of the
|
|
194
|
-
* primary language if no script subtag is present.
|
|
195
|
-
* @public
|
|
196
|
-
*/
|
|
197
|
-
public get effectiveScript(): Iana.LanguageSubtags.Model.IRegisteredScript | undefined {
|
|
198
|
-
if (this._effectiveScript === undefined) {
|
|
199
|
-
if (this._subtags.script) {
|
|
200
|
-
this._effectiveScript = this._iana.subtags.scripts.tryGet(this._subtags.script);
|
|
201
|
-
} else if (!this._effectiveScript) {
|
|
202
|
-
const suppressed = this.primaryLanguage?.suppressScript;
|
|
203
|
-
if (suppressed) {
|
|
204
|
-
this._effectiveScript = this._iana.subtags.scripts.tryGet(suppressed);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (!this._effectiveScript) {
|
|
208
|
-
this._effectiveScript = false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return this._effectiveScript ? this._effectiveScript : undefined;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Registry data associated with the region subtag of the language tag from
|
|
216
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
217
|
-
* was constructed, or `undefined` if the region is missing or invalid.
|
|
218
|
-
* @public
|
|
219
|
-
*/
|
|
220
|
-
public get region(): Iana.LanguageSubtags.Model.IRegisteredRegion | undefined {
|
|
221
|
-
if (this._region === undefined) {
|
|
222
|
-
if (this._subtags.region) {
|
|
223
|
-
this._region = this._iana.subtags.regions.tryGet(this._subtags.region);
|
|
224
|
-
}
|
|
225
|
-
if (!this._region) {
|
|
226
|
-
this._region = false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return this._region ? this._region : undefined;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Registry data associated with the variant subtags of the language tag from
|
|
234
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
235
|
-
* was constructed, or `undefined` if variant subtags are missing or invalid.
|
|
236
|
-
* @public
|
|
237
|
-
*/
|
|
238
|
-
public get variants(): IRegisteredVariantValue[] | undefined {
|
|
239
|
-
if (this._variants === undefined) {
|
|
240
|
-
if (this._subtags.variants !== undefined) {
|
|
241
|
-
this._variants = this._subtags.variants.map((v) => {
|
|
242
|
-
return {
|
|
243
|
-
subtag: v,
|
|
244
|
-
registry: this._iana.subtags.variants.tryGet(v)
|
|
245
|
-
};
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
if (!this._subtags.variants || this._subtags.variants.length === 0) {
|
|
249
|
-
this._variants = false;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return this._variants ? this._variants : undefined;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Registry data associated with the extension subtags of the language tag from
|
|
257
|
-
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
258
|
-
* was constructed, or `undefined` if extension subtags are missing or invalid.
|
|
259
|
-
* @public
|
|
260
|
-
*/
|
|
261
|
-
public get extensions(): IRegisteredExtensionValue[] | undefined {
|
|
262
|
-
if (this._extensions === undefined) {
|
|
263
|
-
if (this._subtags.extensions !== undefined) {
|
|
264
|
-
this._extensions = this._subtags.extensions.map((e) => {
|
|
265
|
-
return {
|
|
266
|
-
...e,
|
|
267
|
-
registry: this._iana.extensions.extensions.tryGet(e.singleton)
|
|
268
|
-
};
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
if (!this._subtags.variants || this._subtags.variants.length === 0) {
|
|
272
|
-
this._variants = false;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return this._extensions ? this._extensions : undefined;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Registry data for grandfathered tags, or `undefined` if the tag is not recognized
|
|
280
|
-
* as a grandfathered tag.
|
|
281
|
-
* @public
|
|
282
|
-
*/
|
|
283
|
-
public get grandfathered(): Iana.LanguageSubtags.Model.IRegisteredGrandfatheredTag | undefined {
|
|
284
|
-
if (this._grandfathered === undefined) {
|
|
285
|
-
if (this._subtags.grandfathered) {
|
|
286
|
-
this._grandfathered = this._iana.subtags.grandfathered.tryGet(this._subtags.grandfathered);
|
|
287
|
-
}
|
|
288
|
-
if (!this._grandfathered) {
|
|
289
|
-
this._grandfathered = false;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return this._grandfathered ? this._grandfathered : undefined;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @returns A string representation of the subtags from which this
|
|
297
|
-
* {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
298
|
-
* was created.
|
|
299
|
-
* @public
|
|
300
|
-
*/
|
|
301
|
-
public toString(): string {
|
|
302
|
-
return subtagsToString(this._subtags);
|
|
303
|
-
}
|
|
304
|
-
}
|