@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.
Files changed (103) hide show
  1. package/dist/data/bcp/overrides.json +21 -0
  2. package/dist/data/unsd/m49.json +3723 -0
  3. package/dist/index.browser.js +30 -0
  4. package/dist/index.js +28 -0
  5. package/dist/packlets/bcp47/bcp47Subtags/converters.js +32 -0
  6. package/dist/packlets/bcp47/bcp47Subtags/index.js +26 -0
  7. package/dist/packlets/bcp47/bcp47Subtags/model.js +23 -0
  8. package/dist/packlets/bcp47/bcp47Subtags/validate.js +48 -0
  9. package/dist/packlets/bcp47/common.js +53 -0
  10. package/dist/packlets/bcp47/helpers.js +96 -0
  11. package/dist/packlets/bcp47/index.js +32 -0
  12. package/dist/packlets/bcp47/languageRegistryData.js +202 -0
  13. package/dist/packlets/bcp47/languageTag.js +363 -0
  14. package/dist/packlets/bcp47/languageTagParser.js +275 -0
  15. package/dist/packlets/bcp47/match/chooser.js +88 -0
  16. package/dist/packlets/bcp47/match/common.js +49 -0
  17. package/dist/packlets/bcp47/match/index.js +26 -0
  18. package/dist/packlets/bcp47/match/similarity.js +205 -0
  19. package/dist/packlets/bcp47/normalization/baseNormalizer.js +89 -0
  20. package/dist/packlets/bcp47/normalization/canonicalNormalizer.js +86 -0
  21. package/dist/packlets/bcp47/normalization/common.js +77 -0
  22. package/dist/packlets/bcp47/normalization/index.js +27 -0
  23. package/dist/packlets/bcp47/normalization/normalizeTag.js +101 -0
  24. package/dist/packlets/bcp47/normalization/preferredTagNormalizer.js +177 -0
  25. package/dist/packlets/bcp47/overrides/converters.js +49 -0
  26. package/dist/packlets/bcp47/overrides/defaultRegistries.js +38 -0
  27. package/dist/packlets/bcp47/overrides/index.js +25 -0
  28. package/dist/packlets/bcp47/overrides/model.js +23 -0
  29. package/dist/packlets/bcp47/overrides/overridesRegistry.js +83 -0
  30. package/dist/packlets/bcp47/validation/baseValidator.js +86 -0
  31. package/dist/packlets/bcp47/validation/common.js +77 -0
  32. package/dist/packlets/bcp47/validation/index.js +29 -0
  33. package/dist/packlets/bcp47/validation/isCanonical.js +79 -0
  34. package/dist/packlets/bcp47/validation/isInPreferredForm.js +46 -0
  35. package/dist/packlets/bcp47/validation/isStrictlyValid.js +94 -0
  36. package/dist/packlets/bcp47/validation/isValid.js +92 -0
  37. package/dist/packlets/bcp47/validation/isWellFormed.js +75 -0
  38. package/dist/packlets/bcp47/validation/validateTag.js +153 -0
  39. package/dist/packlets/iana/common/converters.js +58 -0
  40. package/dist/packlets/iana/common/model.js +23 -0
  41. package/dist/packlets/iana/common/registeredItems.js +120 -0
  42. package/dist/packlets/iana/common/utils.js +30 -0
  43. package/dist/packlets/iana/common/validate.js +59 -0
  44. package/dist/packlets/iana/converters.js +25 -0
  45. package/dist/packlets/iana/defaultRegistries.js +38 -0
  46. package/dist/packlets/iana/iana-data-embedded.js +60 -0
  47. package/dist/packlets/iana/index.browser.js +34 -0
  48. package/dist/packlets/iana/index.js +34 -0
  49. package/dist/packlets/iana/jar/converters.js +25 -0
  50. package/dist/packlets/iana/jar/index.js +26 -0
  51. package/dist/packlets/iana/jar/jarConverters.js +60 -0
  52. package/dist/packlets/iana/jar/jarModel.js +23 -0
  53. package/dist/packlets/iana/jar/language-subtags/converters.js +25 -0
  54. package/dist/packlets/iana/jar/language-subtags/index.js +26 -0
  55. package/dist/packlets/iana/jar/language-subtags/model.js +25 -0
  56. package/dist/packlets/iana/jar/language-subtags/registry/converters.js +180 -0
  57. package/dist/packlets/iana/jar/language-subtags/registry/index.js +26 -0
  58. package/dist/packlets/iana/jar/language-subtags/registry/model.js +43 -0
  59. package/dist/packlets/iana/jar/language-subtags/tags/converters.js +101 -0
  60. package/dist/packlets/iana/jar/language-subtags/tags/index.js +27 -0
  61. package/dist/packlets/iana/jar/language-subtags/tags/model.js +23 -0
  62. package/dist/packlets/iana/jar/language-subtags/tags/tagValidation.js +66 -0
  63. package/dist/packlets/iana/jar/language-subtags/tags/validate.js +85 -0
  64. package/dist/packlets/iana/jar/model.js +25 -0
  65. package/dist/packlets/iana/language-subtags/common.js +23 -0
  66. package/dist/packlets/iana/language-subtags/converters.js +182 -0
  67. package/dist/packlets/iana/language-subtags/index.browser.js +30 -0
  68. package/dist/packlets/iana/language-subtags/index.js +29 -0
  69. package/dist/packlets/iana/language-subtags/jarConverters.js +288 -0
  70. package/dist/packlets/iana/language-subtags/model.js +23 -0
  71. package/dist/packlets/iana/language-subtags/scope.js +169 -0
  72. package/dist/packlets/iana/language-subtags/subtagRegistry.js +108 -0
  73. package/dist/packlets/iana/language-subtags/validate.js +23 -0
  74. package/dist/packlets/iana/language-tag-extensions/converters.js +59 -0
  75. package/dist/packlets/iana/language-tag-extensions/extensionsRegistry.js +64 -0
  76. package/dist/packlets/iana/language-tag-extensions/extensionsScope.js +50 -0
  77. package/dist/packlets/iana/language-tag-extensions/index.js +28 -0
  78. package/dist/packlets/iana/language-tag-extensions/jarConverters.js +143 -0
  79. package/dist/packlets/iana/language-tag-extensions/model.js +24 -0
  80. package/dist/packlets/iana/language-tag-extensions/validate.js +33 -0
  81. package/dist/packlets/iana/languageRegistries.js +80 -0
  82. package/dist/packlets/iana/languageRegistriesFileLoader.js +73 -0
  83. package/dist/packlets/iana/languageRegistriesLoader.js +113 -0
  84. package/dist/packlets/iana/model.js +25 -0
  85. package/dist/packlets/iana/validate.js +23 -0
  86. package/dist/packlets/unsd/areas.js +92 -0
  87. package/dist/packlets/unsd/common.js +23 -0
  88. package/dist/packlets/unsd/csv/converters.js +75 -0
  89. package/dist/packlets/unsd/csv/index.js +25 -0
  90. package/dist/packlets/unsd/csv/model.js +23 -0
  91. package/dist/packlets/unsd/defaultRegistries.js +38 -0
  92. package/dist/packlets/unsd/index.js +27 -0
  93. package/dist/packlets/unsd/regionCodes.js +115 -0
  94. package/dist/packlets/unsd/regions.js +71 -0
  95. package/dist/packlets/utils/index.js +24 -0
  96. package/dist/packlets/utils/jsonHelpers.js +25 -0
  97. package/dist/packlets/utils/public.js +24 -0
  98. package/dist/packlets/utils/validationHelpers.js +116 -0
  99. package/dist/test/unit/bcp47/commonTestCases.js +475 -0
  100. package/dist/test/unit/bcp47/languageTagHelpers.js +178 -0
  101. package/dist/test/unit/iana/testConstants.js +68 -0
  102. package/dist/tsdoc-metadata.json +1 -1
  103. package/package.json +36 -31
