@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,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
// istanbul ignore file
|
|
23
|
+
export * from './common';
|
|
24
|
+
export { IsCanonicalValidator } from './isCanonical';
|
|
25
|
+
export { IsStrictlyValidValidator } from './isStrictlyValid';
|
|
26
|
+
export { IsValidValidator } from './isValid';
|
|
27
|
+
export { IsWellFormedValidator } from './isWellFormed';
|
|
28
|
+
export { ValidateTag } from './validateTag';
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
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 Iana from '../../iana';
|
|
23
|
+
import * as Bcp47Subtags from '../bcp47Subtags';
|
|
24
|
+
import { allSucceed, fail, succeed } from '@fgv/ts-utils';
|
|
25
|
+
import { TagValidatorBase } from './baseValidator';
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export class IsCanonicalValidator extends TagValidatorBase {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.validity = 'well-formed';
|
|
33
|
+
}
|
|
34
|
+
_checkLanguage(subtags) {
|
|
35
|
+
if (subtags.primaryLanguage) {
|
|
36
|
+
return this.iana.subtags.languages.verifyIsCanonical(subtags.primaryLanguage);
|
|
37
|
+
}
|
|
38
|
+
return succeed(undefined);
|
|
39
|
+
}
|
|
40
|
+
_checkExtlangs(subtags) {
|
|
41
|
+
if (subtags.extlangs) {
|
|
42
|
+
return allSucceed(subtags.extlangs.map((e) => this.iana.subtags.extlangs.verifyIsCanonical(e)), subtags.extlangs);
|
|
43
|
+
}
|
|
44
|
+
return succeed(undefined);
|
|
45
|
+
}
|
|
46
|
+
_checkScript(subtags) {
|
|
47
|
+
return subtags.script ? this.iana.subtags.scripts.verifyIsCanonical(subtags.script) : succeed(undefined);
|
|
48
|
+
}
|
|
49
|
+
_checkRegion(subtags) {
|
|
50
|
+
return subtags.region ? this.iana.subtags.regions.verifyIsCanonical(subtags.region) : succeed(undefined);
|
|
51
|
+
}
|
|
52
|
+
_checkVariants(subtags) {
|
|
53
|
+
if (subtags.variants) {
|
|
54
|
+
return allSucceed(subtags.variants.map((v) => this.iana.subtags.variants.verifyIsCanonical(v)), subtags.variants);
|
|
55
|
+
}
|
|
56
|
+
return succeed(undefined);
|
|
57
|
+
}
|
|
58
|
+
_checkExtensionSingleton(singleton) {
|
|
59
|
+
return this.iana.extensions.extensions.verifyIsCanonical(singleton);
|
|
60
|
+
}
|
|
61
|
+
_checkExtensionSubtagValue(value) {
|
|
62
|
+
return Bcp47Subtags.Validate.extensionSubtag.verifyIsCanonical(value);
|
|
63
|
+
}
|
|
64
|
+
_checkPrivateUseTags(subtags) {
|
|
65
|
+
if (subtags.privateUse) {
|
|
66
|
+
const result = Iana.LanguageSubtags.Validate.extendedLanguageRange.verifyIsCanonical(subtags.privateUse.join('-'));
|
|
67
|
+
if (result.isFailure()) {
|
|
68
|
+
return fail(result.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return succeed(subtags.privateUse);
|
|
72
|
+
}
|
|
73
|
+
_checkGrandfatheredTags(subtags) {
|
|
74
|
+
return subtags.grandfathered
|
|
75
|
+
? this.iana.subtags.grandfathered.verifyIsCanonical(subtags.grandfathered)
|
|
76
|
+
: succeed(undefined);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=isCanonical.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
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 Iana from '../../iana';
|
|
23
|
+
import { fail, succeed } from '@fgv/ts-utils';
|
|
24
|
+
import { subtagsToString } from '../common';
|
|
25
|
+
import { NormalizeTag } from '../normalization';
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export class IsInPreferredFromValidator {
|
|
30
|
+
constructor(iana) {
|
|
31
|
+
this.validity = 'valid';
|
|
32
|
+
/* c8 ignore next */
|
|
33
|
+
this.iana = iana !== null && iana !== void 0 ? iana : Iana.DefaultRegistries.languageRegistries;
|
|
34
|
+
}
|
|
35
|
+
validateSubtags(subtags) {
|
|
36
|
+
return NormalizeTag.toPreferred(subtags).onSuccess((preferred) => {
|
|
37
|
+
const want = subtagsToString(preferred);
|
|
38
|
+
const have = subtagsToString(subtags);
|
|
39
|
+
if (want !== have) {
|
|
40
|
+
return fail(`${have}: does not match preferred form ${want}`);
|
|
41
|
+
}
|
|
42
|
+
return succeed(true);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=isInPreferredForm.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { fail, mapResults, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { subtagsToString } from '../common';
|
|
24
|
+
import { NormalizeTag } from '../normalization';
|
|
25
|
+
import { IsValidValidator } from './isValid';
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export class IsStrictlyValidValidator extends IsValidValidator {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.validity = 'strictly-valid';
|
|
33
|
+
this.normalization = 'unknown';
|
|
34
|
+
}
|
|
35
|
+
_checkExtlangs(subtags) {
|
|
36
|
+
if (subtags.extlangs) {
|
|
37
|
+
return super._checkExtlangs(subtags).onSuccess(() => this._validateExtlangPrefix(subtags));
|
|
38
|
+
}
|
|
39
|
+
return succeed(undefined);
|
|
40
|
+
}
|
|
41
|
+
_checkVariants(subtags) {
|
|
42
|
+
if (subtags.variants) {
|
|
43
|
+
return super._checkVariants(subtags).onSuccess((v) => this._validateVariantPrefix(subtags, v));
|
|
44
|
+
}
|
|
45
|
+
return succeed(undefined);
|
|
46
|
+
}
|
|
47
|
+
_validateExtlangPrefix(subtags) {
|
|
48
|
+
if (subtags.extlangs) {
|
|
49
|
+
const prefix = this.iana.subtags.languages.toCanonical(subtags.primaryLanguage).orDefault();
|
|
50
|
+
if (!prefix) {
|
|
51
|
+
return fail('missing primary language for extlang prefix validation.');
|
|
52
|
+
}
|
|
53
|
+
return mapResults(subtags.extlangs.map((extlang) => {
|
|
54
|
+
const def = this.iana.subtags.extlangs.tryGet(extlang);
|
|
55
|
+
/* c8 ignore next 3 - should never happen due to guards earlier in conversion */
|
|
56
|
+
if (!def) {
|
|
57
|
+
return fail(`invalid extlang subtag "${extlang}" (not registered).`);
|
|
58
|
+
}
|
|
59
|
+
if (prefix !== def.prefix) {
|
|
60
|
+
return fail(`invalid prefix "${prefix}" for extlang subtag ${extlang} (expected "${def.prefix}").`);
|
|
61
|
+
}
|
|
62
|
+
return succeed(extlang);
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/* c8 ignore next 2 - should be caught in the caller */
|
|
66
|
+
return succeed(undefined);
|
|
67
|
+
}
|
|
68
|
+
_validateVariantPrefix(subtags, variants) {
|
|
69
|
+
const { primaryLanguage, extlangs, script, region } = subtags;
|
|
70
|
+
const nonCanonical = { primaryLanguage, extlangs, script, region };
|
|
71
|
+
const canonical = NormalizeTag.normalizeSubtags(nonCanonical, 'canonical');
|
|
72
|
+
/* c8 ignore next 3 - should be caught in the first pass */
|
|
73
|
+
if (canonical.isFailure()) {
|
|
74
|
+
return fail(`failed to normalize variant prefix: ${canonical.message}`);
|
|
75
|
+
}
|
|
76
|
+
let prefix = subtagsToString(canonical.value);
|
|
77
|
+
return mapResults(variants.map((variant) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const def = this.iana.subtags.variants.tryGet(variant);
|
|
80
|
+
/* c8 ignore next 3 - should be caught in the first pass */
|
|
81
|
+
if (!def) {
|
|
82
|
+
return fail(`invalid variant subtag "${variant}" (not registered).`);
|
|
83
|
+
}
|
|
84
|
+
// only fail if registration specifies prefixes but none are present
|
|
85
|
+
if (((_a = def.prefix) === null || _a === void 0 ? void 0 : _a.includes(prefix)) === false) {
|
|
86
|
+
return fail(`invalid prefix "${prefix}" for variant subtag ${variant} (expected "(${def.prefix.join(', ')})").`);
|
|
87
|
+
}
|
|
88
|
+
const canonicalVariant = this.iana.subtags.variants.toCanonical(variant).orDefault();
|
|
89
|
+
prefix = `${prefix}-${canonicalVariant}`;
|
|
90
|
+
return succeed(variant);
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=isStrictlyValid.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
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 Iana from '../../iana';
|
|
23
|
+
import * as Bcp47Subtags from '../bcp47Subtags';
|
|
24
|
+
import { allSucceed, fail, mapResults, succeed } from '@fgv/ts-utils';
|
|
25
|
+
import { TagValidatorBase } from './baseValidator';
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export class IsValidValidator extends TagValidatorBase {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.validity = 'valid';
|
|
33
|
+
}
|
|
34
|
+
_checkLanguage(subtags) {
|
|
35
|
+
return subtags.primaryLanguage
|
|
36
|
+
? this.iana.subtags.languages.verifyIsValid(subtags.primaryLanguage)
|
|
37
|
+
: succeed(undefined);
|
|
38
|
+
}
|
|
39
|
+
_checkExtlangs(subtags) {
|
|
40
|
+
if (subtags.extlangs) {
|
|
41
|
+
return allSucceed(subtags.extlangs.map((e) => this.iana.subtags.extlangs.verifyIsValid(e)), subtags.extlangs);
|
|
42
|
+
}
|
|
43
|
+
return succeed(undefined);
|
|
44
|
+
}
|
|
45
|
+
_checkScript(subtags) {
|
|
46
|
+
return subtags.script ? this.iana.subtags.scripts.verifyIsValid(subtags.script) : succeed(undefined);
|
|
47
|
+
}
|
|
48
|
+
_checkRegion(subtags) {
|
|
49
|
+
return subtags.region ? this.iana.subtags.regions.verifyIsValid(subtags.region) : succeed(undefined);
|
|
50
|
+
}
|
|
51
|
+
_checkVariants(subtags) {
|
|
52
|
+
if (subtags.variants) {
|
|
53
|
+
return allSucceed(subtags.variants.map((v) => this.iana.subtags.variants.verifyIsValid(v)), subtags.variants).onSuccess((v) => {
|
|
54
|
+
return mapResults(v.map((vc) => this.iana.subtags.variants.toCanonical(vc))).onSuccess((canonical) => {
|
|
55
|
+
return this._verifyUnique('variant subtag', canonical, (v) => v);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return succeed(undefined);
|
|
60
|
+
}
|
|
61
|
+
_checkExtensionSingleton(singleton) {
|
|
62
|
+
return this.iana.extensions.extensions.verifyIsValid(singleton);
|
|
63
|
+
}
|
|
64
|
+
_checkExtensionSubtagValue(value) {
|
|
65
|
+
return Bcp47Subtags.Validate.extensionSubtag.verifyIsWellFormed(value);
|
|
66
|
+
}
|
|
67
|
+
_checkExtensions(subtags) {
|
|
68
|
+
return super._checkExtensions(subtags).onSuccess((extensions) => {
|
|
69
|
+
return this._verifyUnique('extensions', extensions, (e) => e.singleton.toLowerCase());
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
_checkPrivateUseTags(subtags) {
|
|
73
|
+
if (subtags.privateUse) {
|
|
74
|
+
return allSucceed(subtags.privateUse.map((pu) => Iana.LanguageSubtags.Validate.extendedLanguageRange.verifyIsWellFormed(pu)), subtags.privateUse);
|
|
75
|
+
}
|
|
76
|
+
return succeed(subtags.privateUse);
|
|
77
|
+
}
|
|
78
|
+
_checkGrandfatheredTags(subtags) {
|
|
79
|
+
return subtags.grandfathered
|
|
80
|
+
? this.iana.subtags.grandfathered.verifyIsValid(subtags.grandfathered)
|
|
81
|
+
: succeed(undefined);
|
|
82
|
+
}
|
|
83
|
+
_postValidate(subtags) {
|
|
84
|
+
return this._basicPostValidation(subtags).onSuccess((validated) => {
|
|
85
|
+
if (validated.extlangs && validated.extlangs.length > 1) {
|
|
86
|
+
return fail(`${validated.extlangs.join('-')}: multiple extlang subtags is invalid`);
|
|
87
|
+
}
|
|
88
|
+
return succeed(validated);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=isValid.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
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 Iana from '../../iana';
|
|
23
|
+
import * as Bcp47Subtags from '../bcp47Subtags';
|
|
24
|
+
import { allSucceed, succeed } from '@fgv/ts-utils';
|
|
25
|
+
import { TagValidatorBase } from './baseValidator';
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export class IsWellFormedValidator extends TagValidatorBase {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.validity = 'well-formed';
|
|
33
|
+
}
|
|
34
|
+
_checkLanguage(subtags) {
|
|
35
|
+
return subtags.primaryLanguage
|
|
36
|
+
? this.iana.subtags.languages.verifyIsWellFormed(subtags.primaryLanguage)
|
|
37
|
+
: succeed(undefined);
|
|
38
|
+
}
|
|
39
|
+
_checkExtlangs(subtags) {
|
|
40
|
+
if (subtags.extlangs) {
|
|
41
|
+
return allSucceed(subtags.extlangs.map((e) => this.iana.subtags.extlangs.verifyIsWellFormed(e)), subtags.extlangs);
|
|
42
|
+
}
|
|
43
|
+
return succeed(undefined);
|
|
44
|
+
}
|
|
45
|
+
_checkScript(subtags) {
|
|
46
|
+
return subtags.script ? this.iana.subtags.scripts.verifyIsWellFormed(subtags.script) : succeed(undefined);
|
|
47
|
+
}
|
|
48
|
+
_checkRegion(subtags) {
|
|
49
|
+
return subtags.region ? this.iana.subtags.regions.verifyIsWellFormed(subtags.region) : succeed(undefined);
|
|
50
|
+
}
|
|
51
|
+
_checkVariants(subtags) {
|
|
52
|
+
if (subtags.variants) {
|
|
53
|
+
return allSucceed(subtags.variants.map((v) => this.iana.subtags.variants.verifyIsWellFormed(v)), subtags.variants);
|
|
54
|
+
}
|
|
55
|
+
return succeed(undefined);
|
|
56
|
+
}
|
|
57
|
+
_checkExtensionSingleton(singleton) {
|
|
58
|
+
return this.iana.extensions.extensions.verifyIsWellFormed(singleton);
|
|
59
|
+
}
|
|
60
|
+
_checkExtensionSubtagValue(value) {
|
|
61
|
+
return Bcp47Subtags.Validate.extensionSubtag.verifyIsWellFormed(value);
|
|
62
|
+
}
|
|
63
|
+
_checkPrivateUseTags(subtags) {
|
|
64
|
+
if (subtags.privateUse) {
|
|
65
|
+
return allSucceed(subtags.privateUse.map((pu) => Iana.LanguageSubtags.Validate.extendedLanguageRange.verifyIsWellFormed(pu)), subtags.privateUse);
|
|
66
|
+
}
|
|
67
|
+
return succeed(subtags.privateUse);
|
|
68
|
+
}
|
|
69
|
+
_checkGrandfatheredTags(subtags) {
|
|
70
|
+
return subtags.grandfathered
|
|
71
|
+
? this.iana.subtags.grandfathered.verifyIsWellFormed(subtags.grandfathered)
|
|
72
|
+
: succeed(undefined);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=isWellFormed.js.map
|
|
@@ -0,0 +1,153 @@
|
|
|
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 { succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { compareValidity } from './common';
|
|
24
|
+
import { IsCanonicalValidator } from './isCanonical';
|
|
25
|
+
import { IsInPreferredFromValidator } from './isInPreferredForm';
|
|
26
|
+
import { IsStrictlyValidValidator } from './isStrictlyValid';
|
|
27
|
+
import { IsValidValidator } from './isValid';
|
|
28
|
+
import { IsWellFormedValidator } from './isWellFormed';
|
|
29
|
+
/**
|
|
30
|
+
* Validation helpers for BCP-47 language tags.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export class ValidateTag {
|
|
34
|
+
/**
|
|
35
|
+
* Determines if supplied {@link Bcp47.Subtags | subtags } are in canonical form,
|
|
36
|
+
* meaning that they are at least well-formed as specified by
|
|
37
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646}, and
|
|
38
|
+
* all subtags are also
|
|
39
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1.1 | capitalized as recommended}.
|
|
40
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to test.
|
|
41
|
+
* @returns `true` if the {@link Bcp47.Subtags | subtags } represent
|
|
42
|
+
* a language tag in canonical, false otherwise.
|
|
43
|
+
* @example `en-US` is in canonical form, `en-us` is not.
|
|
44
|
+
* @example `eng-US` is in canonical form, `eng-us` is not.
|
|
45
|
+
*/
|
|
46
|
+
static isCanonical(subtags) {
|
|
47
|
+
if (!this._isCanonical) {
|
|
48
|
+
this._isCanonical = new IsCanonicalValidator();
|
|
49
|
+
}
|
|
50
|
+
return this._isCanonical.validateSubtags(subtags).isSuccess();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Determines if supplied {@link Bcp47.Subtags | subtags } are
|
|
54
|
+
* in preferred form. Preferred form is valid as specified by
|
|
55
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646} and
|
|
56
|
+
* also meets additional preferences specified in the
|
|
57
|
+
* {@link https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry | language subtag registry} -
|
|
58
|
+
* extraneous (suppressed) script tags, deprecated language, extlang, script or region tags or
|
|
59
|
+
* deprecated grandfathered or redundant tags (with a defined preferred-value) are not allowed.
|
|
60
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to test.
|
|
61
|
+
* @returns `true` if the {@link Bcp47.Subtags | subtags } represent
|
|
62
|
+
* a valid language tag in preferred form, false otherwise.
|
|
63
|
+
* @example `en-US` is in preferred form, `en-Latn-US` is not.
|
|
64
|
+
* @example `cmn` is in preferred form, `zh-cmn-Hans` is not.
|
|
65
|
+
*/
|
|
66
|
+
static isInPreferredForm(subtags) {
|
|
67
|
+
if (!this._isInPreferredForm) {
|
|
68
|
+
this._isInPreferredForm = new IsInPreferredFromValidator();
|
|
69
|
+
}
|
|
70
|
+
return this._isInPreferredForm.validateSubtags(subtags).isSuccess();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Determines if supplied {@link Bcp47.Subtags | subtags } are
|
|
74
|
+
* strictly valid. A strictly valid tag is both
|
|
75
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | valid as defined in the RFC}
|
|
76
|
+
* and meets any other requirements such as
|
|
77
|
+
* {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-3.1.8 | prefix validity}.
|
|
78
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to test.
|
|
79
|
+
* @returns `true` if the {@link Bcp47.Subtags | subtags } represent
|
|
80
|
+
* a strictly valid language tag, false otherwise.
|
|
81
|
+
* @example `ca-valencia` is strictly valid, `es-valencia` is not.
|
|
82
|
+
*/
|
|
83
|
+
static isStrictlyValid(subtags) {
|
|
84
|
+
return this.validateSubtags(subtags, 'strictly-valid').isSuccess();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Determines if supplied {@link Bcp47.Subtags | subtags } are
|
|
88
|
+
* valid as specified by {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646},
|
|
89
|
+
* meaning that all subtags, or the tag itself for grandfathered tags, are defined in the
|
|
90
|
+
* {@link https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry | IANA language subtag registry}.
|
|
91
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to test.
|
|
92
|
+
* @returns `true` if the {@link Bcp47.Subtags | subtags } represent
|
|
93
|
+
* a valid language tag, false otherwise.
|
|
94
|
+
* @example `en-US` is valid, `eng-US` is not.
|
|
95
|
+
*/
|
|
96
|
+
static isValid(subtags) {
|
|
97
|
+
return this.validateSubtags(subtags, 'valid').isSuccess();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Determines if supplied {@link Bcp47.Subtags | subtags } are
|
|
101
|
+
* well-formed as specified by {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646},
|
|
102
|
+
* meaning that all subtags meet the grammar defined in the specification.
|
|
103
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to test.
|
|
104
|
+
* @returns `true` if the {@link Bcp47.Subtags | subtags } represent
|
|
105
|
+
* a well-formed language tag, false otherwise.
|
|
106
|
+
* @example `en-US` is valid, `english-US` is not.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
static isWellFormed(subtags) {
|
|
110
|
+
return this.validateSubtags(subtags, 'well-formed').isSuccess();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Chooses an appropriate default tag validator given desired and optional current
|
|
114
|
+
* {@link Bcp47.TagValidity | validation level}.
|
|
115
|
+
* @param wantValidity - The desired {@link Bcp47.TagValidity | validity level}.
|
|
116
|
+
* @param haveValidity - (optional) The current {@link Bcp47.TagValidity | validity level}.
|
|
117
|
+
* @returns An appropriate {@link Bcp47.TagValidator | tag validator} or `undefined` if no
|
|
118
|
+
* additional validation is necessary.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
static chooseValidator(wantValidity, haveValidity) {
|
|
122
|
+
if (haveValidity && compareValidity(haveValidity, wantValidity) >= 0) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (!this._validators) {
|
|
126
|
+
this._validators = {
|
|
127
|
+
unknown: new IsWellFormedValidator(),
|
|
128
|
+
'well-formed': new IsWellFormedValidator(),
|
|
129
|
+
valid: new IsValidValidator(),
|
|
130
|
+
'strictly-valid': new IsStrictlyValidValidator()
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return this._validators[wantValidity];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Validates supplied {@link Bcp47.Subtags | subtags } to a requested
|
|
137
|
+
* {@link Bcp47.TagValidity | validity level}, if necessary.
|
|
138
|
+
* @param subtags - The {@link Bcp47.Subtags | subtags } to be validated.
|
|
139
|
+
* @param wantValidity - The desired {@link Bcp47.TagValidity | validity level}.
|
|
140
|
+
* @param haveValidity - (optional) The current {@link Bcp47.TagValidity | validity level}.
|
|
141
|
+
* @returns `Success` with the validated {@link Bcp47.Subtags | subtags }, or
|
|
142
|
+
* `Failure` with details if an error occurs.
|
|
143
|
+
* @public
|
|
144
|
+
*/
|
|
145
|
+
static validateSubtags(subtags, wantValidity, haveValidity) {
|
|
146
|
+
var _a;
|
|
147
|
+
const validator = this.chooseValidator(wantValidity, haveValidity);
|
|
148
|
+
// istanbul ignore next - a pain to test
|
|
149
|
+
return (_a = validator === null || validator === void 0 ? void 0 : validator.validateSubtags(subtags)) !== null && _a !== void 0 ? _a : succeed(true);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
ValidateTag._validators = undefined;
|
|
153
|
+
//# sourceMappingURL=validateTag.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
import { Converters } from '@fgv/ts-utils';
|
|
25
|
+
/**
|
|
26
|
+
* Validating converter from string {@link Iana.Model.YearMonthDaySpec}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const yearMonthDaySpec = Validate.yearMonthDateSpec.converter;
|
|
30
|
+
/**
|
|
31
|
+
* Validating converter from string {@link Iana.Model.IsoAlpha2RegionCode}.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export const isoAlpha2RegionCode = Validate.isoAlpha2RegionCode.converter;
|
|
35
|
+
/**
|
|
36
|
+
* Validating converter from string {@link Iana.Model.IsoAlpha3RegionCode}.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export const isoAlpha3RegionCode = Validate.isoAlpha3RegionCode.converter;
|
|
40
|
+
/**
|
|
41
|
+
* Validating converter from string {@link Iana.Model.UnM49RegionCode}.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export const unM49RegionCode = Validate.unM49RegionCode.converter;
|
|
45
|
+
/**
|
|
46
|
+
* Helper function which creates a converter that returns a validated {@Link Iana.Model.IDatedRegistry | DatedRegistry}
|
|
47
|
+
* containing entries of supplied template type `T`.
|
|
48
|
+
* @param entryConverter - A `Converter<T>` to validate each entry
|
|
49
|
+
* @returns A new validating `Converter` which yields {@Link Iana.Model.IDatedRegistry | DatedRegistry<T>}
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export function datedRegistry(entryConverter) {
|
|
53
|
+
return Converters.strictObject({
|
|
54
|
+
fileDate: yearMonthDaySpec,
|
|
55
|
+
entries: Converters.arrayOf(entryConverter)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=converters.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
|