continent-country-utils
Version:
Utility functions for continent and country lookup by ISO3 or name
1,281 lines (1,271 loc) • 26.1 kB
text/typescript
export interface Country {
country: string;
continent: string;
ISO_3: string;
}
export interface ContinentCountries {
continent: string;
country: Country[];
}
const continentWiseCountryList: ContinentCountries[] = [
{
continent: "Asia",
country: [
{
country: "Afghanistan",
continent: "Asia",
ISO_3: "AFG",
},
{
country: "Armenia",
continent: "Asia",
ISO_3: "ARM",
},
{
country: "Azerbaijan",
continent: "Asia",
ISO_3: "AZE",
},
{
country: "Bahrain",
continent: "Asia",
ISO_3: "BHR",
},
{
country: "Bangladesh",
continent: "Asia",
ISO_3: "BGD",
},
{
country: "Bhutan",
continent: "Asia",
ISO_3: "BTN",
},
{
country: "Brunei Darussalam",
continent: "Asia",
ISO_3: "BRN",
},
{
country: "Cambodia",
continent: "Asia",
ISO_3: "KHM",
},
{
country: "China",
continent: "Asia",
ISO_3: "CHN",
},
{
country: "Cyprus",
continent: "Asia",
ISO_3: "CYP",
},
{
country: "Georgia",
continent: "Asia",
ISO_3: "GEO",
},
{
country: "Hong Kong",
continent: "Asia",
ISO_3: "HKG",
},
{
country: "India",
continent: "Asia",
ISO_3: "IND",
},
{
country: "Indonesia",
continent: "Asia",
ISO_3: "IDN",
},
{
country: "Iraq",
continent: "Asia",
ISO_3: "IRQ",
},
{
country: "Israel",
continent: "Asia",
ISO_3: "ISR",
},
{
country: "Iran",
continent: "Asia",
ISO_3: "IRN",
},
{
country: "Japan",
continent: "Asia",
ISO_3: "JPN",
},
{
country: "Jordan",
continent: "Asia",
ISO_3: "JOR",
},
{
country: "Kazakhstan",
continent: "Asia",
ISO_3: "KAZ",
},
{
country: "Kuwait",
continent: "Asia",
ISO_3: "KWT",
},
{
country: "Kyrgyzstan",
continent: "Asia",
ISO_3: "KGZ",
},
{
country: "Lebanon",
continent: "Asia",
ISO_3: "LBN",
},
{
country: "Lao People's Democratic Republic",
continent: "Asia",
ISO_3: "LAO",
},
{
country: "Macao",
continent: "Asia",
ISO_3: "MAC",
},
{
country: "Malaysia",
continent: "Asia",
ISO_3: "MYS",
},
{
country: "Maldives",
continent: "Asia",
ISO_3: "MDV",
},
{
country: "Mongolia",
continent: "Asia",
ISO_3: "MNG",
},
{
country: "Myanmar",
continent: "Asia",
ISO_3: "MMR",
},
{
country: "Nepal",
continent: "Asia",
ISO_3: "NPL",
},
{
country: "Oman",
continent: "Asia",
ISO_3: "OMN",
},
{
country: "Pakistan",
continent: "Asia",
ISO_3: "PAK",
},
{
country: "Philippines",
continent: "Asia",
ISO_3: "PHL",
},
{
country: "Qatar",
continent: "Asia",
ISO_3: "QAT",
},
{
country: "Russian Federation",
continent: "Asia",
ISO_3: "RUS",
},
{
country: "Saudi Arabia",
continent: "Asia",
ISO_3: "SAU",
},
{
country: "South Korea",
continent: "Asia",
ISO_3: "KOR",
},
{
country: "Singapore",
continent: "Asia",
ISO_3: "SGP",
},
{
country: "Sri Lanka",
continent: "Asia",
ISO_3: "LKA",
},
{
country: "Tajikistan",
continent: "Asia",
ISO_3: "TJK",
},
{
country: "Thailand",
continent: "Asia",
ISO_3: "THA",
},
{
country: "Turkey",
continent: "Asia",
ISO_3: "TUR",
},
{
country: "Turkmenistan",
continent: "Asia",
ISO_3: "TKM",
},
{
country: "Taiwan",
continent: "Asia",
ISO_3: "TWN",
},
{
country: "United Arab Emirates",
continent: "Asia",
ISO_3: "ARE",
},
{
country: "Uzbekistan",
continent: "Asia",
ISO_3: "UZB",
},
{
country: "Vietnam",
continent: "Asia",
ISO_3: "VNM",
},
{
country: "Yemen",
continent: "Asia",
ISO_3: "YEM",
},
],
},
{
continent: "Europe",
country: [
{
country: "Albania",
continent: "Europe",
ISO_3: "ALB",
},
{
country: "Andorra",
continent: "Europe",
ISO_3: "AND",
},
{
country: "Austria",
continent: "Europe",
ISO_3: "AUT",
},
{
country: "Belarus",
continent: "Europe",
ISO_3: "BLR",
},
{
country: "Belgium",
continent: "Europe",
ISO_3: "BEL",
},
{
country: "Bosnia and Herzegovina",
continent: "Europe",
ISO_3: "BIH",
},
{
country: "Bulgaria",
continent: "Europe",
ISO_3: "BGR",
},
{
country: "Croatia",
continent: "Europe",
ISO_3: "HRV",
},
{
country: "Czech Republic",
continent: "Europe",
ISO_3: "CZE",
},
{
country: "Denmark",
continent: "Europe",
ISO_3: "DNK",
},
{
country: "Estonia",
continent: "Europe",
ISO_3: "EST",
},
{
country: "Faroe Islands",
continent: "Europe",
ISO_3: "FRO",
},
{
country: "Finland",
continent: "Europe",
ISO_3: "FIN",
},
{
country: "France",
continent: "Europe",
ISO_3: "FRA",
},
{
country: "Germany",
continent: "Europe",
ISO_3: "DEU",
},
{
country: "Gibraltar",
continent: "Europe",
ISO_3: "GIB",
},
{
country: "Greece",
continent: "Europe",
ISO_3: "GRC",
},
{
country: "Holy See (Vatican City State)",
continent: "Europe",
ISO_3: "VAT",
},
{
country: "Hungary",
continent: "Europe",
ISO_3: "HUN",
},
{
country: "Iceland",
continent: "Europe",
ISO_3: "ISL",
},
{
country: "Ireland",
continent: "Europe",
ISO_3: "IRL",
},
{
country: "Italy",
continent: "Europe",
ISO_3: "ITA",
},
{
country: "Latvia",
continent: "Europe",
ISO_3: "LVA",
},
{
country: "Liechtenstein",
continent: "Europe",
ISO_3: "LIE",
},
{
country: "Lithuania",
continent: "Europe",
ISO_3: "LTU",
},
{
country: "Luxembourg",
continent: "Europe",
ISO_3: "LUX",
},
{
country: "Malta",
continent: "Europe",
ISO_3: "MLT",
},
{
country: "Monaco",
continent: "Europe",
ISO_3: "MCO",
},
{
country: "Montenegro",
continent: "Europe",
ISO_3: "MNE",
},
{
country: "Netherlands",
continent: "Europe",
ISO_3: "NLD",
},
{
country: "Norway",
continent: "Europe",
ISO_3: "NOR",
},
{
country: "Poland",
continent: "Europe",
ISO_3: "POL",
},
{
country: "Portugal",
continent: "Europe",
ISO_3: "PRT",
},
{
country: "Romania",
continent: "Europe",
ISO_3: "ROU",
},
{
country: "San Marino",
continent: "Europe",
ISO_3: "SMR",
},
{
country: "Serbia",
continent: "Europe",
ISO_3: "SRB",
},
{
country: "Slovakia",
continent: "Europe",
ISO_3: "SVK",
},
{
country: "Slovenia",
continent: "Europe",
ISO_3: "SVN",
},
{
country: "Spain",
continent: "Europe",
ISO_3: "ESP",
},
{
country: "Svalbard and Jan Mayen",
continent: "Europe",
ISO_3: "SJM",
},
{
country: "Sweden",
continent: "Europe",
ISO_3: "SWE",
},
{
country: "Switzerland",
continent: "Europe",
ISO_3: "CHE",
},
{
country: "Ukraine",
continent: "Europe",
ISO_3: "UKR",
},
{
country: "United Kingdom - Scotland",
continent: "Europe",
ISO_3: "SCT",
},
{
country: "United Kingdom",
continent: "Europe",
ISO_3: "GBR",
},
{
country: "Isle of Man",
continent: "Europe",
ISO_3: "IMN",
},
{
country: "Guernsey",
continent: "Europe",
ISO_3: "GGY",
},
{
country: "Jersey",
continent: "Europe",
ISO_3: "JEY",
},
],
},
{
continent: "Africa",
country: [
{
country: "Algeria",
continent: "Africa",
ISO_3: "DZA",
},
{
country: "Angola",
continent: "Africa",
ISO_3: "AGO",
},
{
country: "Benin",
continent: "Africa",
ISO_3: "BEN",
},
{
country: "Botswana",
continent: "Africa",
ISO_3: "BWA",
},
{
country: "British Indian Ocean Territory",
continent: "Africa",
ISO_3: "IOT",
},
{
country: "Burkina Faso",
continent: "Africa",
ISO_3: "BFA",
},
{
country: "Burundi",
continent: "Africa",
ISO_3: "BDI",
},
{
country: "Cameroon",
continent: "Africa",
ISO_3: "CMR",
},
{
country: "Cape Verde",
continent: "Africa",
ISO_3: "CPV",
},
{
country: "Central African Republic",
continent: "Africa",
ISO_3: "CAF",
},
{
country: "Chad",
continent: "Africa",
ISO_3: "TCD",
},
{
country: "Comoros",
continent: "Africa",
ISO_3: "COM",
},
{
country: "Congo",
continent: "Africa",
ISO_3: "COG",
},
{
country: "Côte d'Ivoire",
continent: "Africa",
ISO_3: "CIV",
},
{
country: "Djibouti",
continent: "Africa",
ISO_3: "DJI",
},
{
country: "Egypt",
continent: "Africa",
ISO_3: "EGY",
},
{
country: "Equatorial Guinea",
continent: "Africa",
ISO_3: "GNQ",
},
{
country: "Eritrea",
continent: "Africa",
ISO_3: "ERI",
},
{
country: "Ethiopia",
continent: "Africa",
ISO_3: "ETH",
},
{
country: "Gabon",
continent: "Africa",
ISO_3: "GAB",
},
{
country: "Gambia",
continent: "Africa",
ISO_3: "GMB",
},
{
country: "Ghana",
continent: "Africa",
ISO_3: "GHA",
},
{
country: "Guinea",
continent: "Africa",
ISO_3: "GIN",
},
{
country: "Guinea-Bissau",
continent: "Africa",
ISO_3: "GNB",
},
{
country: "Kenya",
continent: "Africa",
ISO_3: "KEN",
},
{
country: "Lesotho",
continent: "Africa",
ISO_3: "LSO",
},
{
country: "Liberia",
continent: "Africa",
ISO_3: "LBR",
},
{
country: "Libya",
continent: "Africa",
ISO_3: "LBY",
},
{
country: "Madagascar",
continent: "Africa",
ISO_3: "MDG",
},
{
country: "Malawi",
continent: "Africa",
ISO_3: "MWI",
},
{
country: "Mali",
continent: "Africa",
ISO_3: "MLI",
},
{
country: "Mauritania",
continent: "Africa",
ISO_3: "MRT",
},
{
country: "Mauritius",
continent: "Africa",
ISO_3: "MUS",
},
{
country: "Mayotte",
continent: "Africa",
ISO_3: "MYT",
},
{
country: "Morocco",
continent: "Africa",
ISO_3: "MAR",
},
{
country: "Mozambique",
continent: "Africa",
ISO_3: "MOZ",
},
{
country: "Namibia",
continent: "Africa",
ISO_3: "NAM",
},
{
country: "Niger",
continent: "Africa",
ISO_3: "NER",
},
{
country: "Nigeria",
continent: "Africa",
ISO_3: "NGA",
},
{
country: "Rwanda",
continent: "Africa",
ISO_3: "RWA",
},
{
country: "Sao Tome and Principe",
continent: "Africa",
ISO_3: "STP",
},
{
country: "Senegal",
continent: "Africa",
ISO_3: "SEN",
},
{
country: "Seychelles",
continent: "Africa",
ISO_3: "SYC",
},
{
country: "Sierra Leone",
continent: "Africa",
ISO_3: "SLE",
},
{
country: "Somalia",
continent: "Africa",
ISO_3: "SOM",
},
{
country: "South Africa",
continent: "Africa",
ISO_3: "ZAF",
},
{
country: "South Sudan",
continent: "Africa",
ISO_3: "SSD",
},
{
country: "Sudan",
continent: "Africa",
ISO_3: "SDN",
},
{
country: "Togo",
continent: "Africa",
ISO_3: "TGO",
},
{
country: "Tunisia",
continent: "Africa",
ISO_3: "TUN",
},
{
country: "Tanzania",
continent: "Africa",
ISO_3: "TZA",
},
{
country: "Uganda",
continent: "Africa",
ISO_3: "UGA",
},
{
country: "Western Sahara",
continent: "Africa",
ISO_3: "ESH",
},
{
country: "Zambia",
continent: "Africa",
ISO_3: "ZMB",
},
{
country: "Zimbabwe",
continent: "Africa",
ISO_3: "ZWE",
},
],
},
{
continent: "Oceania",
country: [
{
country: "American Samoa",
continent: "Oceania",
ISO_3: "ASM",
},
{
country: "Australia",
continent: "Oceania",
ISO_3: "AUS",
},
{
country: "Christmas Island",
continent: "Oceania",
ISO_3: "CXR",
},
{
country: "Cocos (Keeling) Islands",
continent: "Oceania",
ISO_3: "CCK",
},
{
country: "Cook Islands",
continent: "Oceania",
ISO_3: "COK",
},
{
country: "French Polynesia",
continent: "Oceania",
ISO_3: "PYF",
},
{
country: "Fiji",
continent: "Oceania",
ISO_3: "FJI",
},
{
country: "Guam",
continent: "Oceania",
ISO_3: "GUM",
},
{
country: "Kiribati",
continent: "Oceania",
ISO_3: "KIR",
},
{
country: "Marshall Islands",
continent: "Oceania",
ISO_3: "MHL",
},
{
country: "Micronesia, Federated States of",
continent: "Oceania",
ISO_3: "FSM",
},
{
country: "Nauru",
continent: "Oceania",
ISO_3: "NRU",
},
{
country: "New Caledonia",
continent: "Oceania",
ISO_3: "NCL",
},
{
country: "New Zealand",
continent: "Oceania",
ISO_3: "NZL",
},
{
country: "Niue",
continent: "Oceania",
ISO_3: "NIU",
},
{
country: "Norfolk Island",
continent: "Oceania",
ISO_3: "NFK",
},
{
country: "Northern Mariana Islands",
continent: "Oceania",
ISO_3: "MNP",
},
{
country: "Palau",
continent: "Oceania",
ISO_3: "PLW",
},
{
country: "Papua New Guinea",
continent: "Oceania",
ISO_3: "PNG",
},
{
country: "Pitcairn",
continent: "Oceania",
ISO_3: "PCN",
},
{
country: "Samoa",
continent: "Oceania",
ISO_3: "WSM",
},
{
country: "Solomon Islands",
continent: "Oceania",
ISO_3: "SLB",
},
{
country: "Tokelau",
continent: "Oceania",
ISO_3: "TKL",
},
{
country: "Tonga",
continent: "Oceania",
ISO_3: "TON",
},
{
country: "Tuvalu",
continent: "Oceania",
ISO_3: "TUV",
},
{
country: "United States Minor Outlying Islands",
continent: "Oceania",
ISO_3: "UMI",
},
{
country: "Vanuatu",
continent: "Oceania",
ISO_3: "VUT",
},
{
country: "Wallis and Futuna",
continent: "Oceania",
ISO_3: "WLF",
},
],
},
{
continent: "North America",
country: [
{
country: "Anguilla",
continent: "North America",
ISO_3: "AIA",
},
{
country: "Antigua and Barbuda",
continent: "North America",
ISO_3: "ATG",
},
{
country: "Aruba",
continent: "North America",
ISO_3: "ABW",
},
{
country: "Bahamas",
continent: "North America",
ISO_3: "BHS",
},
{
country: "Barbados",
continent: "North America",
ISO_3: "BRB",
},
{
country: "Belize",
continent: "North America",
ISO_3: "BLZ",
},
{
country: "Bermuda",
continent: "North America",
ISO_3: "BMU",
},
{
country: "Canada",
continent: "North America",
ISO_3: "CAN",
},
{
country: "Cayman Islands",
continent: "North America",
ISO_3: "CYM",
},
{
country: "Costa Rica",
continent: "North America",
ISO_3: "CRI",
},
{
country: "Cuba",
continent: "North America",
ISO_3: "CUB",
},
{
country: "Dominica",
continent: "North America",
ISO_3: "DMA",
},
{
country: "Dominican Republic",
continent: "North America",
ISO_3: "DOM",
},
{
country: "El Salvador",
continent: "North America",
ISO_3: "SLV",
},
{
country: "Greenland",
continent: "North America",
ISO_3: "GRL",
},
{
country: "Grenada",
continent: "North America",
ISO_3: "GRD",
},
{
country: "Guadeloupe",
continent: "North America",
ISO_3: "GLP",
},
{
country: "Guatemala",
continent: "North America",
ISO_3: "GTM",
},
{
country: "Haiti",
continent: "North America",
ISO_3: "HTI",
},
{
country: "Honduras",
continent: "North America",
ISO_3: "HND",
},
{
country: "Jamaica",
continent: "North America",
ISO_3: "JAM",
},
{
country: "Martinique",
continent: "North America",
ISO_3: "MTQ",
},
{
country: "Mexico",
continent: "North America",
ISO_3: "MEX",
},
{
country: "Montserrat",
continent: "North America",
ISO_3: "MSR",
},
{
country: "Nicaragua",
continent: "North America",
ISO_3: "NIC",
},
{
country: "Panama",
continent: "North America",
ISO_3: "PAN",
},
{
country: "Puerto Rico",
continent: "North America",
ISO_3: "PRI",
},
{
country: "Saint Kitts and Nevis",
continent: "North America",
ISO_3: "KNA",
},
{
country: "Saint Lucia",
continent: "North America",
ISO_3: "LCA",
},
{
country: "Saint Pierre and Miquelon",
continent: "North America",
ISO_3: "SPM",
},
{
country: "Saint Vincent and the Grenadines",
continent: "North America",
ISO_3: "VCT",
},
{
country: "Saint Martin",
continent: "North America",
ISO_3: "MAF",
},
{
country: "Trinidad and Tobago",
continent: "North America",
ISO_3: "TTO",
},
{
country: "Turks and Caicos Islands",
continent: "North America",
ISO_3: "TCA",
},
{
country: "United States of America",
continent: "North America",
ISO_3: "USA",
},
{
country: "Virgin Islands, British",
continent: "North America",
ISO_3: "VGB",
},
{
country: "Virgin Islands, U.S.",
continent: "North America",
ISO_3: "VIR",
},
{
country: "Caribbean Netherlands",
continent: "North America",
ISO_3: "BES",
},
{
country: "Curaçao",
continent: "North America",
ISO_3: "CUW",
},
],
},
{
continent: "Antarctica",
country: [
{
country: "Antarctica",
continent: "Antarctica",
ISO_3: "ATA",
},
{
country: "Bouvet Island",
continent: "Antarctica",
ISO_3: "BVT",
},
{
country: "Heard Island and McDonald Islands",
continent: "Antarctica",
ISO_3: "HMD",
},
{
country: "South Georgia and the South Sandwich Islands",
continent: "Antarctica",
ISO_3: "SGS",
},
],
},
{
continent: "South America",
country: [
{
country: "Argentina",
continent: "South America",
ISO_3: "ARG",
},
{
country: "Brazil",
continent: "South America",
ISO_3: "BRA",
},
{
country: "Bolivia",
continent: "South America",
ISO_3: "BOL",
},
{
country: "Chile",
continent: "South America",
ISO_3: "CHL",
},
{
country: "Colombia",
continent: "South America",
ISO_3: "COL",
},
{
country: "Ecuador",
continent: "South America",
ISO_3: "ECU",
},
{
country: "French Guiana",
continent: "South America",
ISO_3: "GUF",
},
{
country: "Falkland Islands",
continent: "South America",
ISO_3: "FLK",
},
{
country: "Guyana",
continent: "South America",
ISO_3: "GUY",
},
{
country: "Paraguay",
continent: "South America",
ISO_3: "PRY",
},
{
country: "Peru",
continent: "South America",
ISO_3: "PER",
},
{
country: "Suriname",
continent: "South America",
ISO_3: "SUR",
},
{
country: "Uruguay",
continent: "South America",
ISO_3: "URY",
},
{
country: "Venezuela",
continent: "South America",
ISO_3: "VEN",
},
{
country: "Eswatini",
continent: "South America",
ISO_3: "SWZ",
},
],
},
];
export const continentWithCountryList = continentWiseCountryList;
export function findCountryContinent(countryISO: string): string | null {
for (const continent of continentWiseCountryList) {
const country = continent.country.find(
(c) => c.ISO_3.trim().toUpperCase() === countryISO.trim().toUpperCase()
);
if (country) return continent.continent;
}
return null;
}
export function findContinentByCountryIso3(countryInput: string): string | null {
for (const continent of continentWiseCountryList) {
let country = continent.country.find(
(c) => c.ISO_3.trim().toLowerCase() === countryInput.trim().toLowerCase()
);
if (country) return continent.continent;
country = continent.country.find(
(c) => c.country.trim().toLowerCase() === countryInput.trim().toLowerCase()
);
if (country) return continent.continent;
}
return null;
}
export function getCountryDetails(countryISO: string): { country: string; continent: string } | null {
for (const continent of continentWiseCountryList) {
const country = continent.country.find(
(c) => c.ISO_3.trim().toUpperCase() === countryISO.trim().toUpperCase()
);
if (country) {
return { country: country.country, continent: continent.continent };
}
}
return null;
}
export function listCountriesInContinent(continentName: string): string[] | null {
const continent = continentWiseCountryList.find(
(c) => c.continent.trim().toLowerCase() === continentName.trim().toLowerCase()
);
return continent ? continent.country.map((c) => c.country) : null;
}