@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.
Files changed (95) hide show
  1. package/package.json +8 -8
  2. package/src/data/bcp/overrides.json +0 -20
  3. package/src/data/iana/language-subtags.json +0 -57439
  4. package/src/data/iana/language-tag-extensions.json +0 -38
  5. package/src/data/unsd/m49.json +0 -3723
  6. package/src/index.ts +0 -29
  7. package/src/packlets/bcp47/bcp47Subtags/converters.ts +0 -33
  8. package/src/packlets/bcp47/bcp47Subtags/index.ts +0 -27
  9. package/src/packlets/bcp47/bcp47Subtags/model.ts +0 -46
  10. package/src/packlets/bcp47/bcp47Subtags/validate.ts +0 -55
  11. package/src/packlets/bcp47/common.ts +0 -85
  12. package/src/packlets/bcp47/helpers.ts +0 -117
  13. package/src/packlets/bcp47/index.ts +0 -38
  14. package/src/packlets/bcp47/languageRegistryData.ts +0 -304
  15. package/src/packlets/bcp47/languageTag.ts +0 -467
  16. package/src/packlets/bcp47/languageTagParser.ts +0 -307
  17. package/src/packlets/bcp47/match/chooser.ts +0 -164
  18. package/src/packlets/bcp47/match/common.ts +0 -57
  19. package/src/packlets/bcp47/match/index.ts +0 -26
  20. package/src/packlets/bcp47/match/similarity.ts +0 -243
  21. package/src/packlets/bcp47/normalization/baseNormalizer.ts +0 -146
  22. package/src/packlets/bcp47/normalization/canonicalNormalizer.ts +0 -102
  23. package/src/packlets/bcp47/normalization/common.ts +0 -84
  24. package/src/packlets/bcp47/normalization/index.ts +0 -27
  25. package/src/packlets/bcp47/normalization/normalizeTag.ts +0 -116
  26. package/src/packlets/bcp47/normalization/preferredTagNormalizer.ts +0 -213
  27. package/src/packlets/bcp47/overrides/converters.ts +0 -58
  28. package/src/packlets/bcp47/overrides/defaultRegistries.ts +0 -40
  29. package/src/packlets/bcp47/overrides/index.ts +0 -25
  30. package/src/packlets/bcp47/overrides/model.ts +0 -33
  31. package/src/packlets/bcp47/overrides/overridesRegistry.ts +0 -104
  32. package/src/packlets/bcp47/validation/baseValidator.ts +0 -132
  33. package/src/packlets/bcp47/validation/common.ts +0 -86
  34. package/src/packlets/bcp47/validation/index.ts +0 -29
  35. package/src/packlets/bcp47/validation/isCanonical.ts +0 -103
  36. package/src/packlets/bcp47/validation/isInPreferredForm.ts +0 -53
  37. package/src/packlets/bcp47/validation/isStrictlyValid.ts +0 -117
  38. package/src/packlets/bcp47/validation/isValid.ts +0 -122
  39. package/src/packlets/bcp47/validation/isWellFormed.ts +0 -102
  40. package/src/packlets/bcp47/validation/validateTag.ts +0 -175
  41. package/src/packlets/iana/common/converters.ts +0 -67
  42. package/src/packlets/iana/common/model.ts +0 -56
  43. package/src/packlets/iana/common/registeredItems.ts +0 -145
  44. package/src/packlets/iana/common/utils.ts +0 -32
  45. package/src/packlets/iana/common/validate.ts +0 -64
  46. package/src/packlets/iana/converters.ts +0 -26
  47. package/src/packlets/iana/defaultRegistries.ts +0 -40
  48. package/src/packlets/iana/index.ts +0 -33
  49. package/src/packlets/iana/jar/converters.ts +0 -26
  50. package/src/packlets/iana/jar/index.ts +0 -27
  51. package/src/packlets/iana/jar/jarConverters.ts +0 -70
  52. package/src/packlets/iana/jar/jarModel.ts +0 -34
  53. package/src/packlets/iana/jar/language-subtags/converters.ts +0 -26
  54. package/src/packlets/iana/jar/language-subtags/index.ts +0 -27
  55. package/src/packlets/iana/jar/language-subtags/model.ts +0 -26
  56. package/src/packlets/iana/jar/language-subtags/registry/converters.ts +0 -40
  57. package/src/packlets/iana/jar/language-subtags/registry/index.ts +0 -26
  58. package/src/packlets/iana/jar/language-subtags/registry/model.ts +0 -171
  59. package/src/packlets/iana/jar/language-subtags/tags/converters.ts +0 -120
  60. package/src/packlets/iana/jar/language-subtags/tags/index.ts +0 -28
  61. package/src/packlets/iana/jar/language-subtags/tags/model.ts +0 -71
  62. package/src/packlets/iana/jar/language-subtags/tags/tagValidation.ts +0 -67
  63. package/src/packlets/iana/jar/language-subtags/tags/validate.ts +0 -106
  64. package/src/packlets/iana/jar/model.ts +0 -26
  65. package/src/packlets/iana/language-subtags/common.ts +0 -46
  66. package/src/packlets/iana/language-subtags/converters.ts +0 -226
  67. package/src/packlets/iana/language-subtags/index.ts +0 -30
  68. package/src/packlets/iana/language-subtags/jarConverters.ts +0 -269
  69. package/src/packlets/iana/language-subtags/model.ts +0 -213
  70. package/src/packlets/iana/language-subtags/scope.ts +0 -222
  71. package/src/packlets/iana/language-subtags/subtagRegistry.ts +0 -136
  72. package/src/packlets/iana/language-subtags/validate.ts +0 -23
  73. package/src/packlets/iana/language-tag-extensions/converters.ts +0 -71
  74. package/src/packlets/iana/language-tag-extensions/extensionsRegistry.ts +0 -92
  75. package/src/packlets/iana/language-tag-extensions/extensionsScope.ts +0 -60
  76. package/src/packlets/iana/language-tag-extensions/index.ts +0 -29
  77. package/src/packlets/iana/language-tag-extensions/jarConverters.ts +0 -91
  78. package/src/packlets/iana/language-tag-extensions/model.ts +0 -67
  79. package/src/packlets/iana/language-tag-extensions/validate.ts +0 -36
  80. package/src/packlets/iana/languageRegistries.ts +0 -57
  81. package/src/packlets/iana/model.ts +0 -26
  82. package/src/packlets/iana/validate.ts +0 -23
  83. package/src/packlets/unsd/areas.ts +0 -105
  84. package/src/packlets/unsd/common.ts +0 -79
  85. package/src/packlets/unsd/csv/converters.ts +0 -82
  86. package/src/packlets/unsd/csv/index.ts +0 -26
  87. package/src/packlets/unsd/csv/model.ts +0 -44
  88. package/src/packlets/unsd/defaultRegistries.ts +0 -40
  89. package/src/packlets/unsd/index.ts +0 -28
  90. package/src/packlets/unsd/regionCodes.ts +0 -144
  91. package/src/packlets/unsd/regions.ts +0 -95
  92. package/src/packlets/utils/index.ts +0 -24
  93. package/src/packlets/utils/jsonHelpers.ts +0 -25
  94. package/src/packlets/utils/public.ts +0 -28
  95. package/src/packlets/utils/validationHelpers.ts +0 -180
