@temboplus/frontend-core 0.2.4 → 0.2.5
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/README.md +12 -7
- package/esm/src/data/countries.d.ts +26 -3
- package/esm/src/data/countries.js +2227 -974
- package/esm/src/models/country/country.d.ts +134 -18
- package/esm/src/models/country/country.d.ts.map +1 -1
- package/esm/src/models/country/country.js +184 -12
- package/esm/src/models/country/service.d.ts +43 -7
- package/esm/src/models/country/service.d.ts.map +1 -1
- package/esm/src/models/country/service.js +197 -98
- package/package.json +1 -1
- package/script/src/data/countries.d.ts +26 -3
- package/script/src/data/countries.js +2227 -974
- package/script/src/models/country/country.d.ts +134 -18
- package/script/src/models/country/country.d.ts.map +1 -1
- package/script/src/models/country/country.js +185 -13
- package/script/src/models/country/service.d.ts +43 -7
- package/script/src/models/country/service.d.ts.map +1 -1
- package/script/src/models/country/service.js +196 -97
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Country } from "./country.js";
|
|
1
|
+
import { CONTINENT, Country, SUB_REGION } from "./country.js";
|
|
2
2
|
/**
|
|
3
3
|
* Service for managing country data.
|
|
4
4
|
* @class CountryService
|
|
@@ -7,8 +7,10 @@ export declare class CountryService {
|
|
|
7
7
|
private static instance;
|
|
8
8
|
private countryList;
|
|
9
9
|
private codeRecord;
|
|
10
|
+
private iso3Record;
|
|
10
11
|
private nameRecord;
|
|
11
|
-
private
|
|
12
|
+
private continentRecord;
|
|
13
|
+
private regionRecord;
|
|
12
14
|
private staticReferences;
|
|
13
15
|
private constructor();
|
|
14
16
|
/**
|
|
@@ -18,37 +20,71 @@ export declare class CountryService {
|
|
|
18
20
|
* @returns {CountryService} The singleton instance
|
|
19
21
|
*/
|
|
20
22
|
static getInstance(): CountryService;
|
|
23
|
+
/**
|
|
24
|
+
* Maps a string continent name to the CONTINENT enum
|
|
25
|
+
* @param continentName String continent name from JSON
|
|
26
|
+
* @returns The corresponding CONTINENT enum value
|
|
27
|
+
*/
|
|
28
|
+
private mapContinent;
|
|
29
|
+
/**
|
|
30
|
+
* Maps a string region name to the SUB_REGION enum
|
|
31
|
+
* @param regionName String region name from JSON
|
|
32
|
+
* @returns The corresponding SUB_REGION enum value
|
|
33
|
+
*/
|
|
34
|
+
private mapRegion;
|
|
21
35
|
/**
|
|
22
36
|
* Initializes the service with country data.
|
|
23
37
|
* Should be called once when your application starts.
|
|
24
38
|
*/
|
|
25
39
|
private initialize;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the static properties on the Country class
|
|
42
|
+
*/
|
|
43
|
+
private initializeCountryStatics;
|
|
26
44
|
/**
|
|
27
45
|
* Gets all countries.
|
|
28
46
|
* @returns {Country[]} Array of all countries
|
|
29
47
|
*/
|
|
30
48
|
getAll(): Country[];
|
|
49
|
+
/**
|
|
50
|
+
* Gets static country references to be used by the Country class.
|
|
51
|
+
* @returns {Map<string, Country>} Map of static references
|
|
52
|
+
*/
|
|
53
|
+
getStaticReferences(): Map<string, Country>;
|
|
31
54
|
/**
|
|
32
55
|
* Gets all countries as a record.
|
|
33
56
|
* @returns {Record<string, Country>} Record of country codes and country objects
|
|
34
57
|
*/
|
|
35
58
|
getAllAsRecord(): Record<string, Country>;
|
|
36
59
|
/**
|
|
37
|
-
* Gets
|
|
38
|
-
* @
|
|
60
|
+
* Gets all countries from a specific continent.
|
|
61
|
+
* @param {CONTINENT} continent The continent enum value
|
|
62
|
+
* @returns {Country[]} Array of countries in the specified continent
|
|
39
63
|
*/
|
|
40
|
-
|
|
64
|
+
getByContinent(continent: CONTINENT): Country[];
|
|
65
|
+
/**
|
|
66
|
+
* Gets all countries from a specific region.
|
|
67
|
+
* @param {SUB_REGION} region The region enum value
|
|
68
|
+
* @returns {Country[]} Array of countries in the specified region
|
|
69
|
+
*/
|
|
70
|
+
getByRegion(region: SUB_REGION): Country[];
|
|
41
71
|
/**
|
|
42
72
|
* Gets the full name record mapping.
|
|
43
73
|
* @returns {Record<string, Country>} Record of uppercase full name keys to country objects
|
|
44
74
|
*/
|
|
45
75
|
getFullNameRecord(): Record<string, Country>;
|
|
46
76
|
/**
|
|
47
|
-
* Retrieves a country by its ISO code.
|
|
48
|
-
* @param {string} code The ISO code of the country.
|
|
77
|
+
* Retrieves a country by its ISO-2 code.
|
|
78
|
+
* @param {string} code The ISO-2 code of the country.
|
|
49
79
|
* @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
|
|
50
80
|
*/
|
|
51
81
|
fromCode(code: string): Country | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves a country by its ISO-3 code.
|
|
84
|
+
* @param {string} iso3 The ISO-3 code of the country.
|
|
85
|
+
* @returns {Country | undefined} The country corresponding to the ISO-3 code or `undefined` if not found.
|
|
86
|
+
*/
|
|
87
|
+
fromIso3(iso3: string): Country | undefined;
|
|
52
88
|
/**
|
|
53
89
|
* Retrieves a country by its name.
|
|
54
90
|
* @param {string} countryName The name of the country.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/country/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/country/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG9D;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,UAAU,CAA+B;IAEjD,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,eAAe,CAGrB;IACF,OAAO,CAAC,YAAY,CAGlB;IAGF,OAAO,CAAC,gBAAgB,CAAmC;IAE3D,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,cAAc;IAQpC;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAqBpB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAiDjB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAqIlB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAchC;;;OAGG;IACH,MAAM,IAAI,OAAO,EAAE;IAInB;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAI3C;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC;;;;OAIG;IACH,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,EAAE;IAI/C;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,EAAE;IAI1C;;;OAGG;IACH,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI3C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI3C;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAgBlD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,EAAE;IAgBzD;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO;CAMvD"}
|
|
@@ -24,13 +24,26 @@ class CountryService {
|
|
|
24
24
|
writable: true,
|
|
25
25
|
value: {}
|
|
26
26
|
});
|
|
27
|
+
Object.defineProperty(this, "iso3Record", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: {}
|
|
32
|
+
});
|
|
33
|
+
// private nameRecord: Record<string, Country> = {};
|
|
27
34
|
Object.defineProperty(this, "nameRecord", {
|
|
28
35
|
enumerable: true,
|
|
29
36
|
configurable: true,
|
|
30
37
|
writable: true,
|
|
31
38
|
value: {}
|
|
32
39
|
});
|
|
33
|
-
Object.defineProperty(this, "
|
|
40
|
+
Object.defineProperty(this, "continentRecord", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: {}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "regionRecord", {
|
|
34
47
|
enumerable: true,
|
|
35
48
|
configurable: true,
|
|
36
49
|
writable: true,
|
|
@@ -57,133 +70,198 @@ class CountryService {
|
|
|
57
70
|
}
|
|
58
71
|
return CountryService.instance;
|
|
59
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Maps a string continent name to the CONTINENT enum
|
|
75
|
+
* @param continentName String continent name from JSON
|
|
76
|
+
* @returns The corresponding CONTINENT enum value
|
|
77
|
+
*/
|
|
78
|
+
mapContinent(continentName) {
|
|
79
|
+
switch (continentName) {
|
|
80
|
+
case "Africa":
|
|
81
|
+
return country_js_1.CONTINENT.AFRICA;
|
|
82
|
+
case "Antarctica":
|
|
83
|
+
return country_js_1.CONTINENT.ANTARCTICA;
|
|
84
|
+
case "Asia":
|
|
85
|
+
return country_js_1.CONTINENT.ASIA;
|
|
86
|
+
case "Europe":
|
|
87
|
+
return country_js_1.CONTINENT.EUROPE;
|
|
88
|
+
case "North America":
|
|
89
|
+
return country_js_1.CONTINENT.NORTH_AMERICA;
|
|
90
|
+
case "Oceania":
|
|
91
|
+
return country_js_1.CONTINENT.OCEANIA;
|
|
92
|
+
case "South America":
|
|
93
|
+
return country_js_1.CONTINENT.SOUTH_AMERICA;
|
|
94
|
+
default:
|
|
95
|
+
return country_js_1.CONTINENT.EUROPE; // Default value
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Maps a string region name to the SUB_REGION enum
|
|
100
|
+
* @param regionName String region name from JSON
|
|
101
|
+
* @returns The corresponding SUB_REGION enum value
|
|
102
|
+
*/
|
|
103
|
+
mapRegion(regionName) {
|
|
104
|
+
switch (regionName) {
|
|
105
|
+
case "Australia and New Zealand":
|
|
106
|
+
return country_js_1.SUB_REGION.AUSTRALIA_AND_NEW_ZEALAND;
|
|
107
|
+
case "Caribbean":
|
|
108
|
+
return country_js_1.SUB_REGION.CARIBBEAN;
|
|
109
|
+
case "Central America":
|
|
110
|
+
return country_js_1.SUB_REGION.CENTRAL_AMERICA;
|
|
111
|
+
case "Central Asia":
|
|
112
|
+
return country_js_1.SUB_REGION.CENTRAL_ASIA;
|
|
113
|
+
case "Eastern Africa":
|
|
114
|
+
return country_js_1.SUB_REGION.EASTERN_AFRICA;
|
|
115
|
+
case "Eastern Asia":
|
|
116
|
+
return country_js_1.SUB_REGION.EASTERN_ASIA;
|
|
117
|
+
case "Eastern Europe":
|
|
118
|
+
return country_js_1.SUB_REGION.EASTERN_EUROPE;
|
|
119
|
+
case "Melanesia":
|
|
120
|
+
return country_js_1.SUB_REGION.MELANESIA;
|
|
121
|
+
case "Micronesia":
|
|
122
|
+
return country_js_1.SUB_REGION.MICRONESIA;
|
|
123
|
+
case "Middle Africa":
|
|
124
|
+
return country_js_1.SUB_REGION.MIDDLE_AFRICA;
|
|
125
|
+
case "Northern Africa":
|
|
126
|
+
return country_js_1.SUB_REGION.NORTHERN_AFRICA;
|
|
127
|
+
case "Northern America":
|
|
128
|
+
return country_js_1.SUB_REGION.NORTHERN_AMERICA;
|
|
129
|
+
case "Northern Europe":
|
|
130
|
+
return country_js_1.SUB_REGION.NORTHERN_EUROPE;
|
|
131
|
+
case "Polynesia":
|
|
132
|
+
return country_js_1.SUB_REGION.POLYNESIA;
|
|
133
|
+
case "South-eastern Asia":
|
|
134
|
+
return country_js_1.SUB_REGION.SOUTH_EASTERN_ASIA;
|
|
135
|
+
case "Southern Africa":
|
|
136
|
+
return country_js_1.SUB_REGION.SOUTHERN_AFRICA;
|
|
137
|
+
case "Southern Asia":
|
|
138
|
+
return country_js_1.SUB_REGION.SOUTHERN_ASIA;
|
|
139
|
+
case "Southern Europe":
|
|
140
|
+
return country_js_1.SUB_REGION.SOUTHERN_EUROPE;
|
|
141
|
+
case "Western Africa":
|
|
142
|
+
return country_js_1.SUB_REGION.WESTERN_AFRICA;
|
|
143
|
+
case "Western Asia":
|
|
144
|
+
return country_js_1.SUB_REGION.WESTERN_ASIA;
|
|
145
|
+
case "Western Europe":
|
|
146
|
+
return country_js_1.SUB_REGION.WESTERN_EUROPE;
|
|
147
|
+
default:
|
|
148
|
+
return country_js_1.SUB_REGION.NORTHERN_EUROPE; // Default value
|
|
149
|
+
}
|
|
150
|
+
}
|
|
60
151
|
/**
|
|
61
152
|
* Initializes the service with country data.
|
|
62
153
|
* Should be called once when your application starts.
|
|
63
154
|
*/
|
|
64
155
|
initialize() {
|
|
65
156
|
try {
|
|
157
|
+
// Parse the JSON data
|
|
66
158
|
const data = JSON.parse(JSON.stringify(countries_js_1.default));
|
|
67
|
-
|
|
159
|
+
// deno-lint-ignore no-explicit-any
|
|
160
|
+
const countriesData = data.countries || [];
|
|
161
|
+
// Initialize continent and region records
|
|
162
|
+
Object.values(country_js_1.CONTINENT).forEach((continent) => {
|
|
163
|
+
this.continentRecord[continent] = [];
|
|
164
|
+
});
|
|
165
|
+
Object.values(country_js_1.SUB_REGION).forEach((region) => {
|
|
166
|
+
this.regionRecord[region] = [];
|
|
167
|
+
});
|
|
168
|
+
// Create Country instances from the data
|
|
169
|
+
const countries = countriesData.map((c) => {
|
|
170
|
+
const continent = this.mapContinent(c.continent);
|
|
171
|
+
const region = this.mapRegion(c.region);
|
|
172
|
+
return new country_js_1.Country(c.name, c.iso_2, c.name_official, c.iso_3, c.flag_emoji, continent, region);
|
|
173
|
+
});
|
|
68
174
|
const code_record = {};
|
|
175
|
+
const iso3_record = {};
|
|
176
|
+
// const name_record: Record<string, Country> = {};
|
|
69
177
|
const name_record = {};
|
|
70
|
-
const fullname_record = {};
|
|
71
178
|
countries.forEach((country) => {
|
|
72
|
-
// Populate code
|
|
179
|
+
// Populate code records
|
|
73
180
|
code_record[country.code] = country;
|
|
181
|
+
iso3_record[country.iso3] = country;
|
|
74
182
|
// Add to record by name
|
|
75
|
-
name_record[country.name.toUpperCase()] = country;
|
|
183
|
+
// name_record[country.name.toUpperCase()] = country;
|
|
76
184
|
// Generate uppercase full name with underscores
|
|
77
|
-
const
|
|
185
|
+
const nameKey = country.name
|
|
78
186
|
.toUpperCase()
|
|
79
187
|
.replace(/\s+/g, "_")
|
|
80
188
|
.replace(/[-(),.']/g, "")
|
|
81
189
|
.replace(/&/g, "AND");
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
this.
|
|
85
|
-
|
|
190
|
+
name_record[nameKey] = country;
|
|
191
|
+
// Group countries by continent
|
|
192
|
+
this.continentRecord[country.continent].push(country);
|
|
193
|
+
// Group countries by region
|
|
194
|
+
this.regionRecord[country.region].push(country);
|
|
195
|
+
this.staticReferences.set(country.code, country);
|
|
196
|
+
this.staticReferences.set(nameKey, country);
|
|
86
197
|
});
|
|
87
|
-
//
|
|
88
|
-
if (code_record["US"]) {
|
|
89
|
-
fullname_record["UNITED_STATES"] = code_record["US"];
|
|
90
|
-
this.staticReferences.set("UNITED_STATES", code_record["US"]);
|
|
91
|
-
}
|
|
92
|
-
// Add specific country mappings
|
|
198
|
+
// Add specific country mappings for special cases
|
|
93
199
|
// Cocos Islands
|
|
94
200
|
if (code_record["CC"]) {
|
|
95
|
-
|
|
201
|
+
name_record["COCOS_ISLANDS"] = code_record["CC"];
|
|
96
202
|
this.staticReferences.set("COCOS_ISLANDS", code_record["CC"]);
|
|
97
203
|
}
|
|
98
|
-
// Democratic Republic of Congo
|
|
99
|
-
if (code_record["CD"]) {
|
|
100
|
-
fullname_record["DEMOCRATIC_REPUBLIC_OF_CONGO"] = code_record["CD"];
|
|
101
|
-
this.staticReferences.set("DEMOCRATIC_REPUBLIC_OF_CONGO", code_record["CD"]);
|
|
102
|
-
}
|
|
103
204
|
// Cote d'Ivoire
|
|
104
205
|
if (code_record["CI"]) {
|
|
105
|
-
|
|
206
|
+
name_record["COTE_DIVOIRE"] = code_record["CI"];
|
|
106
207
|
this.staticReferences.set("COTE_DIVOIRE", code_record["CI"]);
|
|
107
208
|
}
|
|
108
|
-
//
|
|
109
|
-
if (code_record["FK"]) {
|
|
110
|
-
fullname_record["FALKLAND_ISLANDS"] = code_record["FK"];
|
|
111
|
-
this.staticReferences.set("FALKLAND_ISLANDS", code_record["FK"]);
|
|
112
|
-
}
|
|
113
|
-
// Holy See (Vatican)
|
|
114
|
-
if (code_record["VA"]) {
|
|
115
|
-
fullname_record["HOLY_SEE"] = code_record["VA"];
|
|
116
|
-
this.staticReferences.set("HOLY_SEE", code_record["VA"]);
|
|
117
|
-
}
|
|
118
|
-
// Iran
|
|
119
|
-
if (code_record["IR"]) {
|
|
120
|
-
fullname_record["IRAN"] = code_record["IR"];
|
|
121
|
-
this.staticReferences.set("IRAN", code_record["IR"]);
|
|
122
|
-
}
|
|
123
|
-
// North Korea
|
|
124
|
-
if (code_record["KP"]) {
|
|
125
|
-
fullname_record["NORTH_KOREA"] = code_record["KP"];
|
|
126
|
-
this.staticReferences.set("NORTH_KOREA", code_record["KP"]);
|
|
127
|
-
}
|
|
128
|
-
// South Korea
|
|
129
|
-
if (code_record["KR"]) {
|
|
130
|
-
fullname_record["SOUTH_KOREA"] = code_record["KR"];
|
|
131
|
-
this.staticReferences.set("SOUTH_KOREA", code_record["KR"]);
|
|
132
|
-
}
|
|
133
|
-
// Lao People's Democratic Republic
|
|
134
|
-
if (code_record["LA"]) {
|
|
135
|
-
fullname_record["LAO"] = code_record["LA"];
|
|
136
|
-
this.staticReferences.set("LAO", code_record["LA"]);
|
|
137
|
-
}
|
|
138
|
-
// Palestine
|
|
139
|
-
if (code_record["PS"]) {
|
|
140
|
-
fullname_record["PALESTINE"] = code_record["PS"];
|
|
141
|
-
this.staticReferences.set("PALESTINE", code_record["PS"]);
|
|
142
|
-
}
|
|
143
|
-
// Macedonia
|
|
209
|
+
// Macedonia (North Macedonia)
|
|
144
210
|
if (code_record["MK"]) {
|
|
145
|
-
|
|
211
|
+
name_record["MACEDONIA"] = code_record["MK"];
|
|
146
212
|
this.staticReferences.set("MACEDONIA", code_record["MK"]);
|
|
147
213
|
}
|
|
148
|
-
// Micronesia
|
|
149
|
-
if (code_record["FM"]) {
|
|
150
|
-
fullname_record["MICRONESIA"] = code_record["FM"];
|
|
151
|
-
this.staticReferences.set("MICRONESIA", code_record["FM"]);
|
|
152
|
-
}
|
|
153
|
-
// Moldova
|
|
154
|
-
if (code_record["MD"]) {
|
|
155
|
-
fullname_record["MOLDOVA"] = code_record["MD"];
|
|
156
|
-
this.staticReferences.set("MOLDOVA", code_record["MD"]);
|
|
157
|
-
}
|
|
158
|
-
// Taiwan
|
|
159
|
-
if (code_record["TW"]) {
|
|
160
|
-
fullname_record["TAIWAN"] = code_record["TW"];
|
|
161
|
-
this.staticReferences.set("TAIWAN", code_record["TW"]);
|
|
162
|
-
}
|
|
163
|
-
// Tanzania
|
|
164
|
-
if (code_record["TZ"]) {
|
|
165
|
-
fullname_record["TANZANIA"] = code_record["TZ"];
|
|
166
|
-
this.staticReferences.set("TANZANIA", code_record["TZ"]);
|
|
167
|
-
}
|
|
168
214
|
// US Virgin Islands
|
|
169
215
|
if (code_record["VI"]) {
|
|
170
|
-
|
|
216
|
+
name_record["VIRGIN_ISLANDS_US"] = code_record["VI"];
|
|
171
217
|
this.staticReferences.set("VIRGIN_ISLANDS_US", code_record["VI"]);
|
|
172
218
|
}
|
|
173
219
|
// British Virgin Islands
|
|
174
220
|
if (code_record["VG"]) {
|
|
175
|
-
|
|
221
|
+
name_record["VIRGIN_ISLANDS_BRITISH"] = code_record["VG"];
|
|
176
222
|
this.staticReferences.set("VIRGIN_ISLANDS_BRITISH", code_record["VG"]);
|
|
177
223
|
}
|
|
224
|
+
// Democratic Republic of the Congo
|
|
225
|
+
if (code_record["CD"]) {
|
|
226
|
+
name_record["DEMOCRATIC_REPUBLIC_OF_CONGO"] = code_record["CD"];
|
|
227
|
+
this.staticReferences.set("DEMOCRATIC_REPUBLIC_OF_CONGO", code_record["CD"]);
|
|
228
|
+
}
|
|
229
|
+
// Falkland Islands (Malvinas)
|
|
230
|
+
if (code_record["FK"]) {
|
|
231
|
+
name_record["FALKLAND_ISLANDS"] = code_record["FK"];
|
|
232
|
+
this.staticReferences.set("FALKLAND_ISLANDS", code_record["FK"]);
|
|
233
|
+
}
|
|
234
|
+
// Lao
|
|
235
|
+
if (code_record["LA"]) {
|
|
236
|
+
name_record["LAO"] = code_record["LA"];
|
|
237
|
+
this.staticReferences.set("LAO", code_record["LA"]);
|
|
238
|
+
}
|
|
178
239
|
this.codeRecord = code_record;
|
|
240
|
+
this.iso3Record = iso3_record;
|
|
179
241
|
this.nameRecord = name_record;
|
|
180
|
-
this.fullNameRecord = fullname_record;
|
|
181
242
|
this.countryList = countries;
|
|
243
|
+
// Initialize static properties on Country class
|
|
244
|
+
this.initializeCountryStatics();
|
|
182
245
|
}
|
|
183
246
|
catch (error) {
|
|
184
247
|
console.error("Failed to initialize CountryService:", error);
|
|
185
248
|
}
|
|
186
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Initialize the static properties on the Country class
|
|
252
|
+
*/
|
|
253
|
+
initializeCountryStatics() {
|
|
254
|
+
// Initialize ISO-2 code properties
|
|
255
|
+
Object.entries(this.codeRecord).forEach(([code, country]) => {
|
|
256
|
+
// deno-lint-ignore no-explicit-any
|
|
257
|
+
country_js_1.Country[code.toUpperCase()] = country;
|
|
258
|
+
});
|
|
259
|
+
// Initialize full name properties
|
|
260
|
+
Object.entries(this.nameRecord).forEach(([fullName, country]) => {
|
|
261
|
+
// deno-lint-ignore no-explicit-any
|
|
262
|
+
country_js_1.Country[fullName] = country;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
187
265
|
/**
|
|
188
266
|
* Gets all countries.
|
|
189
267
|
* @returns {Country[]} Array of all countries
|
|
@@ -191,6 +269,13 @@ class CountryService {
|
|
|
191
269
|
getAll() {
|
|
192
270
|
return this.countryList;
|
|
193
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Gets static country references to be used by the Country class.
|
|
274
|
+
* @returns {Map<string, Country>} Map of static references
|
|
275
|
+
*/
|
|
276
|
+
getStaticReferences() {
|
|
277
|
+
return this.staticReferences;
|
|
278
|
+
}
|
|
194
279
|
/**
|
|
195
280
|
* Gets all countries as a record.
|
|
196
281
|
* @returns {Record<string, Country>} Record of country codes and country objects
|
|
@@ -199,44 +284,56 @@ class CountryService {
|
|
|
199
284
|
return this.codeRecord;
|
|
200
285
|
}
|
|
201
286
|
/**
|
|
202
|
-
* Gets
|
|
203
|
-
* @
|
|
287
|
+
* Gets all countries from a specific continent.
|
|
288
|
+
* @param {CONTINENT} continent The continent enum value
|
|
289
|
+
* @returns {Country[]} Array of countries in the specified continent
|
|
204
290
|
*/
|
|
205
|
-
|
|
206
|
-
return this.
|
|
291
|
+
getByContinent(continent) {
|
|
292
|
+
return this.continentRecord[continent] || [];
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Gets all countries from a specific region.
|
|
296
|
+
* @param {SUB_REGION} region The region enum value
|
|
297
|
+
* @returns {Country[]} Array of countries in the specified region
|
|
298
|
+
*/
|
|
299
|
+
getByRegion(region) {
|
|
300
|
+
return this.regionRecord[region] || [];
|
|
207
301
|
}
|
|
208
302
|
/**
|
|
209
303
|
* Gets the full name record mapping.
|
|
210
304
|
* @returns {Record<string, Country>} Record of uppercase full name keys to country objects
|
|
211
305
|
*/
|
|
212
306
|
getFullNameRecord() {
|
|
213
|
-
return this.
|
|
307
|
+
return this.nameRecord;
|
|
214
308
|
}
|
|
215
309
|
/**
|
|
216
|
-
* Retrieves a country by its ISO code.
|
|
217
|
-
* @param {string} code The ISO code of the country.
|
|
310
|
+
* Retrieves a country by its ISO-2 code.
|
|
311
|
+
* @param {string} code The ISO-2 code of the country.
|
|
218
312
|
* @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
|
|
219
313
|
*/
|
|
220
314
|
fromCode(code) {
|
|
221
315
|
return this.codeRecord[code.toUpperCase()];
|
|
222
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Retrieves a country by its ISO-3 code.
|
|
319
|
+
* @param {string} iso3 The ISO-3 code of the country.
|
|
320
|
+
* @returns {Country | undefined} The country corresponding to the ISO-3 code or `undefined` if not found.
|
|
321
|
+
*/
|
|
322
|
+
fromIso3(iso3) {
|
|
323
|
+
return this.iso3Record[iso3.toUpperCase()];
|
|
324
|
+
}
|
|
223
325
|
/**
|
|
224
326
|
* Retrieves a country by its name.
|
|
225
327
|
* @param {string} countryName The name of the country.
|
|
226
328
|
* @returns {Country | undefined} The country corresponding to the name or `undefined` if not found.
|
|
227
329
|
*/
|
|
228
330
|
fromName(countryName) {
|
|
229
|
-
// First try direct lookup in name record
|
|
230
|
-
const directMatch = this.nameRecord[countryName.toUpperCase()];
|
|
231
|
-
if (directMatch)
|
|
232
|
-
return directMatch;
|
|
233
|
-
// Then try full name record
|
|
234
331
|
const fullNameKey = countryName
|
|
235
332
|
.toUpperCase()
|
|
236
333
|
.replace(/\s+/g, "_")
|
|
237
334
|
.replace(/[-(),.']/g, "")
|
|
238
335
|
.replace(/&/g, "AND");
|
|
239
|
-
const fullNameMatch = this.
|
|
336
|
+
const fullNameMatch = this.nameRecord[fullNameKey];
|
|
240
337
|
if (fullNameMatch)
|
|
241
338
|
return fullNameMatch;
|
|
242
339
|
// If not found, try more lenient matching
|
|
@@ -255,7 +352,9 @@ class CountryService {
|
|
|
255
352
|
if (term.length === 0)
|
|
256
353
|
return [];
|
|
257
354
|
const results = this.countryList.filter((country) => country.name.toLowerCase().includes(term) ||
|
|
258
|
-
country.
|
|
355
|
+
country.nameOfficial.toLowerCase().includes(term) ||
|
|
356
|
+
country.code.toLowerCase().includes(term) ||
|
|
357
|
+
country.iso3.toLowerCase().includes(term));
|
|
259
358
|
return results.slice(0, limit);
|
|
260
359
|
}
|
|
261
360
|
/**
|