Country Info Helper
A JavaScript / TypeScript base library for handling and manipulating country information easily.
Installation
You can install this package using npm or yarn:
npm install @country-info-helper/common
# or
yarn add @country-info-helper/common
Usage
Import the functions you need from the package and use them in your JavaScript/TypeScript project.
import {
getCountOfCountries,
getCountryNames,
getCountryCodes,
getCapitalCities,
getAllLanguages,
getCountriesInRegion,
getFlagUrl,
getDialingCode,
getCountriesSharingBorders,
isCountryLandlocked,
getTopLevelDomain,
getMapUrls,
getCoatOfArmsUrls,
getEmoji,
getUnicode,
getAlpha3Code,
getNativeNames,
getCountryArea,
getNumericCode,
getCountryCurrencies,
getDialingCodeAndFlagUrl,
getAllDialingCodeAndFlagUrl,
getStatesByCountryCode,
getStatesByCountryName,
getStatesByAlpha3Code,
getCitiesByCountryCode,
getCitiesByCountryName,
getCitiesByAlpha3Code,
getCitiesByStateName
} from '@country-info-helper/common/build/src';
Functions and Use Cases
Here are the functions available in this package and their respective use cases:
getCountOfCountries
1. Get the count of countries.
const count = getCountOfCountries();
console.log(`Total countries: ${count}`);
getCountryNames
2. Get a list of country names.
const names = getCountryNames();
console.log(`Country names: ${names.join(', ')}`);
getCountryCodes
3. Get a list of country codes.
const codes = getCountryCodes();
console.log(`Country codes: ${codes.join(', ')}`);
getCapitalCities
4. Get a list of capital cities.
const capitals = getCapitalCities();
console.log(`Capital cities: ${capitals.join(', ')}`);
getAllLanguages
5. Get a list of languages spoken in all countries.
const languages = getAllLanguages();
console.log(`Languages spoken: ${languages.join(', ')}`);
getCountriesInRegion
6. Get a list of countries in a specific region.
const region = 'Europe';
const countriesInRegion = getCountriesInRegion(region);
console.log(`Countries in ${region}: ${countriesInRegion.join(', ')}`);
getFlagUrl
7. Get the flag URL for a specific country code.
const countryCode = 'US';
const flagUrl = getFlagUrl(countryCode);
console.log(`Flag URL for ${countryCode}: ${flagUrl}`);
getDialingCode
8. Get the dialing code for a specific country code.
const dialingCode = getDialingCode('FR');
console.log(`Dialing code for France: ${dialingCode}`);
getCountriesSharingBorders
9. Get countries that share borders with a specific country.
const countryCode = 'CA';
const borderingCountries = getCountriesSharingBorders(countryCode);
console.log(`Countries sharing borders with Canada: ${borderingCountries.join(', ')}`);
isCountryLandlocked
10. Check if a country is landlocked.
const countryCode = 'AT';
const isLandlocked = isCountryLandlocked(countryCode);
console.log(`Is Austria landlocked? ${isLandlocked}`);
getTopLevelDomain
11. Get the top-level domain for a specific country code.
const countryCode = 'JP';
const topLevelDomain = getTopLevelDomain(countryCode);
console.log(`Top-level domain for Japan: ${topLevelDomain}`);
getMapUrls
12. Get the maps URLs for a specific country.
const countryCode = 'AU';
const mapUrls = getMapUrls(countryCode);
console.log(`Google Maps URL: ${mapUrls.googleMaps}`);
console.log(`OpenStreetMaps URL: ${mapUrls.openStreetMaps}`);
getCoatOfArmsUrls
13. Get the coat of arms URLs for a specific country.
const countryCode = 'BR';
const coatOfArmsUrls = getCoatOfArmsUrls(countryCode);
console.log(`PNG Coat of Arms URL: ${coatOfArmsUrls.png}`);
console.log(`SVG Coat of Arms URL: ${coatOfArmsUrls.svg}`);
getEmoji
14. Get the emoji for a specific country code.
const countryCode = 'DE';
const emoji = getEmoji(countryCode);
console.log(`Emoji for Germany: ${emoji}`);
getUnicode
15. Get the Unicode for a specific country code.
const countryCode = 'IT';
const unicode = getUnicode(countryCode);
console.log(`Unicode for Italy: ${unicode}`);
getAlpha3Code
16. Get the alpha3 code for a specific country code.
const countryCode = 'CN';
const alpha3Code = getAlpha3Code(countryCode);
console.log(`Alpha3 code for China: ${alpha3Code}`);
getNativeNames
17. Get the native names for a specific country code.
const countryCode = 'ES';
const nativeNames = getNativeNames(countryCode);
console.log(`Native names for Spain:`, nativeNames);
getCountryArea
18. Get the area of a specific country code.
const countryCode = 'RU';
const area = getCountryArea(countryCode);
console.log(`Area of Russia: ${area} square kilometers`);
getNumericCode
19. Get the numeric code for a specific country code.
const countryCode = 'IN';
const numericCode = getNumericCode(countryCode);
console.log(`Numeric code for India: ${numericCode}`);
getCountryCurrencies
20. Get the currencies used in a specific country.
const countryCode = 'GB';
const currencies = getCountryCurrencies(countryCode);
console.log(`Currencies used in the UK:`, currencies);
getDialingCodeAndFlagUrl
21. Get the dialing code and flag URL for a specific country code.
const countryCode = 'ZA';
const info = getDialingCodeAndFlagUrl(countryCode);
console.log(`Dialing code: ${info.dialingCode}`);
console.log(`Flag URL: ${info.flagUrl}`);
getAllDialingCodeAndFlagUrl
22. Get the dialing code and flag URL for all countries.
const allCountriesInfo = getAllDialingCodeAndFlagUrl();
console.log('Dialing codes and flag URLs for all countries:', allCountriesInfo);
getStatesByCountryCode
23. Get a list of states for a specific country code.
const countryCode = 'US';
const states = getStatesByCountryCode(countryCode);
console.log(`States in the United States: ${states.join(', ')}`);
getStatesByCountryName
24. Get a list of states for a specific country name.
const countryName = 'Canada';
const states = getStatesByCountryName(countryName);
console.log(`Provinces in Canada: ${states.join(', ')}`);
getStatesByAlpha3Code
25. Get a list of states for a specific alpha3 code.
const alpha3Code = 'DEU';
const states = getStatesByAlpha3Code(alpha3Code);
console.log(`States in Germany: ${states.join(', ')}`);
getCitiesByCountryCode
26. Get a list of cities for a specific country code.
const countryCode = 'FR';
const cities = getCitiesByCountryCode(countryCode);
console.log(`Cities in France: ${cities.join(', ')}`);
getCitiesByCountryName
27. Get a list of cities for a specific country name.
const countryName = 'Australia';
const cities = getCitiesByCountryName(countryName);
console.log(`Cities in Australia: ${cities.join(', ')}`);
getCitiesByAlpha3Code
28. Get a list of cities for a specific alpha3 code.
const alpha3Code = 'USA';
const cities = getCitiesByAlpha3Code(alpha3Code);
console.log(`Cities in the United States: ${cities.join(', ')}`);
getCitiesByStateName
29. Get a list of cities for a specific state in a country.
const stateName = 'California';
const cities = getCitiesByStateName(stateName);
console.log(`Cities in California, USA: ${cities.join(', ')}`);
Contribution
Feel free to send a PR to fix, update or add new entry anytime. For non-minor changes (ex: country: name, language, city, independence date..), please include a source, if possible.
License
This library is licensed under the MIT License.