package/src/index.ts DELETED
@@ -1,29 +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 Bcp47 from './packlets/bcp47';
24
- import * as Iana from './packlets/iana';
25
- import * as Unsd from './packlets/unsd';
26
- // eslint-disable-next-line @rushstack/packlets/mechanics
27
- import * as Utils from './packlets/utils/public';
28
-
29
- export { Bcp47, Iana, Unsd, Utils };
@@ -1,33 +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
- /* eslint-disable @rushstack/typedef-var */
23
-
24
- import * as Validate from './validate';
25
-
26
- /**
27
- * @internal
28
- */
29
- export const extensionSubtag = Validate.extensionSubtag.converter;
30
- /**
31
- * @internal
32
- */
33
- export const privateUsePrefix = Validate.privateUsePrefix.converter;
@@ -1,27 +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 Converters from './converters';
24
- import * as Model from './model';
25
- import * as Validate from './validate';
26
-
27
- export { Converters, Model, Validate };
@@ -1,46 +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 { Brand } from '@fgv/ts-utils';
24
-
25
- /**
26
- * @public
27
- */
28
- export type ExtensionSubtag = Brand<string, 'ExtensionSubtag'>;
29
-
30
- /**
31
- * @internal
32
- */
33
- export type PrivateUseSubtag = Brand<string, 'PrivateUseSubtag'>;
34
-
35
- /**
36
- * @internal
37
- */
38
- export type PrivateUsePrefix = Brand<string, 'PrivateUsePrefix'>;
39
-
40
- import * as Iana from '../../iana';
41
-
42
- /**
43
- * @public
44
- */
45
- type ExtensionSingleton = Iana.LanguageTagExtensions.Model.ExtensionSingleton;
46
- export { ExtensionSingleton };
@@ -1,55 +0,0 @@
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
-
24
- import * as Iana from '../../iana';
25
- import * as Subtags from './model';
26
-
27
- import { RegExpValidationHelpers } from '../../utils';
28
-
29
- import { succeed } from '@fgv/ts-utils';
30
-
31
- /**
32
- * @public
33
- */
34
- export const extensionSingleton = Iana.LanguageTagExtensions.Validate.extensionSingleton;
35
-
36
- /**
37
- * @public
38
- */
39
- export const extensionSubtag = new RegExpValidationHelpers<Subtags.ExtensionSubtag>({
40
- description: 'language tag extension subtag',
41
- wellFormed: /^([a-zA-Z0-9]{2,8})(-[a-zA-Z0-9]{2,8})*$/,
42
- canonical: /^([a-z0-9]{2,8})(-[a-z0-9]{2,8})*$/,
43
- toCanonical: (from: Subtags.ExtensionSubtag) =>
44
- Iana.Jar.LanguageSubtags.Tags.Helpers.TagValidationHelpers.toCanonicalTag(from)
45
- });
46
-
47
- /**
48
- * @public
49
- */
50
- export const privateUsePrefix = new RegExpValidationHelpers<Subtags.PrivateUsePrefix>({
51
- description: 'language tag private-use prefix',
52
- wellFormed: /^[xX]$/,
53
- canonical: /^x$/,
54
- toCanonical: (from: Subtags.PrivateUsePrefix) => succeed(from.toLowerCase() as Subtags.PrivateUsePrefix)
55
- });
@@ -1,85 +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 { ExtensionSingleton, ExtensionSubtag } from './bcp47Subtags/model';
26
- export { ExtensionSingleton, ExtensionSubtag };
27
-
28
- /**
29
- * @public
30
- */
31
- export interface IExtensionSubtagValue {
32
- readonly singleton: ExtensionSingleton;
33
- readonly value: ExtensionSubtag;
34
- }
35
-
36
- /**
37
- * @public
38
- */
39
- export interface ISubtags {
40
- primaryLanguage?: Iana.LanguageSubtags.LanguageSubtag;
41
- extlangs?: Iana.LanguageSubtags.ExtLangSubtag[];
42
- script?: Iana.LanguageSubtags.ScriptSubtag;
43
- region?: Iana.LanguageSubtags.RegionSubtag;
44
- variants?: Iana.LanguageSubtags.VariantSubtag[];
45
- extensions?: IExtensionSubtagValue[];
46
- privateUse?: Iana.LanguageSubtags.ExtendedLanguageRange[];
47
-
48
- grandfathered?: Iana.LanguageSubtags.GrandfatheredTag;
49
- }
50
-
51
- /**
52
- * Converts {@link Bcp47.Subtags | subtags} to a string.
53
- * @param subtags - The {@link Bcp47.Subtags | subtags} to be converted.
54
- * @returns A string representing the supplied {@link Bcp47.Subtags | subtags}.
55
- * @public
56
- */
57
- export function subtagsToString(subtags: ISubtags): string {
58
- if (subtags.grandfathered) {
59
- return subtags.grandfathered;
60
- }
61
- return [
62
- subtags.primaryLanguage,
63
- ...(subtags.extlangs ?? []),
64
- subtags.script,
65
- subtags.region,
66
- ...(subtags.variants ?? []),
67
- ...(subtags.extensions ?? []).map((e) => `${e.singleton}-${e.value}`),
68
- ...(subtags.privateUse && subtags.privateUse.length > 0 ? [`x-${subtags.privateUse.join('-')}`] : [])
69
- ]
70
- .filter((s): s is string => s !== undefined)
71
- .join('-');
72
- }
73
-
74
- /**
75
- * @public
76
- */
77
- // eslint-disable-next-line @typescript-eslint/naming-convention
78
- export const UndeterminedLanguage: Iana.LanguageSubtags.LanguageSubtag =
79
- 'und' as Iana.LanguageSubtags.LanguageSubtag;
80
-
81
- /**
82
- * @public
83
- */
84
- // eslint-disable-next-line @typescript-eslint/naming-convention
85
- export const GlobalRegion: Iana.LanguageSubtags.RegionSubtag = '001' as Iana.LanguageSubtags.RegionSubtag;
@@ -1,117 +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 { Result, mapResults, succeed } from '@fgv/ts-utils';
24
- import { ISubtags } from './common';
25
- import { ILanguageTagInitOptions, LanguageTag } from './languageTag';
26
- import { LanguageSimilarityMatcher } from './match';
27
- import { ILanguageChooserOptions, LanguageChooser } from './match/chooser';
28
-
29
- /**
30
- * Any of the possible ways to represent a language - as a `string`,
31
- * parsed {@link Bcp47.Subtags | subtags} or an instantiated
32
- * {@link Bcp47.LanguageTag | language tag}.
33
- * @public
34
- */
35
- export type LanguageSpec = string | ISubtags | LanguageTag;
36
-
37
- /**
38
- * Creates a new {@link Bcp47.LanguageTag | language tag} from a {@link Bcp47.LanguageSpec | language specifier}
39
- *
40
- * The supplied initializer must be at least
41
- * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | well-formed according to RFC 5646}.
42
- * Higher degrees of validation along with any normalizations may be optionally specified.
43
- *
44
- * @param from - The {@link Bcp47.LanguageSpec | language specifier} from which the tag is to
45
- * be created.
46
- * @param options - (optional) The {@link Bcp47.ILanguageTagInitOptions | options} used to construct
47
- * and validate the tag.
48
- * @returns `Success` with a valid {@link Bcp47.LanguageTag | language tag} or `Failure` with details
49
- * if an error occurs.
50
- * @public
51
- */
52
- /* c8 ignore next 3 - tests applied for wrapped function */
53
- export function tag(from: LanguageSpec, options?: ILanguageTagInitOptions): Result<LanguageTag> {
54
- return from instanceof LanguageTag ? succeed(from) : LanguageTag.create(from, options);
55
- }
56
-
57
- /**
58
- * Creates an array of {@link Bcp47.LanguageTag | language tags} from an incoming array of
59
- * {@link Bcp47.LanguageSpec | language specifiers}.
60
- * @param from - The array of {@link Bcp47.LanguageSpec} to be converted.
61
- * @param options - (optional) The {@link Bcp47.ILanguageTagInitOptions | options} used to construct
62
- * and validate any created tags.
63
- * @returns `Success` with an array of {@link Bcp47.LanguageTag | language tags}, or `Failure`
64
- * with details if an error occurs.
65
- * @public
66
- */
67
- export function tags(from: LanguageSpec[], options?: ILanguageTagInitOptions): Result<LanguageTag[]> {
68
- return mapResults(from.map((f) => tag(f, options)));
69
- }
70
-
71
- /**
72
- * Determine how similar two language tags are to each other.
73
- *
74
- * @param t1 - First tag to match, supplied as one of `string`, individual
75
- * {@link Bcp47.Subtags | subtags}, or constructed
76
- * {@link Bcp47.LanguageTag | language tag}.
77
- * @param t2 - Second tag to match, supplied as one of `string`, individual
78
- * {@link Bcp47.Subtags | subtags}, or constructed
79
- * {@link Bcp47.LanguageTag | language tag}.
80
- * @param options - (optional) A set of {@link Bcp47.ILanguageTagInitOptions | language tag options}
81
- * which control any necessary conversion or parsing.
82
- * @returns A numeric value in the range 1.0 (exact match) to 0.0 (no match).
83
- * @see For a set of common levels of similarity, see {@link Bcp47.tagSimilarity | similarity}.
84
- * @public
85
- */
86
- /* c8 ignore next - tests applied for wrapped function */
87
- export function similarity(
88
- t1: LanguageSpec,
89
- t2: LanguageSpec,
90
- options?: ILanguageTagInitOptions
91
- ): Result<number> {
92
- return tags([t1, t2], options).onSuccess((tags) => {
93
- return succeed(new LanguageSimilarityMatcher().matchLanguageTags(tags[0], tags[1]));
94
- });
95
- }
96
-
97
- /**
98
- * Matches a list of desired {@link Bcp47.LanguageSpec | languages} to a list of available {@link Bcp47.LanguageSpec | languages},
99
- * return a list of matching languages ordered from best to worst.
100
- * @param desired - An array of {@link Bcp47.LanguageSpec | language specifications} containing an ordered list of preferred languages.
101
- * @param available - An array of {@link Bcp47.LanguageSpec | language specifications} containing an unordered list of available languages.
102
- * @param options - (optional) Parameters to control language tag conversion or comparison
103
- * @returns `Success` with an ordered list of matching {@link Bcp47.LanguageTag | languages}, or `Failure` with details if
104
- * an error occurs.
105
- * @public
106
- */
107
- export function choose(
108
- desired: LanguageSpec[],
109
- available: LanguageSpec[],
110
- options?: ILanguageTagInitOptions & ILanguageChooserOptions
111
- ): Result<LanguageTag[]> {
112
- return tags(desired, options).onSuccess((w) => {
113
- return tags(available, options).onSuccess((h) => {
114
- return succeed(new LanguageChooser().filterLanguageTags(w, h, options));
115
- });
116
- });
117
- }
@@ -1,38 +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
- // istanbul ignore file
23
- import * as Subtags from './bcp47Subtags';
24
- import * as Overrides from './overrides';
25
-
26
- export {
27
- ExtensionSingleton,
28
- ExtensionSubtag,
29
- IExtensionSubtagValue,
30
- ISubtags,
31
- subtagsToString
32
- } from './common';
33
- export * from './helpers';
34
- export { ILanguageTagInitOptions, LanguageTag } from './languageTag';
35
- export { ILanguageChooserOptions, LanguageSimilarityMatcher, TagSimilarity, tagSimilarity } from './match';
36
- export { NormalizeTag, TagNormalization } from './normalization';
37
- export { TagValidity, ValidateTag } from './validation';
38
- export { Overrides, Subtags };