1.0.3 • Published 9 days ago

country-codes-and-flags v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

Country Codes and Flags ⛳️

Features

This package provides utilities for

  • retrieving a country's flag emoji, ISO alpha2, and ISO alpha3 codes given the country's name
  • reverse lookups to go from ISO codes or a flag emoji back to a country's name
  • retrieving a full dataset object that maps country names to their flags and iso codes

You can also find the full set of country data here

Installation

npm install country-codes-and-flags

Usage

Available Methods

FunctionInput TypeInputOutput
getFlagByCountrystringCountry nameFlag emoji string or null
getFlagByAlpha2stringTwo-letter country codeFlag emoji string or null
getFlagByAlpha3stringThree-letter country codeFlag emoji string or null
getAlpha2ByCountrystringCountry nameTwo-letter country code string or null
getAlpha3ByCountrystringCountry nameThree-letter country code string or null
getCountryFromFlagstringFlag emojiCountry name string or null
getCountryByAlpha2stringTwo-letter country codeCountry name string or null
getCountryByAlpha3stringThree-letter country codeCountry name string or null
getAllByCountrystringCountry nameCountryMetadata object or null
getAllN/AnoneReturns the full dataset ({ [COUNTRY_NAME: { flag: string; alpha2: string; alpha3: string}})

Examples

import {getAllByCountry, getFlagByCountry, getCountryFromFlag} from "country-codes-and-flags";

// Get All Metadata
const greeceData = getAllByCountry("Greece");
console.log(greeceData)
// Output:
// {
//   'flag': '🇬🇷',
//   'alpha2': 'GR',
//   'alpha3: 'GRC',
// }

// Get Flag
const greeceFlag = getFlagByCountry("Greece");
console.log(greeceFlag)
// Output:
// '🇬🇷'

// Get Country
const greeceName = getCountryFromFlag("🇬🇷");
console.log(greeceName)
// Output:
// 'Greece'

Handling Invalid Inputs

Invalid inputs or non-matching country names will result in null being returned. Planning to implement more descriptive error handling in future versions

Building the Library

You can clone this repo and build it locally with the following command:

npm run build

This will generate builds in the dist directory.

Contributing

Any contributions or suggestions for improvements are welcome! Please open an issue or submit a pull request.

Contact

For comments or questions email kathleen.garrity223@gmail.com

License

MIT