country-codes-library 1.1.3 → 2.0.0
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 +327 -44
- package/dist/countryData.d.ts +13 -0
- package/dist/countryData.js +39 -0
- package/dist/countryNames.d.ts +5 -0
- package/dist/countryNames.js +252 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +33 -1
- package/dist/types.d.ts +62 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +123 -0
- package/dist/utils.js +241 -0
- package/dist/validators.d.ts +94 -0
- package/dist/validators.js +225 -0
- package/package.json +29 -23
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CountryNames = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Mapping of PascalCase keys to proper country names
|
|
6
|
+
* This provides the canonical display names for all countries
|
|
7
|
+
*/
|
|
8
|
+
exports.CountryNames = {
|
|
9
|
+
Afghanistan: "Afghanistan",
|
|
10
|
+
AlandIslands: "Åland Islands",
|
|
11
|
+
Albania: "Albania",
|
|
12
|
+
Algeria: "Algeria",
|
|
13
|
+
AmericanSamoa: "American Samoa",
|
|
14
|
+
Andorra: "Andorra",
|
|
15
|
+
Angola: "Angola",
|
|
16
|
+
Anguilla: "Anguilla",
|
|
17
|
+
AntiguaandBarbuda: "Antigua and Barbuda",
|
|
18
|
+
Argentina: "Argentina",
|
|
19
|
+
Armenia: "Armenia",
|
|
20
|
+
Aruba: "Aruba",
|
|
21
|
+
Australia: "Australia",
|
|
22
|
+
Austria: "Austria",
|
|
23
|
+
Azerbaijan: "Azerbaijan",
|
|
24
|
+
Bahamas: "Bahamas",
|
|
25
|
+
Bahrain: "Bahrain",
|
|
26
|
+
Bangladesh: "Bangladesh",
|
|
27
|
+
Barbados: "Barbados",
|
|
28
|
+
Belarus: "Belarus",
|
|
29
|
+
Belgium: "Belgium",
|
|
30
|
+
Belize: "Belize",
|
|
31
|
+
Benin: "Benin",
|
|
32
|
+
Bermuda: "Bermuda",
|
|
33
|
+
Bhutan: "Bhutan",
|
|
34
|
+
Bolivia: "Bolivia",
|
|
35
|
+
BonaireSintEustatiusandSaba: "Bonaire, Sint Eustatius and Saba",
|
|
36
|
+
BosniaandHerzegovina: "Bosnia and Herzegovina",
|
|
37
|
+
Botswana: "Botswana",
|
|
38
|
+
Brazil: "Brazil",
|
|
39
|
+
BritishIndianOceanTerritory: "British Indian Ocean Territory",
|
|
40
|
+
BritishVirginIslands: "British Virgin Islands",
|
|
41
|
+
Brunei: "Brunei",
|
|
42
|
+
Bulgaria: "Bulgaria",
|
|
43
|
+
BurkinaFaso: "Burkina Faso",
|
|
44
|
+
Burundi: "Burundi",
|
|
45
|
+
CaboVerde: "Cabo Verde",
|
|
46
|
+
Cambodia: "Cambodia",
|
|
47
|
+
Cameroon: "Cameroon",
|
|
48
|
+
Canada: "Canada",
|
|
49
|
+
CaymanIslands: "Cayman Islands",
|
|
50
|
+
CentralAfricanRepublic: "Central African Republic",
|
|
51
|
+
Chad: "Chad",
|
|
52
|
+
Chile: "Chile",
|
|
53
|
+
China: "China",
|
|
54
|
+
ChristmasIsland: "Christmas Island",
|
|
55
|
+
Cocos_Keeling_Islands: "Cocos (Keeling) Islands",
|
|
56
|
+
Colombia: "Colombia",
|
|
57
|
+
Comoros: "Comoros",
|
|
58
|
+
Congo: "Congo",
|
|
59
|
+
Congo_DRC: "Congo (DRC)",
|
|
60
|
+
CookIslands: "Cook Islands",
|
|
61
|
+
CostaRica: "Costa Rica",
|
|
62
|
+
CotedIvoire: "Côte d'Ivoire",
|
|
63
|
+
Croatia: "Croatia",
|
|
64
|
+
Cuba: "Cuba",
|
|
65
|
+
Curacao: "Curaçao",
|
|
66
|
+
Cyprus: "Cyprus",
|
|
67
|
+
Czechia: "Czechia",
|
|
68
|
+
Denmark: "Denmark",
|
|
69
|
+
Djibouti: "Djibouti",
|
|
70
|
+
Dominica: "Dominica",
|
|
71
|
+
DominicanRepublic: "Dominican Republic",
|
|
72
|
+
Ecuador: "Ecuador",
|
|
73
|
+
Egypt: "Egypt",
|
|
74
|
+
ElSalvador: "El Salvador",
|
|
75
|
+
EquatorialGuinea: "Equatorial Guinea",
|
|
76
|
+
Eritrea: "Eritrea",
|
|
77
|
+
Estonia: "Estonia",
|
|
78
|
+
Eswatini: "Eswatini",
|
|
79
|
+
Ethiopia: "Ethiopia",
|
|
80
|
+
FalklandIslands: "Falkland Islands",
|
|
81
|
+
FaroeIslands: "Faroe Islands",
|
|
82
|
+
Fiji: "Fiji",
|
|
83
|
+
Finland: "Finland",
|
|
84
|
+
France: "France",
|
|
85
|
+
FrenchGuiana: "French Guiana",
|
|
86
|
+
FrenchPolynesia: "French Polynesia",
|
|
87
|
+
Gabon: "Gabon",
|
|
88
|
+
Gambia: "Gambia",
|
|
89
|
+
Georgia: "Georgia",
|
|
90
|
+
Germany: "Germany",
|
|
91
|
+
Ghana: "Ghana",
|
|
92
|
+
Gibraltar: "Gibraltar",
|
|
93
|
+
Greece: "Greece",
|
|
94
|
+
Greenland: "Greenland",
|
|
95
|
+
Grenada: "Grenada",
|
|
96
|
+
Guadeloupe: "Guadeloupe",
|
|
97
|
+
Guam: "Guam",
|
|
98
|
+
Guatemala: "Guatemala",
|
|
99
|
+
Guernsey: "Guernsey",
|
|
100
|
+
Guinea: "Guinea",
|
|
101
|
+
GuineaBissau: "Guinea-Bissau",
|
|
102
|
+
Guyana: "Guyana",
|
|
103
|
+
Haiti: "Haiti",
|
|
104
|
+
Honduras: "Honduras",
|
|
105
|
+
HongKongSAR: "Hong Kong SAR",
|
|
106
|
+
Hungary: "Hungary",
|
|
107
|
+
Iceland: "Iceland",
|
|
108
|
+
India: "India",
|
|
109
|
+
Indonesia: "Indonesia",
|
|
110
|
+
Iran: "Iran",
|
|
111
|
+
Iraq: "Iraq",
|
|
112
|
+
Ireland: "Ireland",
|
|
113
|
+
IsleofMan: "Isle of Man",
|
|
114
|
+
Israel: "Israel",
|
|
115
|
+
Italy: "Italy",
|
|
116
|
+
Jamaica: "Jamaica",
|
|
117
|
+
Japan: "Japan",
|
|
118
|
+
Jersey: "Jersey",
|
|
119
|
+
Jordan: "Jordan",
|
|
120
|
+
Kazakhstan: "Kazakhstan",
|
|
121
|
+
Kenya: "Kenya",
|
|
122
|
+
Kiribati: "Kiribati",
|
|
123
|
+
Korea: "Korea",
|
|
124
|
+
Kuwait: "Kuwait",
|
|
125
|
+
Kyrgyzstan: "Kyrgyzstan",
|
|
126
|
+
Laos: "Laos",
|
|
127
|
+
Latvia: "Latvia",
|
|
128
|
+
Lebanon: "Lebanon",
|
|
129
|
+
Lesotho: "Lesotho",
|
|
130
|
+
Liberia: "Liberia",
|
|
131
|
+
Libya: "Libya",
|
|
132
|
+
Liechtenstein: "Liechtenstein",
|
|
133
|
+
Lithuania: "Lithuania",
|
|
134
|
+
Luxembourg: "Luxembourg",
|
|
135
|
+
MacaoSAR: "Macao SAR",
|
|
136
|
+
Madagascar: "Madagascar",
|
|
137
|
+
Malawi: "Malawi",
|
|
138
|
+
Malaysia: "Malaysia",
|
|
139
|
+
Maldives: "Maldives",
|
|
140
|
+
Mali: "Mali",
|
|
141
|
+
Malta: "Malta",
|
|
142
|
+
MarshallIslands: "Marshall Islands",
|
|
143
|
+
Martinique: "Martinique",
|
|
144
|
+
Mauritania: "Mauritania",
|
|
145
|
+
Mauritius: "Mauritius",
|
|
146
|
+
Mayotte: "Mayotte",
|
|
147
|
+
Mexico: "Mexico",
|
|
148
|
+
Micronesia: "Micronesia",
|
|
149
|
+
Moldova: "Moldova",
|
|
150
|
+
Monaco: "Monaco",
|
|
151
|
+
Mongolia: "Mongolia",
|
|
152
|
+
Montenegro: "Montenegro",
|
|
153
|
+
Montserrat: "Montserrat",
|
|
154
|
+
Morocco: "Morocco",
|
|
155
|
+
Mozambique: "Mozambique",
|
|
156
|
+
Myanmar: "Myanmar",
|
|
157
|
+
Namibia: "Namibia",
|
|
158
|
+
Nauru: "Nauru",
|
|
159
|
+
Nepal: "Nepal",
|
|
160
|
+
Netherlands: "Netherlands",
|
|
161
|
+
NewCaledonia: "New Caledonia",
|
|
162
|
+
NewZealand: "New Zealand",
|
|
163
|
+
Nicaragua: "Nicaragua",
|
|
164
|
+
Niger: "Niger",
|
|
165
|
+
Nigeria: "Nigeria",
|
|
166
|
+
Niue: "Niue",
|
|
167
|
+
NorfolkIsland: "Norfolk Island",
|
|
168
|
+
NorthKorea: "North Korea",
|
|
169
|
+
NorthMacedonia: "North Macedonia",
|
|
170
|
+
NorthernMarianaIslands: "Northern Mariana Islands",
|
|
171
|
+
Norway: "Norway",
|
|
172
|
+
Oman: "Oman",
|
|
173
|
+
Pakistan: "Pakistan",
|
|
174
|
+
Palau: "Palau",
|
|
175
|
+
PalestinianAuthority: "Palestinian Authority",
|
|
176
|
+
Panama: "Panama",
|
|
177
|
+
PapuaNewGuinea: "Papua New Guinea",
|
|
178
|
+
Paraguay: "Paraguay",
|
|
179
|
+
Peru: "Peru",
|
|
180
|
+
Philippines: "Philippines",
|
|
181
|
+
PitcairnIslands: "Pitcairn Islands",
|
|
182
|
+
Poland: "Poland",
|
|
183
|
+
Portugal: "Portugal",
|
|
184
|
+
PuertoRico: "Puerto Rico",
|
|
185
|
+
Qatar: "Qatar",
|
|
186
|
+
Reunion: "Réunion",
|
|
187
|
+
Romania: "Romania",
|
|
188
|
+
Russia: "Russia",
|
|
189
|
+
Rwanda: "Rwanda",
|
|
190
|
+
Samoa: "Samoa",
|
|
191
|
+
SanMarino: "San Marino",
|
|
192
|
+
SaoTomeandPrincipe: "São Tomé and Príncipe",
|
|
193
|
+
SaudiArabia: "Saudi Arabia",
|
|
194
|
+
Senegal: "Senegal",
|
|
195
|
+
Serbia: "Serbia",
|
|
196
|
+
Seychelles: "Seychelles",
|
|
197
|
+
SierraLeone: "Sierra Leone",
|
|
198
|
+
Singapore: "Singapore",
|
|
199
|
+
SintMaarten: "Sint Maarten",
|
|
200
|
+
Slovakia: "Slovakia",
|
|
201
|
+
Slovenia: "Slovenia",
|
|
202
|
+
SolomonIslands: "Solomon Islands",
|
|
203
|
+
Somalia: "Somalia",
|
|
204
|
+
SouthAfrica: "South Africa",
|
|
205
|
+
SouthSudan: "South Sudan",
|
|
206
|
+
Spain: "Spain",
|
|
207
|
+
SriLanka: "Sri Lanka",
|
|
208
|
+
StHelenaAscensionTristandaCunha: "St. Helena, Ascension, Tristan da Cunha",
|
|
209
|
+
StBarthelemy: "St. Barthélemy",
|
|
210
|
+
StKittsandNevis: "St. Kitts and Nevis",
|
|
211
|
+
StLucia: "St. Lucia",
|
|
212
|
+
StMartin: "St. Martin",
|
|
213
|
+
StPierreandMiquelon: "St. Pierre and Miquelon",
|
|
214
|
+
StVincentandtheGrenadines: "St. Vincent and the Grenadines",
|
|
215
|
+
Sudan: "Sudan",
|
|
216
|
+
Suriname: "Suriname",
|
|
217
|
+
SvalbardandJanMayen: "Svalbard and Jan Mayen",
|
|
218
|
+
Sweden: "Sweden",
|
|
219
|
+
Switzerland: "Switzerland",
|
|
220
|
+
Syria: "Syria",
|
|
221
|
+
Taiwan: "Taiwan",
|
|
222
|
+
Tajikistan: "Tajikistan",
|
|
223
|
+
Tanzania: "Tanzania",
|
|
224
|
+
Thailand: "Thailand",
|
|
225
|
+
TimorLeste: "Timor-Leste",
|
|
226
|
+
Togo: "Togo",
|
|
227
|
+
Tokelau: "Tokelau",
|
|
228
|
+
Tonga: "Tonga",
|
|
229
|
+
TrinidadandTobago: "Trinidad and Tobago",
|
|
230
|
+
Tunisia: "Tunisia",
|
|
231
|
+
Turkey: "Turkey",
|
|
232
|
+
Turkmenistan: "Turkmenistan",
|
|
233
|
+
TurksandCaicosIslands: "Turks and Caicos Islands",
|
|
234
|
+
Tuvalu: "Tuvalu",
|
|
235
|
+
USOutlyingIslands: "U.S. Outlying Islands",
|
|
236
|
+
USVirginIslands: "U.S. Virgin Islands",
|
|
237
|
+
Uganda: "Uganda",
|
|
238
|
+
Ukraine: "Ukraine",
|
|
239
|
+
UnitedArabEmirates: "United Arab Emirates",
|
|
240
|
+
UnitedKingdom: "United Kingdom",
|
|
241
|
+
UnitedStates: "United States",
|
|
242
|
+
Uruguay: "Uruguay",
|
|
243
|
+
Uzbekistan: "Uzbekistan",
|
|
244
|
+
Vanuatu: "Vanuatu",
|
|
245
|
+
VaticanCity: "Vatican City",
|
|
246
|
+
Venezuela: "Venezuela",
|
|
247
|
+
Vietnam: "Vietnam",
|
|
248
|
+
WallisandFutuna: "Wallis and Futuna",
|
|
249
|
+
Yemen: "Yemen",
|
|
250
|
+
Zambia: "Zambia",
|
|
251
|
+
Zimbabwe: "Zimbabwe"
|
|
252
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,3 +6,8 @@ export { CountryCurrencyCodes } from './countryCurrencyCodes';
|
|
|
6
6
|
export { ChinaProvinceCode } from './China/chinaProvinceCode';
|
|
7
7
|
export { CanadaProvinceCode } from './Canada/canadaProvinceCode';
|
|
8
8
|
export { USAStateCode } from './UnitedStates/USAStateCode';
|
|
9
|
+
export { CountryData, getAllCountries, getAllCountryNames } from './countryData';
|
|
10
|
+
export { CountryNames } from './countryNames';
|
|
11
|
+
export type { Country, LookupResult, SearchOptions, PhoneValidationResult, CountryName, CountryCode2, CountryCode3 } from './types';
|
|
12
|
+
export { getCountryByCode2, getCountryByCode3, getCountryByName, getCountriesByCurrency, getCountriesByCallingCode, searchCountries, convertCountryCode, getCallingCode, getCurrencyCode, getCurrencySymbol, getAllCurrencies, getAllCallingCodes } from './utils';
|
|
13
|
+
export { isValidCountryCode2, isValidCountryCode3, isValidCountryCode, isValidCountryName, isValidCurrencyCode, isValidCallingCode, validatePhoneNumber, parsePhoneNumber } from './validators';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.USAStateCode = exports.CanadaProvinceCode = exports.ChinaProvinceCode = exports.CountryCurrencyCodes = exports.CountryCurrencySymbols = exports.CountryCallingCodes = exports.ThreeLetterISORegionCode = exports.TwoLetterISORegionCode = void 0;
|
|
3
|
+
exports.parsePhoneNumber = exports.validatePhoneNumber = exports.isValidCallingCode = exports.isValidCurrencyCode = exports.isValidCountryName = exports.isValidCountryCode = exports.isValidCountryCode3 = exports.isValidCountryCode2 = exports.getAllCallingCodes = exports.getAllCurrencies = exports.getCurrencySymbol = exports.getCurrencyCode = exports.getCallingCode = exports.convertCountryCode = exports.searchCountries = exports.getCountriesByCallingCode = exports.getCountriesByCurrency = exports.getCountryByName = exports.getCountryByCode3 = exports.getCountryByCode2 = exports.CountryNames = exports.getAllCountryNames = exports.getAllCountries = exports.CountryData = exports.USAStateCode = exports.CanadaProvinceCode = exports.ChinaProvinceCode = exports.CountryCurrencyCodes = exports.CountryCurrencySymbols = exports.CountryCallingCodes = exports.ThreeLetterISORegionCode = exports.TwoLetterISORegionCode = void 0;
|
|
4
|
+
// Original exports - backwards compatible
|
|
4
5
|
var twoLetterISORegionCode_1 = require("./twoLetterISORegionCode");
|
|
5
6
|
Object.defineProperty(exports, "TwoLetterISORegionCode", { enumerable: true, get: function () { return twoLetterISORegionCode_1.TwoLetterISORegionCode; } });
|
|
6
7
|
var threeLetterISORegionCode_1 = require("./threeLetterISORegionCode");
|
|
@@ -17,3 +18,34 @@ var canadaProvinceCode_1 = require("./Canada/canadaProvinceCode");
|
|
|
17
18
|
Object.defineProperty(exports, "CanadaProvinceCode", { enumerable: true, get: function () { return canadaProvinceCode_1.CanadaProvinceCode; } });
|
|
18
19
|
var USAStateCode_1 = require("./UnitedStates/USAStateCode");
|
|
19
20
|
Object.defineProperty(exports, "USAStateCode", { enumerable: true, get: function () { return USAStateCode_1.USAStateCode; } });
|
|
21
|
+
// New unified country data
|
|
22
|
+
var countryData_1 = require("./countryData");
|
|
23
|
+
Object.defineProperty(exports, "CountryData", { enumerable: true, get: function () { return countryData_1.CountryData; } });
|
|
24
|
+
Object.defineProperty(exports, "getAllCountries", { enumerable: true, get: function () { return countryData_1.getAllCountries; } });
|
|
25
|
+
Object.defineProperty(exports, "getAllCountryNames", { enumerable: true, get: function () { return countryData_1.getAllCountryNames; } });
|
|
26
|
+
var countryNames_1 = require("./countryNames");
|
|
27
|
+
Object.defineProperty(exports, "CountryNames", { enumerable: true, get: function () { return countryNames_1.CountryNames; } });
|
|
28
|
+
// Utility functions
|
|
29
|
+
var utils_1 = require("./utils");
|
|
30
|
+
Object.defineProperty(exports, "getCountryByCode2", { enumerable: true, get: function () { return utils_1.getCountryByCode2; } });
|
|
31
|
+
Object.defineProperty(exports, "getCountryByCode3", { enumerable: true, get: function () { return utils_1.getCountryByCode3; } });
|
|
32
|
+
Object.defineProperty(exports, "getCountryByName", { enumerable: true, get: function () { return utils_1.getCountryByName; } });
|
|
33
|
+
Object.defineProperty(exports, "getCountriesByCurrency", { enumerable: true, get: function () { return utils_1.getCountriesByCurrency; } });
|
|
34
|
+
Object.defineProperty(exports, "getCountriesByCallingCode", { enumerable: true, get: function () { return utils_1.getCountriesByCallingCode; } });
|
|
35
|
+
Object.defineProperty(exports, "searchCountries", { enumerable: true, get: function () { return utils_1.searchCountries; } });
|
|
36
|
+
Object.defineProperty(exports, "convertCountryCode", { enumerable: true, get: function () { return utils_1.convertCountryCode; } });
|
|
37
|
+
Object.defineProperty(exports, "getCallingCode", { enumerable: true, get: function () { return utils_1.getCallingCode; } });
|
|
38
|
+
Object.defineProperty(exports, "getCurrencyCode", { enumerable: true, get: function () { return utils_1.getCurrencyCode; } });
|
|
39
|
+
Object.defineProperty(exports, "getCurrencySymbol", { enumerable: true, get: function () { return utils_1.getCurrencySymbol; } });
|
|
40
|
+
Object.defineProperty(exports, "getAllCurrencies", { enumerable: true, get: function () { return utils_1.getAllCurrencies; } });
|
|
41
|
+
Object.defineProperty(exports, "getAllCallingCodes", { enumerable: true, get: function () { return utils_1.getAllCallingCodes; } });
|
|
42
|
+
// Validation functions
|
|
43
|
+
var validators_1 = require("./validators");
|
|
44
|
+
Object.defineProperty(exports, "isValidCountryCode2", { enumerable: true, get: function () { return validators_1.isValidCountryCode2; } });
|
|
45
|
+
Object.defineProperty(exports, "isValidCountryCode3", { enumerable: true, get: function () { return validators_1.isValidCountryCode3; } });
|
|
46
|
+
Object.defineProperty(exports, "isValidCountryCode", { enumerable: true, get: function () { return validators_1.isValidCountryCode; } });
|
|
47
|
+
Object.defineProperty(exports, "isValidCountryName", { enumerable: true, get: function () { return validators_1.isValidCountryName; } });
|
|
48
|
+
Object.defineProperty(exports, "isValidCurrencyCode", { enumerable: true, get: function () { return validators_1.isValidCurrencyCode; } });
|
|
49
|
+
Object.defineProperty(exports, "isValidCallingCode", { enumerable: true, get: function () { return validators_1.isValidCallingCode; } });
|
|
50
|
+
Object.defineProperty(exports, "validatePhoneNumber", { enumerable: true, get: function () { return validators_1.validatePhoneNumber; } });
|
|
51
|
+
Object.defineProperty(exports, "parsePhoneNumber", { enumerable: true, get: function () { return validators_1.parsePhoneNumber; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a country with all available information
|
|
3
|
+
*/
|
|
4
|
+
export interface Country {
|
|
5
|
+
/** Full country name (e.g., "United States") */
|
|
6
|
+
name: string;
|
|
7
|
+
/** ISO 3166-1 alpha-2 code (e.g., "US") */
|
|
8
|
+
code2: string;
|
|
9
|
+
/** ISO 3166-1 alpha-3 code (e.g., "USA") */
|
|
10
|
+
code3: string;
|
|
11
|
+
/** International calling code (e.g., "+1") */
|
|
12
|
+
callingCode: string;
|
|
13
|
+
/** ISO 4217 currency code (e.g., "USD") */
|
|
14
|
+
currencyCode: string;
|
|
15
|
+
/** Currency symbol (e.g., "$") */
|
|
16
|
+
currencySymbol: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of a reverse lookup operation
|
|
20
|
+
*/
|
|
21
|
+
export interface LookupResult {
|
|
22
|
+
/** Country name */
|
|
23
|
+
country: string;
|
|
24
|
+
/** ISO 3166-1 alpha-2 code */
|
|
25
|
+
code2: string;
|
|
26
|
+
/** ISO 3166-1 alpha-3 code */
|
|
27
|
+
code3: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for search and filter operations
|
|
31
|
+
*/
|
|
32
|
+
export interface SearchOptions {
|
|
33
|
+
/** Case-sensitive search */
|
|
34
|
+
caseSensitive?: boolean;
|
|
35
|
+
/** Exact match only */
|
|
36
|
+
exactMatch?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Phone number validation result
|
|
40
|
+
*/
|
|
41
|
+
export interface PhoneValidationResult {
|
|
42
|
+
/** Whether the phone number is valid */
|
|
43
|
+
isValid: boolean;
|
|
44
|
+
/** Formatted phone number */
|
|
45
|
+
formatted?: string;
|
|
46
|
+
/** Country code detected */
|
|
47
|
+
countryCode?: string;
|
|
48
|
+
/** Error message if invalid */
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Union type of all country names for better autocomplete
|
|
53
|
+
*/
|
|
54
|
+
export type CountryName = keyof typeof import('./twoLetterISORegionCode').TwoLetterISORegionCode;
|
|
55
|
+
/**
|
|
56
|
+
* Union type of all 2-letter country codes
|
|
57
|
+
*/
|
|
58
|
+
export type CountryCode2 = string;
|
|
59
|
+
/**
|
|
60
|
+
* Union type of all 3-letter country codes
|
|
61
|
+
*/
|
|
62
|
+
export type CountryCode3 = string;
|
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Country, SearchOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get country information by 2-letter ISO code
|
|
4
|
+
* @param code - ISO 3166-1 alpha-2 code (e.g., "US", "GB", "CN")
|
|
5
|
+
* @returns Country object or null if not found
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const country = getCountryByCode2("US");
|
|
9
|
+
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function getCountryByCode2(code: string): Country | null;
|
|
13
|
+
/**
|
|
14
|
+
* Get country information by 3-letter ISO code
|
|
15
|
+
* @param code - ISO 3166-1 alpha-3 code (e.g., "USA", "GBR", "CHN")
|
|
16
|
+
* @returns Country object or null if not found
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const country = getCountryByCode3("USA");
|
|
20
|
+
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function getCountryByCode3(code: string): Country | null;
|
|
24
|
+
/**
|
|
25
|
+
* Get country information by name
|
|
26
|
+
* @param name - Country name (e.g., "UnitedStates", "United States")
|
|
27
|
+
* @returns Country object or null if not found
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const country = getCountryByName("UnitedStates");
|
|
31
|
+
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function getCountryByName(name: string): Country | null;
|
|
35
|
+
/**
|
|
36
|
+
* Get all countries that use a specific currency
|
|
37
|
+
* @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
|
|
38
|
+
* @returns Array of countries using the currency
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const countries = getCountriesByCurrency("EUR");
|
|
42
|
+
* // Returns array of European countries using Euro
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCountriesByCurrency(currencyCode: string): Country[];
|
|
46
|
+
/**
|
|
47
|
+
* Get all countries with a specific calling code
|
|
48
|
+
* @param callingCode - International calling code (e.g., "+1", "+44")
|
|
49
|
+
* @returns Array of countries with the calling code
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const countries = getCountriesByCallingCode("+1");
|
|
53
|
+
* // Returns: [USA, Canada, and other +1 countries]
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCountriesByCallingCode(callingCode: string): Country[];
|
|
57
|
+
/**
|
|
58
|
+
* Search countries by name (supports partial matching)
|
|
59
|
+
* @param query - Search query
|
|
60
|
+
* @param options - Search options
|
|
61
|
+
* @returns Array of matching countries
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const results = searchCountries("united");
|
|
65
|
+
* // Returns: [UnitedStates, UnitedKingdom, UnitedArabEmirates]
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function searchCountries(query: string, options?: SearchOptions): Country[];
|
|
69
|
+
/**
|
|
70
|
+
* Convert between 2-letter and 3-letter country codes
|
|
71
|
+
* @param code - Country code to convert
|
|
72
|
+
* @param targetFormat - Target format ('code2' or 'code3')
|
|
73
|
+
* @returns Converted code or null if not found
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* convertCountryCode("US", "code3"); // Returns: "USA"
|
|
77
|
+
* convertCountryCode("GBR", "code2"); // Returns: "GB"
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function convertCountryCode(code: string, targetFormat: 'code2' | 'code3'): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Get calling code for a country
|
|
83
|
+
* @param countryIdentifier - Country name, code2, or code3
|
|
84
|
+
* @returns Calling code or null if not found
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* getCallingCode("US"); // Returns: "+1"
|
|
88
|
+
* getCallingCode("UnitedStates"); // Returns: "+1"
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function getCallingCode(countryIdentifier: string): string | null;
|
|
92
|
+
/**
|
|
93
|
+
* Get currency code for a country
|
|
94
|
+
* @param countryIdentifier - Country name, code2, or code3
|
|
95
|
+
* @returns Currency code or null if not found
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* getCurrencyCode("US"); // Returns: "USD"
|
|
99
|
+
* getCurrencyCode("Germany"); // Returns: "EUR"
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function getCurrencyCode(countryIdentifier: string): string | null;
|
|
103
|
+
/**
|
|
104
|
+
* Get currency symbol for a country
|
|
105
|
+
* @param countryIdentifier - Country name, code2, or code3
|
|
106
|
+
* @returns Currency symbol or null if not found
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* getCurrencySymbol("US"); // Returns: "$"
|
|
110
|
+
* getCurrencySymbol("Japan"); // Returns: "¥"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function getCurrencySymbol(countryIdentifier: string): string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Get all unique currencies used worldwide
|
|
116
|
+
* @returns Array of unique currency codes
|
|
117
|
+
*/
|
|
118
|
+
export declare function getAllCurrencies(): string[];
|
|
119
|
+
/**
|
|
120
|
+
* Get all unique calling codes
|
|
121
|
+
* @returns Array of unique calling codes
|
|
122
|
+
*/
|
|
123
|
+
export declare function getAllCallingCodes(): string[];
|