@@ -0,0 +1,169 @@
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 { allSucceed, fail, succeed } from '@fgv/ts-utils';
23
+ import { sanitizeJson } from '../../utils';
24
+ import { Validators } from '../jar/language-subtags/tags';
25
+ import { RegisteredItemScope } from '../common/registeredItems';
26
+ /**
27
+ * @internal
28
+ */
29
+ class SubtagScope extends RegisteredItemScope {
30
+ constructor(type, validate) {
31
+ super(type, validate);
32
+ }
33
+ add(entry) {
34
+ return this._validateEntry(entry).onSuccess(() => {
35
+ this._items.set(entry.subtag, entry);
36
+ return succeed(true);
37
+ });
38
+ }
39
+ _validateEntry(entry) {
40
+ return this._validateKey(entry.subtag);
41
+ }
42
+ }
43
+ /**
44
+ * @internal
45
+ */
46
+ class SubtagScopeWithRange extends SubtagScope {
47
+ constructor(type, validate) {
48
+ super(type, validate);
49
+ }
50
+ add(entry) {
51
+ return this._validateEntry(entry).onSuccess(() => {
52
+ return this._addRange(entry);
53
+ });
54
+ }
55
+ _validateEntry(entry) {
56
+ var _a;
57
+ const start = entry.subtag;
58
+ const end = (_a = entry.subtagRangeEnd) !== null && _a !== void 0 ? _a : '';
59
+ if (end) {
60
+ return allSucceed([this._validateKey(start), this._validateKey(end), this._validateRange(start, end)], true);
61
+ }
62
+ return this._validateKey(start);
63
+ }
64
+ _validateRange(start, end) {
65
+ return start < end ? succeed(true) : fail(`${start}..${end}: invalid range`);
66
+ }
67
+ _addRange(entry) {
68
+ this._items.set(entry.subtag, entry);
69
+ if (entry.subtagRangeEnd) {
70
+ let next = this._nextInRange(entry.subtag, entry.subtagRangeEnd);
71
+ while (next) {
72
+ const e = sanitizeJson(Object.assign(Object.assign({}, entry), { subtag: next, subtagRangeEnd: undefined }));
73
+ this._items.set(next, e);
74
+ next = this._nextInRange(next, entry.subtagRangeEnd);
75
+ }
76
+ }
77
+ return succeed(true);
78
+ }
79
+ _nextInRange(current, end) {
80
+ if (current >= end) {
81
+ return undefined;
82
+ }
83
+ const next = Array.from(current);
84
+ for (let i = next.length - 1; i >= 0; i--) {
85
+ if (next[i].toLowerCase() < 'z') {
86
+ next[i] = String.fromCharCode(next[i].charCodeAt(0) + 1);
87
+ break;
88
+ }
89
+ else {
90
+ next[i] = 'a';
91
+ }
92
+ }
93
+ return this._validate.toCanonical(next.join('')).getValueOrThrow();
94
+ }
95
+ }
96
+ /**
97
+ * @internal
98
+ */
99
+ class TagScope extends RegisteredItemScope {
100
+ constructor(type, validate) {
101
+ super(type, validate);
102
+ }
103
+ add(entry) {
104
+ return this._validateEntry(entry).onSuccess(() => {
105
+ this._items.set(entry.tag, entry);
106
+ return succeed(true);
107
+ });
108
+ }
109
+ _validateEntry(entry) {
110
+ return this._validateKey(entry.tag);
111
+ }
112
+ }
113
+ /**
114
+ * @public
115
+ */
116
+ export class LanguageSubtagScope extends SubtagScopeWithRange {
117
+ constructor() {
118
+ super('language', Validators.languageSubtag);
119
+ }
120
+ }
121
+ /**
122
+ * @public
123
+ */
124
+ export class ExtLangSubtagScope extends SubtagScope {
125
+ constructor() {
126
+ super('extlang', Validators.extlangSubtag);
127
+ }
128
+ }
129
+ /**
130
+ * @public
131
+ */
132
+ export class ScriptSubtagScope extends SubtagScopeWithRange {
133
+ constructor() {
134
+ super('script', Validators.scriptSubtag);
135
+ }
136
+ }
137
+ /**
138
+ * @public
139
+ */
140
+ export class RegionSubtagScope extends SubtagScopeWithRange {
141
+ constructor() {
142
+ super('region', Validators.regionSubtag);
143
+ }
144
+ }
145
+ /**
146
+ * @public
147
+ */
148
+ export class VariantSubtagScope extends SubtagScope {
149
+ constructor() {
150
+ super('variant', Validators.variantSubtag);
151
+ }
152
+ }
153
+ /**
154
+ * @public
155
+ */
156
+ export class GrandfatheredTagScope extends TagScope {
157
+ constructor() {
158
+ super('grandfathered', Validators.grandfatheredTag);
159
+ }
160
+ }
161
+ /**
162
+ * @public
163
+ */
164
+ export class RedundantTagScope extends TagScope {
165
+ constructor() {
166
+ super('redundant', Validators.redundantTag);
167
+ }
168
+ }
169
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1,108 @@
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 Scope from './scope';
25
+ import { captureResult } from '@fgv/ts-utils';
26
+ import { getIanaDataBuffer } from '../iana-data-embedded';
27
+ import { loadLanguageRegistriesFromZipBuffer } from '../languageRegistriesLoader';
28
+ /**
29
+ * @public
30
+ */
31
+ export class LanguageSubtagRegistry {
32
+ /**
33
+ * @param registry - The contents of the registry file
34
+ * from which the data is loaded.
35
+ * @internal
36
+ */
37
+ constructor(registry) {
38
+ this.languages = new Scope.LanguageSubtagScope();
39
+ this.extlangs = new Scope.ExtLangSubtagScope();
40
+ this.scripts = new Scope.ScriptSubtagScope();
41
+ this.regions = new Scope.RegionSubtagScope();
42
+ this.variants = new Scope.VariantSubtagScope();
43
+ this.collections = new Scope.LanguageSubtagScope();
44
+ this.macrolanguages = new Scope.LanguageSubtagScope();
45
+ this.privateUse = new Scope.LanguageSubtagScope();
46
+ this.special = new Scope.LanguageSubtagScope();
47
+ this.grandfathered = new Scope.GrandfatheredTagScope();
48
+ this.redundant = new Scope.RedundantTagScope();
49
+ this.fileDate = registry.fileDate;
50
+ this._all = registry.entries;
51
+ for (const entry of this._all) {
52
+ switch (entry.type) {
53
+ case 'language':
54
+ this.languages.add(entry);
55
+ if (entry.scope === 'macrolanguage') {
56
+ this.macrolanguages.add(entry);
57
+ }
58
+ else if (entry.scope === 'collection') {
59
+ this.collections.add(entry);
60
+ }
61
+ else if (entry.scope === 'private-use') {
62
+ this.privateUse.add(entry);
63
+ }
64
+ else if (entry.scope === 'special') {
65
+ this.special.add(entry);
66
+ }
67
+ break;
68
+ case 'extlang':
69
+ this.extlangs.add(entry);
70
+ break;
71
+ case 'script':
72
+ this.scripts.add(entry);
73
+ break;
74
+ case 'region':
75
+ this.regions.add(entry);
76
+ break;
77
+ case 'variant':
78
+ this.variants.add(entry);
79
+ break;
80
+ case 'grandfathered':
81
+ this.grandfathered.add(entry);
82
+ break;
83
+ case 'redundant':
84
+ this.redundant.add(entry);
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ static create(registry) {
90
+ return captureResult(() => {
91
+ return new LanguageSubtagRegistry(registry);
92
+ });
93
+ }
94
+ static createFromJson(from) {
95
+ return Converters.registryFile.convert(from).onSuccess(LanguageSubtagRegistry.create);
96
+ }
97
+ static loadDefault() {
98
+ return captureResult(() => {
99
+ const zipBuffer = getIanaDataBuffer();
100
+ const registries = loadLanguageRegistriesFromZipBuffer(zipBuffer).orThrow();
101
+ return registries.subtags;
102
+ });
103
+ }
104
+ static createFromTxtContent(content) {
105
+ return JarConverters.loadTxtSubtagRegistryFromString(content).onSuccess(LanguageSubtagRegistry.create);
106
+ }
107
+ }
108
+ //# sourceMappingURL=subtagRegistry.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 * from '../jar/language-subtags/tags/validate';
23
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,59 @@
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 Validate from './validate';
23
+ import { JsonFile } from '@fgv/ts-json-base';
24
+ import { Converters } from '@fgv/ts-utils';
25
+ import { datedRegistry, yearMonthDaySpec } from '../common/converters';
26
+ /**
27
+ * @public
28
+ */
29
+ export const extensionSingleton = Validate.extensionSingleton.converter;
30
+ /**
31
+ * @internal
32
+ */
33
+ export const languageTagExtension = Converters.strictObject({
34
+ identifier: extensionSingleton,
35
+ description: Converters.stringArray,
36
+ comments: Converters.stringArray,
37
+ added: yearMonthDaySpec,
38
+ rfc: Converters.string,
39
+ authority: Converters.string,
40
+ contactEmail: Converters.string,
41
+ mailingList: Converters.string,
42
+ url: Converters.string
43
+ }, {
44
+ description: 'registered language tag extension'
45
+ });
46
+ /**
47
+ * @internal
48
+ */
49
+ export const languageTagExtensions = datedRegistry(languageTagExtension);
50
+ /**
51
+ * @internal
52
+ * @param path - path from which the extensions registry is to be loaded.
53
+ * @returns `Success` with the loaded language tag extensions data, o
54
+ * or `Failure` with details if an error occurs.
55
+ */
56
+ export function loadLanguageTagExtensionsJsonFileSync(path) {
57
+ return JsonFile.convertJsonFileSync(path, languageTagExtensions);
58
+ }
59
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1,64 @@
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 { captureResult } from '@fgv/ts-utils';
25
+ import { getIanaDataBuffer } from '../iana-data-embedded';
26
+ import { loadLanguageRegistriesFromZipBuffer } from '../languageRegistriesLoader';
27
+ import { TagExtensionsScope } from './extensionsScope';
28
+ /**
29
+ * @public
30
+ */
31
+ export class LanguageTagExtensionRegistry {
32
+ /**
33
+ * Constructs an {@link Iana.LanguageTagExtensions.LanguageTagExtensionRegistry}.
34
+ * @param registry - Registry file from which the registry is to be constructed.
35
+ * @internal
36
+ */
37
+ constructor(registry) {
38
+ this.extensions = new TagExtensionsScope();
39
+ this.fileDate = registry.fileDate;
40
+ this._all = registry.entries;
41
+ for (const entry of this._all) {
42
+ this.extensions.add(entry).orThrow();
43
+ }
44
+ }
45
+ static create(registry) {
46
+ return captureResult(() => {
47
+ return new LanguageTagExtensionRegistry(registry);
48
+ });
49
+ }
50
+ static createFromJson(from) {
51
+ return Converters.languageTagExtensions.convert(from).onSuccess(LanguageTagExtensionRegistry.create);
52
+ }
53
+ static loadDefault() {
54
+ return captureResult(() => {
55
+ const zipBuffer = getIanaDataBuffer();
56
+ const registries = loadLanguageRegistriesFromZipBuffer(zipBuffer).orThrow();
57
+ return registries.extensions;
58
+ });
59
+ }
60
+ static createFromTxtContent(content) {
61
+ return JarConverters.loadTxtLanguageTagExtensionsRegistryFromString(content).onSuccess(LanguageTagExtensionRegistry.create);
62
+ }
63
+ }
64
+ //# sourceMappingURL=extensionsRegistry.js.map
@@ -0,0 +1,50 @@
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 Validate from './validate';
23
+ import { succeed } from '@fgv/ts-utils';
24
+ import { RegisteredItemScope } from '../common/registeredItems';
25
+ /**
26
+ * @public
27
+ */
28
+ export class TagExtensionsScope extends RegisteredItemScope {
29
+ constructor() {
30
+ super('language-tag-extension', Validate.extensionSingleton);
31
+ }
32
+ add(entry) {
33
+ return this._validateEntry(entry).onSuccess(() => {
34
+ this._items.set(entry.identifier, entry);
35
+ return succeed(true);
36
+ });
37
+ }
38
+ /**
39
+ * Validates a single entry from a language tag extensions data file.
40
+ * @param entry - The language tag extensions registry entry to be
41
+ * validated.
42
+ * @returns `Success` with `true` if the entry is valid, `Failure` with
43
+ * details if an error occurs.
44
+ * @internal
45
+ */
46
+ _validateEntry(entry) {
47
+ return this._validateKey(entry.identifier);
48
+ }
49
+ }
50
+ //# sourceMappingURL=extensionsScope.js.map
@@ -0,0 +1,28 @@
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
+ 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 { LanguageTagExtensionRegistry } from './extensionsRegistry';
27
+ export { Converters, JarConverters, Model, Validate };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,143 @@
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 { RecordJar } from '@fgv/ts-extras';
24
+ import { JsonFile } from '@fgv/ts-json-base';
25
+ import { Converters } from '@fgv/ts-utils';
26
+ import { datedRegistry, yearMonthDaySpec } from '../common/converters';
27
+ import { datedRegistryFromJarRecords } from '../jar/jarConverters';
28
+ import { extensionSingleton } from './validate';
29
+ /**
30
+ * @internal
31
+ */
32
+ export const languageTagExtension = Converters.transformObject({
33
+ identifier: { from: 'Identifier', converter: extensionSingleton.converter },
34
+ description: { from: 'Description', converter: Converters.stringArray },
35
+ comments: { from: 'Comments', converter: Converters.stringArray },
36
+ added: { from: 'Added', converter: yearMonthDaySpec },
37
+ rfc: { from: 'RFC', converter: Converters.string },
38
+ authority: { from: 'Authority', converter: Converters.string },
39
+ contactEmail: { from: 'Contact_Email', converter: Converters.string },
40
+ mailingList: { from: 'Mailing_List', converter: Converters.string },
41
+ url: { from: 'URL', converter: Converters.string }
42
+ }, {
43
+ strict: true,
44
+ description: 'registered language tag extension'
45
+ });
46
+ /**
47
+ * @internal
48
+ */
49
+ export const languageTagExtensions = datedRegistry(languageTagExtension);
50
+ /**
51
+ * Loads language tag extensions registry data from a JSON-formatted file.
52
+ * @param path - String path from which registry data is to be read.
53
+ * @returns `Success` with the loaded language tag extension data
54
+ * or `Failure` with details if an error occurs.
55
+ * @internal
56
+ */
57
+ export function loadJsonLanguageTagExtensionsRegistryFileSync(path) {
58
+ return JsonFile.convertJsonFileSync(path, languageTagExtensions);
59
+ }
60
+ /**
61
+ * Loads language tag extensions registry data from a text (JAR-formatted) file.
62
+ * @param path - String path from which registry data is to be read.
63
+ * @returns `Success` with the loaded language tag extension data
64
+ * or `Failure` with details if an error occurs.
65
+ * @internal
66
+ */
67
+ export function loadTxtLanguageTagExtensionsRegistryFileSync(path) {
68
+ return RecordJar.readRecordJarFileSync(path, {
69
+ arrayFields: ['Comments', 'Description'],
70
+ fixedContinuationSize: 1
71
+ }).onSuccess((jar) => {
72
+ return datedRegistryFromJarRecords(languageTagExtension).convert(jar);
73
+ });
74
+ }
75
+ /**
76
+ * Parses language tag extensions registry data from string content.
77
+ * @param content - The string content of the registry file to be parsed.
78
+ * @returns `Success` with the loaded language tag extension data
79
+ * or `Failure` with details if an error occurs.
80
+ * @public
81
+ */
82
+ export function loadTxtLanguageTagExtensionsRegistryFromString(content) {
83
+ const lines = content.split(/\r?\n/);
84
+ return RecordJar.parseRecordJarLines(lines, {
85
+ arrayFields: ['Comments', 'Description'],
86
+ fixedContinuationSize: 1
87
+ }).onSuccess((jar) => {
88
+ return datedRegistryFromJarRecords(languageTagExtension).convert(jar);
89
+ });
90
+ }
91
+ /**
92
+ * JAR format converter for language tag extension entries (preserves underscored field names)
93
+ * @internal
94
+ */
95
+ const jarLanguageTagExtensionEntry = Converters.transformObject({
96
+ Identifier: { from: 'Identifier', converter: extensionSingleton.converter },
97
+ Description: { from: 'Description', converter: Converters.stringArray },
98
+ Comments: { from: 'Comments', converter: Converters.stringArray },
99
+ Added: { from: 'Added', converter: yearMonthDaySpec },
100
+ RFC: { from: 'RFC', converter: Converters.string },
101
+ Authority: { from: 'Authority', converter: Converters.string },
102
+ /* eslint-disable @typescript-eslint/naming-convention */
103
+ Contact_Email: { from: 'Contact_Email', converter: Converters.string },
104
+ Mailing_List: { from: 'Mailing_List', converter: Converters.string },
105
+ /* eslint-enable @typescript-eslint/naming-convention */
106
+ URL: { from: 'URL', converter: Converters.string }
107
+ }, {
108
+ strict: true,
109
+ description: 'JAR language tag extension entry'
110
+ });
111
+ /**
112
+ * Loads a text (JAR) format language tag extensions registry file and returns the registry format
113
+ * with field names matching legacy test JSON format ("Contact_Email", "Mailing_List") suitable for
114
+ * creating test JSON files that work with JAR converters.
115
+ * @param path - The string path from which the registry is to be loaded.
116
+ * @returns `Success` with the transformed registry format or `Failure` with details if an error occurs.
117
+ * @public
118
+ */
119
+ export function loadRawLanguageTagExtensionsRegistryFileSync(path) {
120
+ return RecordJar.readRecordJarFileSync(path, {
121
+ arrayFields: ['Comments', 'Description'],
122
+ fixedContinuationSize: 1
123
+ }).onSuccess((jar) => {
124
+ return datedRegistryFromJarRecords(jarLanguageTagExtensionEntry).convert(jar);
125
+ });
126
+ }
127
+ /**
128
+ * Parses a text (JAR) format language tag extensions registry from string content and returns the registry format
129
+ * with field names matching legacy test JSON format ("Contact_Email", "Mailing_List").
130
+ * @param content - The string content of the registry file to be parsed.
131
+ * @returns `Success` with the transformed registry format or `Failure` with details if an error occurs.
132
+ * @public
133
+ */
134
+ export function loadRawLanguageTagExtensionsRegistryFromString(content) {
135
+ const lines = content.split(/\r?\n/);
136
+ return RecordJar.parseRecordJarLines(lines, {
137
+ arrayFields: ['Comments', 'Description'],
138
+ fixedContinuationSize: 1
139
+ }).onSuccess((jar) => {
140
+ return datedRegistryFromJarRecords(jarLanguageTagExtensionEntry).convert(jar);
141
+ });
142
+ }
143
+ //# sourceMappingURL=jarConverters.js.map
@@ -0,0 +1,24 @@
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 @typescript-eslint/naming-convention */
23
+ export {};
24
+ //# sourceMappingURL=model.js.map