@fgv/ts-bcp47 5.1.0-2 → 5.1.0-4
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/dist/data/bcp/overrides.json +21 -0
- package/dist/data/unsd/m49.json +3723 -0
- package/dist/index.browser.js +30 -0
- package/dist/index.js +28 -0
- package/dist/packlets/bcp47/bcp47Subtags/converters.js +32 -0
- package/dist/packlets/bcp47/bcp47Subtags/index.js +26 -0
- package/dist/packlets/bcp47/bcp47Subtags/model.js +23 -0
- package/dist/packlets/bcp47/bcp47Subtags/validate.js +48 -0
- package/dist/packlets/bcp47/common.js +53 -0
- package/dist/packlets/bcp47/helpers.js +96 -0
- package/dist/packlets/bcp47/index.js +32 -0
- package/dist/packlets/bcp47/languageRegistryData.js +202 -0
- package/dist/packlets/bcp47/languageTag.js +363 -0
- package/dist/packlets/bcp47/languageTagParser.js +275 -0
- package/dist/packlets/bcp47/match/chooser.js +88 -0
- package/dist/packlets/bcp47/match/common.js +49 -0
- package/dist/packlets/bcp47/match/index.js +26 -0
- package/dist/packlets/bcp47/match/similarity.js +205 -0
- package/dist/packlets/bcp47/normalization/baseNormalizer.js +89 -0
- package/dist/packlets/bcp47/normalization/canonicalNormalizer.js +86 -0
- package/dist/packlets/bcp47/normalization/common.js +77 -0
- package/dist/packlets/bcp47/normalization/index.js +27 -0
- package/dist/packlets/bcp47/normalization/normalizeTag.js +101 -0
- package/dist/packlets/bcp47/normalization/preferredTagNormalizer.js +177 -0
- package/dist/packlets/bcp47/overrides/converters.js +49 -0
- package/dist/packlets/bcp47/overrides/defaultRegistries.js +38 -0
- package/dist/packlets/bcp47/overrides/index.js +25 -0
- package/dist/packlets/bcp47/overrides/model.js +23 -0
- package/dist/packlets/bcp47/overrides/overridesRegistry.js +83 -0
- package/dist/packlets/bcp47/validation/baseValidator.js +86 -0
- package/dist/packlets/bcp47/validation/common.js +77 -0
- package/dist/packlets/bcp47/validation/index.js +29 -0
- package/dist/packlets/bcp47/validation/isCanonical.js +79 -0
- package/dist/packlets/bcp47/validation/isInPreferredForm.js +46 -0
- package/dist/packlets/bcp47/validation/isStrictlyValid.js +94 -0
- package/dist/packlets/bcp47/validation/isValid.js +92 -0
- package/dist/packlets/bcp47/validation/isWellFormed.js +75 -0
- package/dist/packlets/bcp47/validation/validateTag.js +153 -0
- package/dist/packlets/iana/common/converters.js +58 -0
- package/dist/packlets/iana/common/model.js +23 -0
- package/dist/packlets/iana/common/registeredItems.js +120 -0
- package/dist/packlets/iana/common/utils.js +30 -0
- package/dist/packlets/iana/common/validate.js +59 -0
- package/dist/packlets/iana/converters.js +25 -0
- package/dist/packlets/iana/defaultRegistries.js +38 -0
- package/dist/packlets/iana/iana-data-embedded.js +60 -0
- package/dist/packlets/iana/index.browser.js +34 -0
- package/dist/packlets/iana/index.js +34 -0
- package/dist/packlets/iana/jar/converters.js +25 -0
- package/dist/packlets/iana/jar/index.js +26 -0
- package/dist/packlets/iana/jar/jarConverters.js +60 -0
- package/dist/packlets/iana/jar/jarModel.js +23 -0
- package/dist/packlets/iana/jar/language-subtags/converters.js +25 -0
- package/dist/packlets/iana/jar/language-subtags/index.js +26 -0
- package/dist/packlets/iana/jar/language-subtags/model.js +25 -0
- package/dist/packlets/iana/jar/language-subtags/registry/converters.js +180 -0
- package/dist/packlets/iana/jar/language-subtags/registry/index.js +26 -0
- package/dist/packlets/iana/jar/language-subtags/registry/model.js +43 -0
- package/dist/packlets/iana/jar/language-subtags/tags/converters.js +101 -0
- package/dist/packlets/iana/jar/language-subtags/tags/index.js +27 -0
- package/dist/packlets/iana/jar/language-subtags/tags/model.js +23 -0
- package/dist/packlets/iana/jar/language-subtags/tags/tagValidation.js +66 -0
- package/dist/packlets/iana/jar/language-subtags/tags/validate.js +85 -0
- package/dist/packlets/iana/jar/model.js +25 -0
- package/dist/packlets/iana/language-subtags/common.js +23 -0
- package/dist/packlets/iana/language-subtags/converters.js +182 -0
- package/dist/packlets/iana/language-subtags/index.browser.js +30 -0
- package/dist/packlets/iana/language-subtags/index.js +29 -0
- package/dist/packlets/iana/language-subtags/jarConverters.js +288 -0
- package/dist/packlets/iana/language-subtags/model.js +23 -0
- package/dist/packlets/iana/language-subtags/scope.js +169 -0
- package/dist/packlets/iana/language-subtags/subtagRegistry.js +108 -0
- package/dist/packlets/iana/language-subtags/validate.js +23 -0
- package/dist/packlets/iana/language-tag-extensions/converters.js +59 -0
- package/dist/packlets/iana/language-tag-extensions/extensionsRegistry.js +64 -0
- package/dist/packlets/iana/language-tag-extensions/extensionsScope.js +50 -0
- package/dist/packlets/iana/language-tag-extensions/index.js +28 -0
- package/dist/packlets/iana/language-tag-extensions/jarConverters.js +143 -0
- package/dist/packlets/iana/language-tag-extensions/model.js +24 -0
- package/dist/packlets/iana/language-tag-extensions/validate.js +33 -0
- package/dist/packlets/iana/languageRegistries.js +80 -0
- package/dist/packlets/iana/languageRegistriesFileLoader.js +73 -0
- package/dist/packlets/iana/languageRegistriesLoader.js +113 -0
- package/dist/packlets/iana/model.js +25 -0
- package/dist/packlets/iana/validate.js +23 -0
- package/dist/packlets/unsd/areas.js +92 -0
- package/dist/packlets/unsd/common.js +23 -0
- package/dist/packlets/unsd/csv/converters.js +75 -0
- package/dist/packlets/unsd/csv/index.js +25 -0
- package/dist/packlets/unsd/csv/model.js +23 -0
- package/dist/packlets/unsd/defaultRegistries.js +38 -0
- package/dist/packlets/unsd/index.js +27 -0
- package/dist/packlets/unsd/regionCodes.js +115 -0
- package/dist/packlets/unsd/regions.js +71 -0
- package/dist/packlets/utils/index.js +24 -0
- package/dist/packlets/utils/jsonHelpers.js +25 -0
- package/dist/packlets/utils/public.js +24 -0
- package/dist/packlets/utils/validationHelpers.js +116 -0
- package/dist/test/unit/bcp47/commonTestCases.js +475 -0
- package/dist/test/unit/bcp47/languageTagHelpers.js +178 -0
- package/dist/test/unit/iana/testConstants.js +68 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +36 -31
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
/* eslint-disable @rushstack/typedef-var */
|
|
23
|
+
import * as TagConverters from '../jar/language-subtags/tags/converters';
|
|
24
|
+
import { Converters } from '@fgv/ts-utils';
|
|
25
|
+
import { datedRegistry, yearMonthDaySpec } from '../common/converters';
|
|
26
|
+
import { JsonFile } from '@fgv/ts-json-base';
|
|
27
|
+
import { registryScopeType } from '../jar/language-subtags/registry/converters';
|
|
28
|
+
export { TagConverters as Tags };
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export const extendedLanguageRange = TagConverters.extendedLanguageRange;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export const registeredLanguage = Converters.strictObject({
|
|
37
|
+
type: Converters.enumeratedValue(['language']),
|
|
38
|
+
subtag: TagConverters.languageSubtag,
|
|
39
|
+
description: Converters.stringArray,
|
|
40
|
+
added: yearMonthDaySpec,
|
|
41
|
+
comments: Converters.stringArray,
|
|
42
|
+
deprecated: yearMonthDaySpec,
|
|
43
|
+
macrolanguage: TagConverters.languageSubtag,
|
|
44
|
+
preferredValue: TagConverters.languageSubtag,
|
|
45
|
+
scope: registryScopeType,
|
|
46
|
+
suppressScript: TagConverters.scriptSubtag,
|
|
47
|
+
subtagRangeEnd: TagConverters.languageSubtag
|
|
48
|
+
}, {
|
|
49
|
+
description: 'language subtag registry entry',
|
|
50
|
+
optionalFields: [
|
|
51
|
+
'comments',
|
|
52
|
+
'deprecated',
|
|
53
|
+
'macrolanguage',
|
|
54
|
+
'preferredValue',
|
|
55
|
+
'scope',
|
|
56
|
+
'suppressScript',
|
|
57
|
+
'subtagRangeEnd'
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export const registeredExtLang = Converters.strictObject({
|
|
64
|
+
type: Converters.enumeratedValue(['extlang']),
|
|
65
|
+
subtag: TagConverters.tagOrStartOfTagRange(TagConverters.extlangSubtag),
|
|
66
|
+
preferredValue: TagConverters.extendedLanguageRange,
|
|
67
|
+
prefix: TagConverters.extlangPrefix,
|
|
68
|
+
description: Converters.stringArray,
|
|
69
|
+
added: yearMonthDaySpec,
|
|
70
|
+
comments: Converters.stringArray,
|
|
71
|
+
deprecated: yearMonthDaySpec,
|
|
72
|
+
macrolanguage: TagConverters.languageSubtag,
|
|
73
|
+
scope: registryScopeType,
|
|
74
|
+
suppressScript: TagConverters.scriptSubtag
|
|
75
|
+
}, {
|
|
76
|
+
description: 'extlang subtag registry entry',
|
|
77
|
+
optionalFields: ['comments', 'deprecated', 'macrolanguage', 'scope', 'suppressScript']
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export const registeredScript = Converters.strictObject({
|
|
83
|
+
type: Converters.enumeratedValue(['script']),
|
|
84
|
+
subtag: TagConverters.scriptSubtag,
|
|
85
|
+
description: Converters.stringArray,
|
|
86
|
+
added: yearMonthDaySpec,
|
|
87
|
+
comments: Converters.stringArray,
|
|
88
|
+
deprecated: yearMonthDaySpec,
|
|
89
|
+
preferredValue: TagConverters.scriptSubtag,
|
|
90
|
+
subtagRangeEnd: TagConverters.scriptSubtag
|
|
91
|
+
}, {
|
|
92
|
+
description: 'script subtag registry entry',
|
|
93
|
+
optionalFields: ['comments', 'deprecated', 'preferredValue', 'subtagRangeEnd']
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
export const registeredRegion = Converters.strictObject({
|
|
99
|
+
type: Converters.enumeratedValue(['region']),
|
|
100
|
+
subtag: TagConverters.regionSubtag,
|
|
101
|
+
description: Converters.stringArray,
|
|
102
|
+
added: yearMonthDaySpec,
|
|
103
|
+
comments: Converters.stringArray,
|
|
104
|
+
deprecated: yearMonthDaySpec,
|
|
105
|
+
preferredValue: TagConverters.regionSubtag,
|
|
106
|
+
subtagRangeEnd: TagConverters.regionSubtag
|
|
107
|
+
}, {
|
|
108
|
+
description: 'region subtag registry entry',
|
|
109
|
+
optionalFields: ['comments', 'deprecated', 'preferredValue', 'subtagRangeEnd']
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export const registeredVariant = Converters.strictObject({
|
|
115
|
+
type: Converters.enumeratedValue(['variant']),
|
|
116
|
+
subtag: TagConverters.variantSubtag,
|
|
117
|
+
description: Converters.stringArray,
|
|
118
|
+
added: yearMonthDaySpec,
|
|
119
|
+
comments: Converters.stringArray,
|
|
120
|
+
deprecated: yearMonthDaySpec,
|
|
121
|
+
preferredValue: TagConverters.variantSubtag,
|
|
122
|
+
prefix: Converters.arrayOf(TagConverters.extendedLanguageRange)
|
|
123
|
+
}, {
|
|
124
|
+
description: 'variant subtag registry entry',
|
|
125
|
+
optionalFields: ['comments', 'deprecated', 'preferredValue', 'prefix']
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
export const registeredGrandfatheredTag = Converters.strictObject({
|
|
131
|
+
type: Converters.enumeratedValue(['grandfathered']),
|
|
132
|
+
tag: TagConverters.grandfatheredTag,
|
|
133
|
+
description: Converters.stringArray,
|
|
134
|
+
added: yearMonthDaySpec,
|
|
135
|
+
comments: Converters.stringArray,
|
|
136
|
+
deprecated: yearMonthDaySpec,
|
|
137
|
+
preferredValue: TagConverters.extendedLanguageRange
|
|
138
|
+
}, {
|
|
139
|
+
description: 'grandfathered tag registry entry',
|
|
140
|
+
optionalFields: ['comments', 'deprecated', 'preferredValue']
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export const registeredRedundantTag = Converters.strictObject({
|
|
146
|
+
type: Converters.enumeratedValue(['redundant']),
|
|
147
|
+
tag: TagConverters.redundantTag,
|
|
148
|
+
description: Converters.stringArray,
|
|
149
|
+
added: yearMonthDaySpec,
|
|
150
|
+
comments: Converters.stringArray,
|
|
151
|
+
deprecated: yearMonthDaySpec,
|
|
152
|
+
preferredValue: TagConverters.extendedLanguageRange
|
|
153
|
+
}, {
|
|
154
|
+
description: 'redundant tag registry entry',
|
|
155
|
+
optionalFields: ['comments', 'deprecated', 'preferredValue']
|
|
156
|
+
});
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
export const registeredItem = Converters.discriminatedObject('type', {
|
|
161
|
+
language: registeredLanguage,
|
|
162
|
+
extlang: registeredExtLang,
|
|
163
|
+
script: registeredScript,
|
|
164
|
+
region: registeredRegion,
|
|
165
|
+
variant: registeredVariant,
|
|
166
|
+
grandfathered: registeredGrandfatheredTag,
|
|
167
|
+
redundant: registeredRedundantTag
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
export const registryFile = datedRegistry(registeredItem);
|
|
173
|
+
/**
|
|
174
|
+
* @public
|
|
175
|
+
* @param path - String path from which file is to be loaded.
|
|
176
|
+
* @returns `Success` with the resulting {@link Iana.LanguageSubtags.Model.RegistryFile | registry file}
|
|
177
|
+
* or `Failure` with details if an error occurs.
|
|
178
|
+
*/
|
|
179
|
+
export function loadLanguageSubtagsJsonFileSync(path) {
|
|
180
|
+
return JsonFile.convertJsonFileSync(path, registryFile);
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
// Browser-safe LanguageSubtags exports - excludes Node.js filesystem dependencies
|
|
23
|
+
import * as Converters from './converters';
|
|
24
|
+
import * as JarConverters from './jarConverters';
|
|
25
|
+
import * as Model from './model';
|
|
26
|
+
import * as Validate from './validate';
|
|
27
|
+
export * from './common';
|
|
28
|
+
// Exclude: LanguageSubtagRegistry (static load methods require Node.js fs/path)
|
|
29
|
+
export { Converters, JarConverters, Model, Validate };
|
|
30
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
import * as Converters from './converters';
|
|
23
|
+
import * as JarConverters from './jarConverters';
|
|
24
|
+
import * as Model from './model';
|
|
25
|
+
import * as Validate from './validate';
|
|
26
|
+
export * from './common';
|
|
27
|
+
export { LanguageSubtagRegistry } from './subtagRegistry';
|
|
28
|
+
export { Converters, JarConverters, Model, Validate };
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,288 @@
|
|
|
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
|
+
import * as TagConverters from '../jar/language-subtags/tags/converters';
|
|
23
|
+
import { RecordJar } from '@fgv/ts-extras';
|
|
24
|
+
import { Converters, succeed } from '@fgv/ts-utils';
|
|
25
|
+
import { datedRegistry, yearMonthDaySpec } from '../common/converters';
|
|
26
|
+
import { JsonFile } from '@fgv/ts-json-base';
|
|
27
|
+
import { datedRegistryFromJarRecords } from '../jar/jarConverters';
|
|
28
|
+
import { jarRegistryEntry } from '../jar/language-subtags/registry/converters';
|
|
29
|
+
import { registryScopeType } from '../jar/language-subtags/registry/converters';
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export const registeredLanguage = Converters.transformObject({
|
|
34
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['language']) },
|
|
35
|
+
subtag: { from: 'Subtag', converter: TagConverters.tagOrStartOfTagRange(TagConverters.languageSubtag) },
|
|
36
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
37
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
38
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
39
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
40
|
+
macrolanguage: { from: 'Macrolanguage', converter: TagConverters.languageSubtag, optional: true },
|
|
41
|
+
preferredValue: { from: 'Preferred-Value', converter: TagConverters.languageSubtag, optional: true },
|
|
42
|
+
scope: { from: 'Scope', converter: registryScopeType, optional: true },
|
|
43
|
+
suppressScript: { from: 'Suppress-Script', converter: TagConverters.scriptSubtag, optional: true },
|
|
44
|
+
subtagRangeEnd: {
|
|
45
|
+
from: 'Subtag',
|
|
46
|
+
converter: TagConverters.endOfTagRangeOrUndefined(TagConverters.languageSubtag),
|
|
47
|
+
optional: true
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
strict: true,
|
|
51
|
+
description: 'language subtag'
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export const registeredExtLang = Converters.transformObject({
|
|
57
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['extlang']) },
|
|
58
|
+
subtag: { from: 'Subtag', converter: TagConverters.extlangSubtag },
|
|
59
|
+
preferredValue: { from: 'Preferred-Value', converter: TagConverters.extendedLanguageRange },
|
|
60
|
+
prefix: { from: 'Prefix', converter: TagConverters.extlangPrefix },
|
|
61
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
62
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
63
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
64
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
65
|
+
macrolanguage: { from: 'Macrolanguage', converter: TagConverters.languageSubtag, optional: true },
|
|
66
|
+
scope: { from: 'Scope', converter: registryScopeType, optional: true },
|
|
67
|
+
suppressScript: { from: 'Suppress-Script', converter: TagConverters.scriptSubtag, optional: true }
|
|
68
|
+
}, {
|
|
69
|
+
strict: true,
|
|
70
|
+
description: 'extlang subtag'
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export const registeredScript = Converters.transformObject({
|
|
76
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['script']) },
|
|
77
|
+
subtag: { from: 'Subtag', converter: TagConverters.tagOrStartOfTagRange(TagConverters.scriptSubtag) },
|
|
78
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
79
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
80
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
81
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
82
|
+
preferredValue: { from: 'Preferred-Value', converter: TagConverters.scriptSubtag, optional: true },
|
|
83
|
+
subtagRangeEnd: {
|
|
84
|
+
from: 'Subtag',
|
|
85
|
+
converter: TagConverters.endOfTagRangeOrUndefined(TagConverters.scriptSubtag),
|
|
86
|
+
optional: true
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
strict: true,
|
|
90
|
+
description: 'script subtag'
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export const registeredRegion = Converters.transformObject({
|
|
96
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['region']) },
|
|
97
|
+
subtag: { from: 'Subtag', converter: TagConverters.tagOrStartOfTagRange(TagConverters.regionSubtag) },
|
|
98
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
99
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
100
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
101
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
102
|
+
preferredValue: { from: 'Preferred-Value', converter: TagConverters.regionSubtag, optional: true },
|
|
103
|
+
subtagRangeEnd: {
|
|
104
|
+
from: 'Subtag',
|
|
105
|
+
converter: TagConverters.endOfTagRangeOrUndefined(TagConverters.regionSubtag),
|
|
106
|
+
optional: true
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
strict: true,
|
|
110
|
+
description: 'region subtag'
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export const registeredVariant = Converters.transformObject({
|
|
116
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['variant']) },
|
|
117
|
+
subtag: { from: 'Subtag', converter: TagConverters.variantSubtag },
|
|
118
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
119
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
120
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
121
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
122
|
+
preferredValue: { from: 'Preferred-Value', converter: TagConverters.variantSubtag, optional: true },
|
|
123
|
+
prefix: {
|
|
124
|
+
from: 'Prefix',
|
|
125
|
+
converter: Converters.arrayOf(TagConverters.extendedLanguageRange),
|
|
126
|
+
optional: true
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
strict: true,
|
|
130
|
+
description: 'variant subtag'
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
export const registeredGrandfatheredTag = Converters.transformObject({
|
|
136
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['grandfathered']) },
|
|
137
|
+
tag: { from: 'Tag', converter: TagConverters.grandfatheredTag },
|
|
138
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
139
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
140
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
141
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
142
|
+
preferredValue: {
|
|
143
|
+
from: 'Preferred-Value',
|
|
144
|
+
converter: TagConverters.extendedLanguageRange,
|
|
145
|
+
optional: true
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
strict: true,
|
|
149
|
+
description: 'grandfathered tag'
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export const registeredRedundantTag = Converters.transformObject({
|
|
155
|
+
type: { from: 'Type', converter: Converters.enumeratedValue(['redundant']) },
|
|
156
|
+
tag: { from: 'Tag', converter: TagConverters.redundantTag },
|
|
157
|
+
description: { from: 'Description', converter: Converters.stringArray },
|
|
158
|
+
added: { from: 'Added', converter: yearMonthDaySpec },
|
|
159
|
+
comments: { from: 'Comments', converter: Converters.stringArray, optional: true },
|
|
160
|
+
deprecated: { from: 'Deprecated', converter: yearMonthDaySpec, optional: true },
|
|
161
|
+
preferredValue: {
|
|
162
|
+
from: 'Preferred-Value',
|
|
163
|
+
converter: TagConverters.extendedLanguageRange,
|
|
164
|
+
optional: true
|
|
165
|
+
}
|
|
166
|
+
}, {
|
|
167
|
+
strict: true,
|
|
168
|
+
description: 'redundant tag'
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
export const registeredItem = Converters.discriminatedObject('Type', {
|
|
174
|
+
language: registeredLanguage,
|
|
175
|
+
extlang: registeredExtLang,
|
|
176
|
+
script: registeredScript,
|
|
177
|
+
region: registeredRegion,
|
|
178
|
+
variant: registeredVariant,
|
|
179
|
+
grandfathered: registeredGrandfatheredTag,
|
|
180
|
+
redundant: registeredRedundantTag
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
export const registryFile = datedRegistry(registeredItem);
|
|
186
|
+
/**
|
|
187
|
+
* Loads a JSON-format language subtag registry file.
|
|
188
|
+
* @param path - The string path from which the registry is to be loaded.
|
|
189
|
+
* @returns `Success` with the resulting {@link Iana.LanguageSubtags.Model.RegistryFile | registry file}
|
|
190
|
+
* or `Failure` with details if an error occurs.
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
export function loadJsonSubtagRegistryFileSync(path) {
|
|
194
|
+
return JsonFile.convertJsonFileSync(path, registryFile);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Loads a text (JAR) format language subtag registry file.
|
|
198
|
+
* @param path - The string path from which the registry is to be loaded.
|
|
199
|
+
* @returns `Success` with the resulting {@link Iana.LanguageSubtags.Model.RegistryFile | registry file}
|
|
200
|
+
* or `Failure` with details if an error occurs.
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export function loadTxtSubtagRegistryFileSync(path) {
|
|
204
|
+
return RecordJar.readRecordJarFileSync(path, {
|
|
205
|
+
arrayFields: ['Comments', 'Description', 'Prefix'],
|
|
206
|
+
fixedContinuationSize: 1
|
|
207
|
+
}).onSuccess((jar) => {
|
|
208
|
+
return datedRegistryFromJarRecords(registeredItem).convert(jar);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Parses a text (JAR) format language subtag registry from string content.
|
|
213
|
+
* @param content - The string content of the registry file to be parsed.
|
|
214
|
+
* @returns `Success` with the resulting {@link Iana.LanguageSubtags.Model.RegistryFile | registry file}
|
|
215
|
+
* or `Failure` with details if an error occurs.
|
|
216
|
+
* @public
|
|
217
|
+
*/
|
|
218
|
+
export function loadTxtSubtagRegistryFromString(content) {
|
|
219
|
+
const lines = content.split(/\r?\n/);
|
|
220
|
+
return RecordJar.parseRecordJarLines(lines, {
|
|
221
|
+
arrayFields: ['Comments', 'Description', 'Prefix'],
|
|
222
|
+
fixedContinuationSize: 1
|
|
223
|
+
}).onSuccess((jar) => {
|
|
224
|
+
return datedRegistryFromJarRecords(registeredItem).convert(jar);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Loads a text (JAR) format language subtag registry file and returns the registry format
|
|
229
|
+
* with field names matching legacy test JSON format ("Suppress-Script", "Preferred-Value")
|
|
230
|
+
* suitable for creating test JSON files that work with JAR converters.
|
|
231
|
+
* @param path - The string path from which the registry is to be loaded.
|
|
232
|
+
* @returns `Success` with the transformed registry format or `Failure` with details if an error occurs.
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export function loadRawSubtagRegistryFileSync(path) {
|
|
236
|
+
return RecordJar.readRecordJarFileSync(path, {
|
|
237
|
+
arrayFields: ['Comments', 'Description', 'Prefix'],
|
|
238
|
+
fixedContinuationSize: 1
|
|
239
|
+
}).onSuccess((jar) => {
|
|
240
|
+
return datedRegistryFromJarRecords(jarRegistryEntry).convert(jar);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Converts array subtags back to range string format for JAR intermediate compatibility
|
|
245
|
+
* @param entry - Registry entry to process
|
|
246
|
+
* @returns Entry with array subtags converted to range strings
|
|
247
|
+
* @internal
|
|
248
|
+
*/
|
|
249
|
+
function formatRangesForJarOutput(entry) {
|
|
250
|
+
// Convert 2-element arrays back to range strings (e.g., ["qaa", "qtz"] -> "qaa..qtz")
|
|
251
|
+
// Applies to entries with Subtag field (language, extlang, script, region, variant)
|
|
252
|
+
// This preserves the JAR format where ranges are represented as strings, not arrays
|
|
253
|
+
if ('Subtag' in entry && Array.isArray(entry.Subtag) && entry.Subtag.length === 2) {
|
|
254
|
+
const result = Object.assign({}, entry);
|
|
255
|
+
// TypeScript doesn't understand that we're converting back to the original format,
|
|
256
|
+
// so we need to use a type assertion here. The JAR format accepts both string and array
|
|
257
|
+
// but we're converting arrays back to string ranges for consistency with the original format.
|
|
258
|
+
// since this is a union type there's no easy way to know exactly which of the possible
|
|
259
|
+
// types is being used, so we need to use a type assertion here.
|
|
260
|
+
const subtagRange = entry.Subtag.join('..');
|
|
261
|
+
result.Subtag = subtagRange;
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
return entry;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Parses a text (JAR) format language subtag registry from string content and returns the registry format
|
|
268
|
+
* with field names matching legacy test JSON format ("Suppress-Script", "Preferred-Value").
|
|
269
|
+
* @param content - The string content of the registry file to be parsed.
|
|
270
|
+
* @returns `Success` with the transformed registry format or `Failure` with details if an error occurs.
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export function loadRawSubtagRegistryFromString(content) {
|
|
274
|
+
const lines = content.split(/\r?\n/);
|
|
275
|
+
return RecordJar.parseRecordJarLines(lines, {
|
|
276
|
+
arrayFields: ['Comments', 'Description', 'Prefix'],
|
|
277
|
+
fixedContinuationSize: 1
|
|
278
|
+
})
|
|
279
|
+
.onSuccess((jar) => {
|
|
280
|
+
return datedRegistryFromJarRecords(jarRegistryEntry).convert(jar);
|
|
281
|
+
})
|
|
282
|
+
.onSuccess((registry) => {
|
|
283
|
+
// Convert array subtags back to range strings for JAR intermediate format compatibility
|
|
284
|
+
const formattedEntries = registry.entries.map(formatRangesForJarOutput);
|
|
285
|
+
return succeed(Object.assign(Object.assign({}, registry), { entries: formattedEntries }));
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=jarConverters.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=model.js.map
|