
Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
country-info-data
Advanced tools
This library helps manage and retrieve continent and country information. It provides methods to fetch details about continents, find countries by continent, and get detailed information about specific countries.
This library helps manage and retrieve continent and country information. It provides methods to fetch details about continents, find countries by continent, and get detailed information about specific countries.
CountryData offers a comprehensive and flexible set of methods for working with country, continent, and region data. Whether you need to query specific countries or work with large datasets, this class provides the tools to efficiently access and manipulate geo information.
import CountryData from "country-info-data";
findCountryDetailsByLocation
CountryInfoData.findCountryDetailsByLocation(location: string): CountryDetails[]
query()
CountryInfoQuery
instance.const query = CountryData.query();
updateCountryData(countries: CountryDetails[])
CountryData.updateCountryData([
{
code: "US",
name: "United States",
continent: { name: "North America", code: "NA" },
region: "NorthAmericaMainland",
},
]);
getCountryNameByCode(countryCode: CountryCode)
undefined
if not found.const countryName = CountryData.getCountryNameByCode("US");
console.log(countryName); // "United States"
getCountryCodeByName(name: string)
undefined
if not found.const countryCode = CountryData.getCountryCodeByName("United States");
console.log(countryCode); // "US"
getAllCountryNames()
const countryNames = CountryData.getAllCountryNames();
console.log(countryNames); // ["United States", "Canada", "Mexico", ...]
getAllCountryCodes()
const countryCodes = CountryData.getAllCountryCodes();
console.log(countryCodes); // ["US", "CA", "MX", ...]
getAllCountryDetails()
const countryDetails = CountryData.getAllCountryDetails();
console.log(countryDetails);
getContinentNameByCode(code: ContinentCode)
undefined
if not found.const continentName = CountryData.getContinentNameByCode("NA");
console.log(continentName); // "North America"
getAllContinentCodes()
const continentCodes = CountryData.getAllContinentCodes();
console.log(continentCodes); // ["AF", "AN", "AS", "EU", "NA", "OC", "SA"]
getCountryCodesByContinent(continentCode: ContinentCode)
const countryCodesInAfrica = CountryData.getCountryCodesByContinent("AF");
console.log(countryCodesInAfrica); // ["DZ", "EG", "MA", ...]
getContinentCodeByCountryCode(countryCode: CountryCode)
const continentCode = CountryData.getContinentCodeByCountryCode("US");
console.log(continentCode); // "NA"
getCountryCodesByContinentName(continentName: ContinentName)
const countryCodesInNorthAmerica =
CountryData.getCountryCodesByContinentName("North America");
console.log(countryCodesInNorthAmerica); // ["US", "CA", "MX"]
getCountryNamesByContinentName(continentName: ContinentName)
const countryNamesInAfrica =
CountryData.getCountryNamesByContinentName("Africa");
console.log(countryNamesInAfrica); // ["Algeria", "Egypt", "Morocco", ...]
getRegionByContinent(continentCode: ContinentCode)
const regionsInAsia = CountryData.getRegionByContinent("AS");
console.log(regionsInAsia); // ["EastAsia", "SouthAsia", "SoutheastAsia", ...]
getRegionByCountryCode(countryCode: CountryCode)
const regionCode = CountryData.getRegionByCountryCode("US");
console.log(regionCode); // "NorthAmericaMainland"
searchCountriesByName(partialName: string)
const countries = CountryData.searchCountriesByName("Unite");
console.log(countries); // ["United States", "United Kingdom", ...]
getCountriesFromMultipleContinentsOrRegions(continentCodes: ContinentCode[], regionCodes: RegionCode[])
const countries = CountryData.getCountriesFromMultipleContinentsOrRegions(
["AF", "AS"],
["WesternAfrica", "EastAsia"]
);
console.log(countries); // ["NG", "CN", "IN", ...]
getAllContinentData()
const continentData = CountryData.getAllContinentData();
console.log(continentData);
isCountryInContinent(countryCode: CountryCode, continentCode: ContinentCode)
const isInAfrica = CountryData.isCountryInContinent("NG", "AF");
console.log(isInAfrica); // true if Nigeria ('NG') is in Africa
getRegionByCountryName(countryName: string)
const regionByCountryName = CountryData.getRegionByCountryName("Kenya");
console.log(regionByCountryName);
// Should print the region code corresponding to Kenya, e.g., 'EasternAfrica'
getCountryNamesByRegion(regionName: string)
const countryNamesByRegion =
CountryData.getCountryNamesByRegion("EasternAfrica");
console.log(countryNamesByRegion);
// Should print a list of country names in the Eastern Africa region
getCountryCodesByRegion(regionName: string)
const countryCodesByRegion =
CountryData.getCountryCodesByRegion("SouthernAfrica");
console.log(countryCodesByRegion);
// Should print an array of country codes in Southern Africa
continent(continentCodes: ContinentCode[])
region(regionOrRegions: RegionCode | RegionCode[])
country(countryCodes: string[])
excludeContinent(continentCodes: ContinentCode[])
excludeRegion(regionCodes: RegionCode[])
countryName(name: string)
excludeCountryCode(countryCodes: string[])
excludeCountryName(countryNames: string[])
sortByName()
sortByContinent()
sortByRegion()
limit(limit: number)
selectFields(fields: Array<keyof CountryDetails>)
withDetails()
execute()
import { CountryInfoQuery } from "country-info-data";
// Create a new query instance
const query = new CountryInfoQuery();
// Build a query to find countries in Africa, excluding specific countries, and limit the results
const results = query
.continent(["AF"])
.excludeCountryName(["United States", "Canada"])
.limit(5)
.execute();
console.log(results);
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
This library helps manage and retrieve continent and country information. It provides methods to fetch details about continents, find countries by continent, and get detailed information about specific countries.
The npm package country-info-data receives a total of 6 weekly downloads. As such, country-info-data popularity was classified as not popular.
We found that country-info-data demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.