@country-info-helper/common
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

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:

1. getCountOfCountries

Get the count of countries.

const count = getCountOfCountries();
console.log(`Total countries: ${count}`);

2. getCountryNames

Get a list of country names.

const names = getCountryNames();
console.log(`Country names: ${names.join(', ')}`);

3. getCountryCodes

Get a list of country codes.

const codes = getCountryCodes();
console.log(`Country codes: ${codes.join(', ')}`);

4. getCapitalCities

Get a list of capital cities.

const capitals = getCapitalCities();
console.log(`Capital cities: ${capitals.join(', ')}`);

5. getAllLanguages

Get a list of languages spoken in all countries.

const languages = getAllLanguages();
console.log(`Languages spoken: ${languages.join(', ')}`);

6. getCountriesInRegion

Get a list of countries in a specific region.

const region = 'Europe';
const countriesInRegion = getCountriesInRegion(region);
console.log(`Countries in ${region}: ${countriesInRegion.join(', ')}`);

7. getFlagUrl

Get the flag URL for a specific country code.

const countryCode = 'US';
const flagUrl = getFlagUrl(countryCode);
console.log(`Flag URL for ${countryCode}: ${flagUrl}`);

8. getDialingCode

Get the dialing code for a specific country code.

const dialingCode = getDialingCode('FR');
console.log(`Dialing code for France: ${dialingCode}`);

9. getCountriesSharingBorders

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(', ')}`);

10. isCountryLandlocked

Check if a country is landlocked.

const countryCode = 'AT';
const isLandlocked = isCountryLandlocked(countryCode);
console.log(`Is Austria landlocked? ${isLandlocked}`);

11. getTopLevelDomain

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}`);

12. getMapUrls

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}`);

13. getCoatOfArmsUrls

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}`);

14. getEmoji

Get the emoji for a specific country code.

const countryCode = 'DE';
const emoji = getEmoji(countryCode);
console.log(`Emoji for Germany: ${emoji}`);

15. getUnicode

Get the Unicode for a specific country code.

const countryCode = 'IT';
const unicode = getUnicode(countryCode);
console.log(`Unicode for Italy: ${unicode}`);

16. getAlpha3Code

Get the alpha3 code for a specific country code.

const countryCode = 'CN';
const alpha3Code = getAlpha3Code(countryCode);
console.log(`Alpha3 code for China: ${alpha3Code}`);

17. getNativeNames

Get the native names for a specific country code.

const countryCode = 'ES';
const nativeNames = getNativeNames(countryCode);
console.log(`Native names for Spain:`, nativeNames);

18. getCountryArea

Get the area of a specific country code.

const countryCode = 'RU';
const area = getCountryArea(countryCode);
console.log(`Area of Russia: ${area} square kilometers`);

19. getNumericCode

Get the numeric code for a specific country code.

const countryCode = 'IN';
const numericCode = getNumericCode(countryCode);
console.log(`Numeric code for India: ${numericCode}`);

20. getCountryCurrencies

Get the currencies used in a specific country.

const countryCode = 'GB';
const currencies = getCountryCurrencies(countryCode);
console.log(`Currencies used in the UK:`, currencies);

21. getDialingCodeAndFlagUrl

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}`);

22. getAllDialingCodeAndFlagUrl

Get the dialing code and flag URL for all countries.

const allCountriesInfo = getAllDialingCodeAndFlagUrl();
console.log('Dialing codes and flag URLs for all countries:', allCountriesInfo);

23. getStatesByCountryCode

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(', ')}`);

24. getStatesByCountryName

Get a list of states for a specific country name.

const countryName = 'Canada';
const states = getStatesByCountryName(countryName);
console.log(`Provinces in Canada: ${states.join(', ')}`);

25. getStatesByAlpha3Code

Get a list of states for a specific alpha3 code.

const alpha3Code = 'DEU';
const states = getStatesByAlpha3Code(alpha3Code);
console.log(`States in Germany: ${states.join(', ')}`);

26. getCitiesByCountryCode

Get a list of cities for a specific country code.

const countryCode = 'FR';
const cities = getCitiesByCountryCode(countryCode);
console.log(`Cities in France: ${cities.join(', ')}`);

27. getCitiesByCountryName

Get a list of cities for a specific country name.

const countryName = 'Australia';
const cities = getCitiesByCountryName(countryName);
console.log(`Cities in Australia: ${cities.join(', ')}`);

28. getCitiesByAlpha3Code

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(', ')}`);

29. getCitiesByStateName

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.

Package Sidebar

Install

npm i @country-info-helper/common

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

6.58 MB

Total Files

14

Last publish

Collaborators

  • pro.shubhamjain