@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.
- package/package.json +8 -8
- package/src/data/bcp/overrides.json +0 -20
- package/src/data/iana/language-subtags.json +0 -57439
- package/src/data/iana/language-tag-extensions.json +0 -38
- package/src/data/unsd/m49.json +0 -3723
- package/src/index.ts +0 -29
- package/src/packlets/bcp47/bcp47Subtags/converters.ts +0 -33
- package/src/packlets/bcp47/bcp47Subtags/index.ts +0 -27
- package/src/packlets/bcp47/bcp47Subtags/model.ts +0 -46
- package/src/packlets/bcp47/bcp47Subtags/validate.ts +0 -55
- package/src/packlets/bcp47/common.ts +0 -85
- package/src/packlets/bcp47/helpers.ts +0 -117
- package/src/packlets/bcp47/index.ts +0 -38
- package/src/packlets/bcp47/languageRegistryData.ts +0 -304
- package/src/packlets/bcp47/languageTag.ts +0 -467
- package/src/packlets/bcp47/languageTagParser.ts +0 -307
- package/src/packlets/bcp47/match/chooser.ts +0 -164
- package/src/packlets/bcp47/match/common.ts +0 -57
- package/src/packlets/bcp47/match/index.ts +0 -26
- package/src/packlets/bcp47/match/similarity.ts +0 -243
- package/src/packlets/bcp47/normalization/baseNormalizer.ts +0 -146
- package/src/packlets/bcp47/normalization/canonicalNormalizer.ts +0 -102
- package/src/packlets/bcp47/normalization/common.ts +0 -84
- package/src/packlets/bcp47/normalization/index.ts +0 -27
- package/src/packlets/bcp47/normalization/normalizeTag.ts +0 -116
- package/src/packlets/bcp47/normalization/preferredTagNormalizer.ts +0 -213
- package/src/packlets/bcp47/overrides/converters.ts +0 -58
- package/src/packlets/bcp47/overrides/defaultRegistries.ts +0 -40
- package/src/packlets/bcp47/overrides/index.ts +0 -25
- package/src/packlets/bcp47/overrides/model.ts +0 -33
- package/src/packlets/bcp47/overrides/overridesRegistry.ts +0 -104
- package/src/packlets/bcp47/validation/baseValidator.ts +0 -132
- package/src/packlets/bcp47/validation/common.ts +0 -86
- package/src/packlets/bcp47/validation/index.ts +0 -29
- package/src/packlets/bcp47/validation/isCanonical.ts +0 -103
- package/src/packlets/bcp47/validation/isInPreferredForm.ts +0 -53
- package/src/packlets/bcp47/validation/isStrictlyValid.ts +0 -117
- package/src/packlets/bcp47/validation/isValid.ts +0 -122
- package/src/packlets/bcp47/validation/isWellFormed.ts +0 -102
- package/src/packlets/bcp47/validation/validateTag.ts +0 -175
- package/src/packlets/iana/common/converters.ts +0 -67
- package/src/packlets/iana/common/model.ts +0 -56
- package/src/packlets/iana/common/registeredItems.ts +0 -145
- package/src/packlets/iana/common/utils.ts +0 -32
- package/src/packlets/iana/common/validate.ts +0 -64
- package/src/packlets/iana/converters.ts +0 -26
- package/src/packlets/iana/defaultRegistries.ts +0 -40
- package/src/packlets/iana/index.ts +0 -33
- package/src/packlets/iana/jar/converters.ts +0 -26
- package/src/packlets/iana/jar/index.ts +0 -27
- package/src/packlets/iana/jar/jarConverters.ts +0 -70
- package/src/packlets/iana/jar/jarModel.ts +0 -34
- package/src/packlets/iana/jar/language-subtags/converters.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/index.ts +0 -27
- package/src/packlets/iana/jar/language-subtags/model.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/registry/converters.ts +0 -40
- package/src/packlets/iana/jar/language-subtags/registry/index.ts +0 -26
- package/src/packlets/iana/jar/language-subtags/registry/model.ts +0 -171
- package/src/packlets/iana/jar/language-subtags/tags/converters.ts +0 -120
- package/src/packlets/iana/jar/language-subtags/tags/index.ts +0 -28
- package/src/packlets/iana/jar/language-subtags/tags/model.ts +0 -71
- package/src/packlets/iana/jar/language-subtags/tags/tagValidation.ts +0 -67
- package/src/packlets/iana/jar/language-subtags/tags/validate.ts +0 -106
- package/src/packlets/iana/jar/model.ts +0 -26
- package/src/packlets/iana/language-subtags/common.ts +0 -46
- package/src/packlets/iana/language-subtags/converters.ts +0 -226
- package/src/packlets/iana/language-subtags/index.ts +0 -30
- package/src/packlets/iana/language-subtags/jarConverters.ts +0 -269
- package/src/packlets/iana/language-subtags/model.ts +0 -213
- package/src/packlets/iana/language-subtags/scope.ts +0 -222
- package/src/packlets/iana/language-subtags/subtagRegistry.ts +0 -136
- package/src/packlets/iana/language-subtags/validate.ts +0 -23
- package/src/packlets/iana/language-tag-extensions/converters.ts +0 -71
- package/src/packlets/iana/language-tag-extensions/extensionsRegistry.ts +0 -92
- package/src/packlets/iana/language-tag-extensions/extensionsScope.ts +0 -60
- package/src/packlets/iana/language-tag-extensions/index.ts +0 -29
- package/src/packlets/iana/language-tag-extensions/jarConverters.ts +0 -91
- package/src/packlets/iana/language-tag-extensions/model.ts +0 -67
- package/src/packlets/iana/language-tag-extensions/validate.ts +0 -36
- package/src/packlets/iana/languageRegistries.ts +0 -57
- package/src/packlets/iana/model.ts +0 -26
- package/src/packlets/iana/validate.ts +0 -23
- package/src/packlets/unsd/areas.ts +0 -105
- package/src/packlets/unsd/common.ts +0 -79
- package/src/packlets/unsd/csv/converters.ts +0 -82
- package/src/packlets/unsd/csv/index.ts +0 -26
- package/src/packlets/unsd/csv/model.ts +0 -44
- package/src/packlets/unsd/defaultRegistries.ts +0 -40
- package/src/packlets/unsd/index.ts +0 -28
- package/src/packlets/unsd/regionCodes.ts +0 -144
- package/src/packlets/unsd/regions.ts +0 -95
- package/src/packlets/utils/index.ts +0 -24
- package/src/packlets/utils/jsonHelpers.ts +0 -25
- package/src/packlets/utils/public.ts +0 -28
- package/src/packlets/utils/validationHelpers.ts +0 -180
|
@@ -1,26 +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
|
-
|
|
23
|
-
export * from './common/model';
|
|
24
|
-
|
|
25
|
-
import * as Jar from './jar/jarModel';
|
|
26
|
-
export { Jar };
|
|
@@ -1,23 +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
|
-
|
|
23
|
-
export * from './common/validate';
|
|
@@ -1,105 +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, fail, succeed } from '@fgv/ts-utils';
|
|
24
|
-
import * as Iana from '../iana';
|
|
25
|
-
import { ICountryOrArea } from './common';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export class Areas {
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
protected _m49: Map<Iana.Model.UnM49RegionCode, ICountryOrArea> = new Map();
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
protected _isoAlpha2: Map<Iana.Model.IsoAlpha2RegionCode, ICountryOrArea> = new Map();
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
protected _isoAlpha3: Map<Iana.Model.IsoAlpha3RegionCode, ICountryOrArea> = new Map();
|
|
45
|
-
|
|
46
|
-
public addArea(area: ICountryOrArea): Result<ICountryOrArea> {
|
|
47
|
-
const existing = {
|
|
48
|
-
m49: this._m49.get(area.code),
|
|
49
|
-
alpha2: area.isoAlpha2 ? this._isoAlpha2.get(area.isoAlpha2) : undefined,
|
|
50
|
-
alpha3: area.isoAlpha3 ? this._isoAlpha3.get(area.isoAlpha3) : undefined
|
|
51
|
-
};
|
|
52
|
-
if (existing.m49) {
|
|
53
|
-
return fail(`${area.name}: Region ${existing.m49.name} already exists with M.49 code ${area.code}`);
|
|
54
|
-
} else if (existing.alpha2) {
|
|
55
|
-
return fail(
|
|
56
|
-
`${area.name}: Region ${existing.alpha2.name} already exists with ISO Alpha-2 code ${area.isoAlpha2}`
|
|
57
|
-
);
|
|
58
|
-
} else if (existing.alpha3) {
|
|
59
|
-
return fail(
|
|
60
|
-
`${area.name}: Region ${existing.alpha3.name} already exists with ISO Alpha-3 code ${area.isoAlpha3}`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
const added = { ...area };
|
|
64
|
-
this._m49.set(area.code, added);
|
|
65
|
-
if (area.isoAlpha2) {
|
|
66
|
-
this._isoAlpha2.set(area.isoAlpha2, added);
|
|
67
|
-
}
|
|
68
|
-
if (area.isoAlpha3) {
|
|
69
|
-
this._isoAlpha3.set(area.isoAlpha3, added);
|
|
70
|
-
}
|
|
71
|
-
area.parent.areas.push(added);
|
|
72
|
-
return succeed(added);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public tryGetArea(from: Iana.Model.UnM49RegionCode): ICountryOrArea | undefined {
|
|
76
|
-
return this._m49.get(from);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public tryGetAlpha2Area(from: Iana.Model.IsoAlpha2RegionCode): ICountryOrArea | undefined {
|
|
80
|
-
return this._isoAlpha2.get(from.toUpperCase() as Iana.Model.IsoAlpha2RegionCode);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public tryGetAlpha3Area(from: Iana.Model.IsoAlpha3RegionCode): ICountryOrArea | undefined {
|
|
84
|
-
return this._isoAlpha3.get(from.toUpperCase() as Iana.Model.IsoAlpha3RegionCode);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public getArea(from: Iana.Model.UnM49RegionCode): Result<ICountryOrArea> {
|
|
88
|
-
const got = this._m49.get(from);
|
|
89
|
-
return got ? succeed(got) : fail(`${from}: area not found`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public getAlpha2Area(from: Iana.Model.IsoAlpha2RegionCode): Result<ICountryOrArea> {
|
|
93
|
-
const got = this._isoAlpha2.get(from.toUpperCase() as Iana.Model.IsoAlpha2RegionCode);
|
|
94
|
-
return got ? succeed(got) : fail(`${from}: alpha-2 area not found`);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public getAlpha3Area(from: Iana.Model.IsoAlpha3RegionCode): Result<ICountryOrArea> {
|
|
98
|
-
const got = this._isoAlpha3.get(from.toUpperCase() as Iana.Model.IsoAlpha3RegionCode);
|
|
99
|
-
return got ? succeed(got) : fail(`${from}: alpha-3 area not found`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public getAll(): ICountryOrArea[] {
|
|
103
|
-
return Array.from(this._m49.values());
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,79 +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
|
-
/**
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export type IntermediateRegionTier = 'region' | 'subRegion' | 'intermediateRegion';
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export type RegionTier = 'global' | IntermediateRegionTier;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @public
|
|
36
|
-
*/
|
|
37
|
-
export interface IGlobalRegion {
|
|
38
|
-
name: string;
|
|
39
|
-
code: Iana.Model.UnM49RegionCode;
|
|
40
|
-
tier: 'global';
|
|
41
|
-
/* eslint-disable no-use-before-define */
|
|
42
|
-
regions: IIntermediateRegion[];
|
|
43
|
-
areas: ICountryOrArea[];
|
|
44
|
-
/* eslint-enable no-use-before-define */
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export interface IIntermediateRegion {
|
|
51
|
-
name: string;
|
|
52
|
-
code: Iana.Model.UnM49RegionCode;
|
|
53
|
-
tier: RegionTier;
|
|
54
|
-
/* eslint-disable no-use-before-define */
|
|
55
|
-
parent: Region;
|
|
56
|
-
regions: IIntermediateRegion[];
|
|
57
|
-
areas: ICountryOrArea[];
|
|
58
|
-
/* eslint-enable no-use-before-define */
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
export type Region = IGlobalRegion | IIntermediateRegion;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export interface ICountryOrArea {
|
|
70
|
-
name: string;
|
|
71
|
-
code: Iana.Model.UnM49RegionCode;
|
|
72
|
-
tier: 'area';
|
|
73
|
-
parent: Region;
|
|
74
|
-
isoAlpha2?: Iana.Model.IsoAlpha2RegionCode;
|
|
75
|
-
isoAlpha3?: Iana.Model.IsoAlpha3RegionCode;
|
|
76
|
-
leastDevelopedCountry: boolean;
|
|
77
|
-
landlockedDevelopingCountry: boolean;
|
|
78
|
-
smallIslandDevelopingState: boolean;
|
|
79
|
-
}
|
|
@@ -1,82 +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 { Csv } from '@fgv/ts-extras';
|
|
25
|
-
import { Converters, Result, succeed } from '@fgv/ts-utils';
|
|
26
|
-
import { Converters as IanaConverters } from '../../iana';
|
|
27
|
-
import { RegionTier } from '../common';
|
|
28
|
-
import * as Model from './model';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export const regionTier = Converters.enumeratedValue<RegionTier>([
|
|
34
|
-
'global',
|
|
35
|
-
'intermediateRegion',
|
|
36
|
-
'region',
|
|
37
|
-
'subRegion'
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
|
-
const optionalString = Converters.string.optional('ignoreErrors');
|
|
41
|
-
const optionalUnM49RegionCode = IanaConverters.unM49RegionCode.optional('ignoreErrors');
|
|
42
|
-
const optionalIsoAlpha2RegionCode = IanaConverters.isoAlpha2RegionCode.optional('ignoreErrors');
|
|
43
|
-
const optionalIsoAlpha3RegionCode = IanaConverters.isoAlpha3RegionCode.optional('ignoreErrors');
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
export const m49CsvRow = Converters.transform<Model.IM49CsvRow>({
|
|
49
|
-
globalCode: Converters.element(0, IanaConverters.unM49RegionCode),
|
|
50
|
-
globalName: Converters.element(1, Converters.string),
|
|
51
|
-
regionCode: Converters.element(2, optionalUnM49RegionCode),
|
|
52
|
-
regionName: Converters.element(3, optionalString),
|
|
53
|
-
subRegionCode: Converters.element(4, optionalUnM49RegionCode),
|
|
54
|
-
subRegionName: Converters.element(5, optionalString),
|
|
55
|
-
intermediateRegionCode: Converters.element(6, optionalUnM49RegionCode),
|
|
56
|
-
intermediateRegionName: Converters.element(7, optionalString),
|
|
57
|
-
countryOrArea: Converters.element(8, Converters.string),
|
|
58
|
-
m49Code: Converters.element(9, IanaConverters.unM49RegionCode),
|
|
59
|
-
isoAlpha2RegionCode: Converters.element(10, optionalIsoAlpha2RegionCode),
|
|
60
|
-
isoAlpha3RegionCode: Converters.element(11, optionalIsoAlpha3RegionCode),
|
|
61
|
-
leastDevelopedCountry: Converters.element(12, Converters.string).map((s) => succeed(s === 'x')),
|
|
62
|
-
landLockedDevelopingCountry: Converters.element(13, Converters.string).map((s) => succeed(s === 'x')),
|
|
63
|
-
smallIslandDevelopingState: Converters.element(14, Converters.string).map((s) => succeed(s === 'x'))
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
export const m49CsvFile = Converters.arrayOf(m49CsvRow);
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Loads a UNSD M.49 registry text (csv) file.
|
|
73
|
-
* @param csvPath - The path from which the file is to be loaded.
|
|
74
|
-
* @returns `Success` with the parsed file contents or `Failure` with
|
|
75
|
-
* details if an error occurs.
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
export function loadM49csvFileSync(csvPath: string): Result<Model.IM49CsvRow[]> {
|
|
79
|
-
return Csv.readCsvFileSync(csvPath, { delimiter: ';' }).onSuccess((csv) => {
|
|
80
|
-
return m49CsvFile.convert(csv);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
@@ -1,26 +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
|
-
|
|
26
|
-
export { Converters, Model };
|
|
@@ -1,44 +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
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export interface IM49CsvRow {
|
|
29
|
-
globalCode: Iana.Model.UnM49RegionCode;
|
|
30
|
-
globalName: string;
|
|
31
|
-
regionCode?: Iana.Model.UnM49RegionCode;
|
|
32
|
-
regionName?: string;
|
|
33
|
-
subRegionCode?: Iana.Model.UnM49RegionCode;
|
|
34
|
-
subRegionName?: string;
|
|
35
|
-
intermediateRegionCode?: Iana.Model.UnM49RegionCode;
|
|
36
|
-
intermediateRegionName?: string;
|
|
37
|
-
countryOrArea: string;
|
|
38
|
-
m49Code: Iana.Model.UnM49RegionCode;
|
|
39
|
-
isoAlpha2RegionCode?: Iana.Model.IsoAlpha2RegionCode;
|
|
40
|
-
isoAlpha3RegionCode?: Iana.Model.IsoAlpha3RegionCode;
|
|
41
|
-
leastDevelopedCountry: boolean;
|
|
42
|
-
landLockedDevelopingCountry: boolean;
|
|
43
|
-
smallIslandDevelopingState: boolean;
|
|
44
|
-
}
|
|
@@ -1,40 +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 { RegionCodes } from './regionCodes';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export class DefaultRegistries {
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
protected static _regionCodes?: RegionCodes = undefined;
|
|
33
|
-
|
|
34
|
-
public static get regionCodes(): RegionCodes {
|
|
35
|
-
if (!this._regionCodes) {
|
|
36
|
-
this._regionCodes = RegionCodes.loadDefault().orThrow();
|
|
37
|
-
}
|
|
38
|
-
return this._regionCodes;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,28 +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 Csv from './csv';
|
|
24
|
-
|
|
25
|
-
export * from './common';
|
|
26
|
-
export { DefaultRegistries } from './defaultRegistries';
|
|
27
|
-
export { RegionCodes } from './regionCodes';
|
|
28
|
-
export { Csv };
|
|
@@ -1,144 +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
|
-
import * as Model from './csv/model';
|
|
25
|
-
|
|
26
|
-
import { Result, allSucceed, succeed } from '@fgv/ts-utils';
|
|
27
|
-
import { ICountryOrArea, Region } from './common';
|
|
28
|
-
import { loadM49csvFileSync, m49CsvFile } from './csv/converters';
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
31
|
-
import defaultRegions from '../../data/unsd/m49.json';
|
|
32
|
-
import { Areas } from './areas';
|
|
33
|
-
import { Regions } from './regions';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export class RegionCodes {
|
|
39
|
-
public readonly regions: Regions;
|
|
40
|
-
public readonly areas: Areas;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
protected constructor() {
|
|
46
|
-
this.regions = new Regions();
|
|
47
|
-
this.areas = new Areas();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public static create(rows: Model.IM49CsvRow[]): Result<RegionCodes> {
|
|
51
|
-
const codes = new RegionCodes();
|
|
52
|
-
return codes._importRows(rows).onSuccess(() => {
|
|
53
|
-
return succeed(codes);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static createFromJson(from: unknown): Result<RegionCodes> {
|
|
58
|
-
return m49CsvFile.convert(from).onSuccess(RegionCodes.create);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static loadDefault(): Result<RegionCodes> {
|
|
62
|
-
return this.createFromJson(defaultRegions);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public static loadCsv(path: string): Result<RegionCodes> {
|
|
66
|
-
return loadM49csvFileSync(path).onSuccess((rows) => {
|
|
67
|
-
return this.create(rows);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public tryGetRegionOrArea(code: Iana.Model.UnM49RegionCode): Region | ICountryOrArea | undefined {
|
|
72
|
-
/* c8 ignore next - numeric area not allowed in bcp-47 so right side of ?? shouldn't be hit. */
|
|
73
|
-
return this.regions.tryGetRegion(code) ?? this.areas.tryGetArea(code);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public getIsContained(container: Region, contained: ICountryOrArea | Region): boolean {
|
|
77
|
-
let next: Region | ICountryOrArea | undefined = contained;
|
|
78
|
-
while (next) {
|
|
79
|
-
if (next === container) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
next = next.tier !== 'global' ? next.parent : undefined;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Imports a single parsed row of UN M.49 region code data
|
|
89
|
-
* @param row - The parsed row to be imported.
|
|
90
|
-
* @returns `Success` with `true` if the row was successfully
|
|
91
|
-
* imported, or `Failure` with details if an error occurs.
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
protected _importRow(row: Model.IM49CsvRow): Result<true> {
|
|
95
|
-
return this.regions
|
|
96
|
-
.getOrAddRegionChildRegion('region', this.regions.global, row.regionCode, row.regionName)
|
|
97
|
-
.onSuccess((region) => {
|
|
98
|
-
return this.regions.getOrAddRegionChildRegion(
|
|
99
|
-
'subRegion',
|
|
100
|
-
region,
|
|
101
|
-
row.subRegionCode,
|
|
102
|
-
row.subRegionName
|
|
103
|
-
);
|
|
104
|
-
})
|
|
105
|
-
.onSuccess((region) => {
|
|
106
|
-
return this.regions.getOrAddRegionChildRegion(
|
|
107
|
-
'intermediateRegion',
|
|
108
|
-
region,
|
|
109
|
-
row.intermediateRegionCode,
|
|
110
|
-
row.intermediateRegionName
|
|
111
|
-
);
|
|
112
|
-
})
|
|
113
|
-
.onSuccess((region) => {
|
|
114
|
-
return this.areas.addArea({
|
|
115
|
-
name: row.countryOrArea,
|
|
116
|
-
code: row.m49Code,
|
|
117
|
-
tier: 'area',
|
|
118
|
-
parent: region,
|
|
119
|
-
isoAlpha2: row.isoAlpha2RegionCode,
|
|
120
|
-
isoAlpha3: row.isoAlpha3RegionCode,
|
|
121
|
-
leastDevelopedCountry: row.leastDevelopedCountry,
|
|
122
|
-
landlockedDevelopingCountry: row.landLockedDevelopingCountry,
|
|
123
|
-
smallIslandDevelopingState: row.smallIslandDevelopingState
|
|
124
|
-
});
|
|
125
|
-
})
|
|
126
|
-
.onSuccess(() => {
|
|
127
|
-
return succeed(true);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Imports multiple parsed rows from UN M.49 region code data
|
|
133
|
-
* @param rows - The parsed rows to be imported.
|
|
134
|
-
* @returns `Success` with `true` if the rows were successfully
|
|
135
|
-
* imported, or `Failure` with details if an error occurs.
|
|
136
|
-
* @internal
|
|
137
|
-
*/
|
|
138
|
-
protected _importRows(rows: Model.IM49CsvRow[]): Result<true> {
|
|
139
|
-
return allSucceed(
|
|
140
|
-
rows.map((row) => this._importRow(row)),
|
|
141
|
-
true
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|