@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,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 exports - excludes Node.js filesystem dependencies
|
|
23
|
+
import * as Bcp47 from './packlets/bcp47';
|
|
24
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
25
|
+
import * as Iana from './packlets/iana/index.browser';
|
|
26
|
+
import * as Unsd from './packlets/unsd';
|
|
27
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
28
|
+
import * as Utils from './packlets/utils/public';
|
|
29
|
+
export { Bcp47, Iana, Unsd, Utils };
|
|
30
|
+
//# sourceMappingURL=index.browser.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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 Bcp47 from './packlets/bcp47';
|
|
23
|
+
import * as Iana from './packlets/iana';
|
|
24
|
+
import * as Unsd from './packlets/unsd';
|
|
25
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
26
|
+
import * as Utils from './packlets/utils/public';
|
|
27
|
+
export { Bcp47, Iana, Unsd, Utils };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
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 Validate from './validate';
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const extensionSubtag = Validate.extensionSubtag.converter;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export const privateUsePrefix = Validate.privateUsePrefix.converter;
|
|
32
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
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 Model from './model';
|
|
24
|
+
import * as Validate from './validate';
|
|
25
|
+
export { Converters, Model, Validate };
|
|
26
|
+
//# sourceMappingURL=index.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
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021 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 Iana from '../../iana';
|
|
24
|
+
import { RegExpValidationHelpers } from '../../utils';
|
|
25
|
+
import { succeed } from '@fgv/ts-utils';
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const extensionSingleton = Iana.LanguageTagExtensions.Validate.extensionSingleton;
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export const extensionSubtag = new RegExpValidationHelpers({
|
|
34
|
+
description: 'language tag extension subtag',
|
|
35
|
+
wellFormed: /^([a-zA-Z0-9]{2,8})(-[a-zA-Z0-9]{2,8})*$/,
|
|
36
|
+
canonical: /^([a-z0-9]{2,8})(-[a-z0-9]{2,8})*$/,
|
|
37
|
+
toCanonical: (from) => Iana.Jar.LanguageSubtags.Tags.Helpers.TagValidationHelpers.toCanonicalTag(from)
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const privateUsePrefix = new RegExpValidationHelpers({
|
|
43
|
+
description: 'language tag private-use prefix',
|
|
44
|
+
wellFormed: /^[xX]$/,
|
|
45
|
+
canonical: /^x$/,
|
|
46
|
+
toCanonical: (from) => succeed(from.toLowerCase())
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
* Converts {@link Bcp47.Subtags | subtags} to a string.
|
|
24
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags} to be converted.
|
|
25
|
+
* @returns A string representing the supplied {@link Bcp47.Subtags | subtags}.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export function subtagsToString(subtags) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
if (subtags.grandfathered) {
|
|
31
|
+
return subtags.grandfathered;
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
subtags.primaryLanguage,
|
|
35
|
+
...((_a = subtags.extlangs) !== null && _a !== void 0 ? _a : []),
|
|
36
|
+
subtags.script,
|
|
37
|
+
subtags.region,
|
|
38
|
+
...((_b = subtags.variants) !== null && _b !== void 0 ? _b : []),
|
|
39
|
+
...((_c = subtags.extensions) !== null && _c !== void 0 ? _c : []).map((e) => `${e.singleton}-${e.value}`),
|
|
40
|
+
...(subtags.privateUse && subtags.privateUse.length > 0 ? [`x-${subtags.privateUse.join('-')}`] : [])
|
|
41
|
+
]
|
|
42
|
+
.filter((s) => s !== undefined)
|
|
43
|
+
.join('-');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export const UndeterminedLanguage = 'und';
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export const GlobalRegion = '001';
|
|
53
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
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 { mapResults, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { LanguageTag } from './languageTag';
|
|
24
|
+
import { LanguageSimilarityMatcher } from './match';
|
|
25
|
+
import { LanguageChooser } from './match/chooser';
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new {@link Bcp47.LanguageTag | language tag} from a {@link Bcp47.LanguageSpec | language specifier}
|
|
28
|
+
*
|
|
29
|
+
* The supplied initializer must be at least
|
|
30
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | well-formed according to RFC 5646}.
|
|
31
|
+
* Higher degrees of validation along with any normalizations may be optionally specified.
|
|
32
|
+
*
|
|
33
|
+
* @param from - The {@link Bcp47.LanguageSpec | language specifier} from which the tag is to
|
|
34
|
+
* be created.
|
|
35
|
+
* @param options - (optional) The {@link Bcp47.ILanguageTagInitOptions | options} used to construct
|
|
36
|
+
* and validate the tag.
|
|
37
|
+
* @returns `Success` with a valid {@link Bcp47.LanguageTag | language tag} or `Failure` with details
|
|
38
|
+
* if an error occurs.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
/* c8 ignore next 3 - tests applied for wrapped function */
|
|
42
|
+
export function tag(from, options) {
|
|
43
|
+
return from instanceof LanguageTag ? succeed(from) : LanguageTag.create(from, options);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates an array of {@link Bcp47.LanguageTag | language tags} from an incoming array of
|
|
47
|
+
* {@link Bcp47.LanguageSpec | language specifiers}.
|
|
48
|
+
* @param from - The array of {@link Bcp47.LanguageSpec} to be converted.
|
|
49
|
+
* @param options - (optional) The {@link Bcp47.ILanguageTagInitOptions | options} used to construct
|
|
50
|
+
* and validate any created tags.
|
|
51
|
+
* @returns `Success` with an array of {@link Bcp47.LanguageTag | language tags}, or `Failure`
|
|
52
|
+
* with details if an error occurs.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export function tags(from, options) {
|
|
56
|
+
return mapResults(from.map((f) => tag(f, options)));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Determine how similar two language tags are to each other.
|
|
60
|
+
*
|
|
61
|
+
* @param t1 - First tag to match, supplied as one of `string`, individual
|
|
62
|
+
* {@link Bcp47.Subtags | subtags}, or constructed
|
|
63
|
+
* {@link Bcp47.LanguageTag | language tag}.
|
|
64
|
+
* @param t2 - Second tag to match, supplied as one of `string`, individual
|
|
65
|
+
* {@link Bcp47.Subtags | subtags}, or constructed
|
|
66
|
+
* {@link Bcp47.LanguageTag | language tag}.
|
|
67
|
+
* @param options - (optional) A set of {@link Bcp47.ILanguageTagInitOptions | language tag options}
|
|
68
|
+
* which control any necessary conversion or parsing.
|
|
69
|
+
* @returns A numeric value in the range 1.0 (exact match) to 0.0 (no match).
|
|
70
|
+
* @see For a set of common levels of similarity, see {@link Bcp47.tagSimilarity | similarity}.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
/* c8 ignore next - tests applied for wrapped function */
|
|
74
|
+
export function similarity(t1, t2, options) {
|
|
75
|
+
return tags([t1, t2], options).onSuccess((tags) => {
|
|
76
|
+
return succeed(new LanguageSimilarityMatcher().matchLanguageTags(tags[0], tags[1]));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Matches a list of desired {@link Bcp47.LanguageSpec | languages} to a list of available {@link Bcp47.LanguageSpec | languages},
|
|
81
|
+
* return a list of matching languages ordered from best to worst.
|
|
82
|
+
* @param desired - An array of {@link Bcp47.LanguageSpec | language specifications} containing an ordered list of preferred languages.
|
|
83
|
+
* @param available - An array of {@link Bcp47.LanguageSpec | language specifications} containing an unordered list of available languages.
|
|
84
|
+
* @param options - (optional) Parameters to control language tag conversion or comparison
|
|
85
|
+
* @returns `Success` with an ordered list of matching {@link Bcp47.LanguageTag | languages}, or `Failure` with details if
|
|
86
|
+
* an error occurs.
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export function choose(desired, available, options) {
|
|
90
|
+
return tags(desired, options).onSuccess((w) => {
|
|
91
|
+
return tags(available, options).onSuccess((h) => {
|
|
92
|
+
return succeed(new LanguageChooser().filterLanguageTags(w, h, options));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
// istanbul ignore file
|
|
23
|
+
import * as Subtags from './bcp47Subtags';
|
|
24
|
+
import * as Overrides from './overrides';
|
|
25
|
+
export { subtagsToString } from './common';
|
|
26
|
+
export * from './helpers';
|
|
27
|
+
export { LanguageTag } from './languageTag';
|
|
28
|
+
export { LanguageSimilarityMatcher, tagSimilarity } from './match';
|
|
29
|
+
export { NormalizeTag } from './normalization';
|
|
30
|
+
export { ValidateTag } from './validation';
|
|
31
|
+
export { Overrides, Subtags };
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,202 @@
|
|
|
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 { subtagsToString } from './common';
|
|
23
|
+
/**
|
|
24
|
+
* Returns all of the data in the IANA language subtags registry for
|
|
25
|
+
* a set of supplied {@link Bcp47.Subtags | subtags}.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class LanguageRegistryData {
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
31
|
+
* from a supplied {@link Bcp47.Subtags | subtags} and {@link Iana.LanguageRegistries | language registries}.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
constructor(subtags, iana) {
|
|
35
|
+
this._iana = iana;
|
|
36
|
+
this._subtags = subtags;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Registry data associated with the primary language subtag of the language tag from
|
|
40
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
41
|
+
* was constructed, or `undefined` if the primary language is missing or invalid.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
get primaryLanguage() {
|
|
45
|
+
var _a;
|
|
46
|
+
if (this._primaryLanguage === undefined) {
|
|
47
|
+
this._primaryLanguage = (_a = this._iana.subtags.languages.tryGet(this._subtags.primaryLanguage)) !== null && _a !== void 0 ? _a : false;
|
|
48
|
+
}
|
|
49
|
+
return this._primaryLanguage ? this._primaryLanguage : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Registry data associated with the extlang subtag of the language tag from
|
|
53
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
54
|
+
* was constructed, or `undefined` if extlang is missing or invalid.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
get extlangs() {
|
|
58
|
+
if (this._extlangs === undefined) {
|
|
59
|
+
if (this._subtags.extlangs !== undefined) {
|
|
60
|
+
this._extlangs = this._subtags.extlangs.map((e) => {
|
|
61
|
+
return {
|
|
62
|
+
subtag: e,
|
|
63
|
+
registry: this._iana.subtags.extlangs.tryGet(e)
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!this._subtags.extlangs || this._subtags.extlangs.length === 0) {
|
|
68
|
+
this._extlangs = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this._extlangs ? this._extlangs : undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Registry data associated with the script of the language tag from
|
|
75
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
76
|
+
* was constructed, or `undefined` if the script cannot be determined.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
get script() {
|
|
81
|
+
if (this._script === undefined) {
|
|
82
|
+
if (this._subtags.script) {
|
|
83
|
+
this._script = this._iana.subtags.scripts.tryGet(this._subtags.script);
|
|
84
|
+
}
|
|
85
|
+
if (!this._script) {
|
|
86
|
+
this._script = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return this._script ? this._script : undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Registry data associated with the script of the language tag from
|
|
93
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
94
|
+
* was constructed, or `undefined` if the script cannot be determined.
|
|
95
|
+
*
|
|
96
|
+
* Note that effectiveScript will default to the registry `Suppress-Script` value of the
|
|
97
|
+
* primary language if no script subtag is present.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
get effectiveScript() {
|
|
101
|
+
var _a;
|
|
102
|
+
if (this._effectiveScript === undefined) {
|
|
103
|
+
if (this._subtags.script) {
|
|
104
|
+
this._effectiveScript = this._iana.subtags.scripts.tryGet(this._subtags.script);
|
|
105
|
+
}
|
|
106
|
+
else if (!this._effectiveScript) {
|
|
107
|
+
const suppressed = (_a = this.primaryLanguage) === null || _a === void 0 ? void 0 : _a.suppressScript;
|
|
108
|
+
if (suppressed) {
|
|
109
|
+
this._effectiveScript = this._iana.subtags.scripts.tryGet(suppressed);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!this._effectiveScript) {
|
|
113
|
+
this._effectiveScript = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return this._effectiveScript ? this._effectiveScript : undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Registry data associated with the region subtag of the language tag from
|
|
120
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
121
|
+
* was constructed, or `undefined` if the region is missing or invalid.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
get region() {
|
|
125
|
+
if (this._region === undefined) {
|
|
126
|
+
if (this._subtags.region) {
|
|
127
|
+
this._region = this._iana.subtags.regions.tryGet(this._subtags.region);
|
|
128
|
+
}
|
|
129
|
+
if (!this._region) {
|
|
130
|
+
this._region = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return this._region ? this._region : undefined;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Registry data associated with the variant subtags of the language tag from
|
|
137
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
138
|
+
* was constructed, or `undefined` if variant subtags are missing or invalid.
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
get variants() {
|
|
142
|
+
if (this._variants === undefined) {
|
|
143
|
+
if (this._subtags.variants !== undefined) {
|
|
144
|
+
this._variants = this._subtags.variants.map((v) => {
|
|
145
|
+
return {
|
|
146
|
+
subtag: v,
|
|
147
|
+
registry: this._iana.subtags.variants.tryGet(v)
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (!this._subtags.variants || this._subtags.variants.length === 0) {
|
|
152
|
+
this._variants = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return this._variants ? this._variants : undefined;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Registry data associated with the extension subtags of the language tag from
|
|
159
|
+
* which this {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
160
|
+
* was constructed, or `undefined` if extension subtags are missing or invalid.
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
get extensions() {
|
|
164
|
+
if (this._extensions === undefined) {
|
|
165
|
+
if (this._subtags.extensions !== undefined) {
|
|
166
|
+
this._extensions = this._subtags.extensions.map((e) => {
|
|
167
|
+
return Object.assign(Object.assign({}, e), { registry: this._iana.extensions.extensions.tryGet(e.singleton) });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (!this._subtags.variants || this._subtags.variants.length === 0) {
|
|
171
|
+
this._variants = false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return this._extensions ? this._extensions : undefined;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Registry data for grandfathered tags, or `undefined` if the tag is not recognized
|
|
178
|
+
* as a grandfathered tag.
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
get grandfathered() {
|
|
182
|
+
if (this._grandfathered === undefined) {
|
|
183
|
+
if (this._subtags.grandfathered) {
|
|
184
|
+
this._grandfathered = this._iana.subtags.grandfathered.tryGet(this._subtags.grandfathered);
|
|
185
|
+
}
|
|
186
|
+
if (!this._grandfathered) {
|
|
187
|
+
this._grandfathered = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return this._grandfathered ? this._grandfathered : undefined;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @returns A string representation of the subtags from which this
|
|
194
|
+
* {@link Bcp47.LanguageTagRegistryData | Bcp47.LanguageTagRegistryData}
|
|
195
|
+
* was created.
|
|
196
|
+
* @public
|
|
197
|
+
*/
|
|
198
|
+
toString() {
|
|
199
|
+
return subtagsToString(this._subtags);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=languageRegistryData.js.map
|