@franekostrowski/country-utils
v1.2.0
Published
Dealing with codes, flags and other country related logic is boring and repetetive. Many projects (including mine) need functions for that kind of thing so I started this project. It simplifies everything for you. Enjoy 🤗
Readme
country-utils 🌏
Dealing with codes, flags and other country related logic is boring and repetetive. Many projects (including mine) need functions for that kind of thing so I started this project. It simplifies everything for you. Enjoy 🤗
Installation
npm i @franekostrowski/country-utilsOr with yarn:
yarn add @franekostrowski/country-utilsUsage
getCountryData
getCountryData(country: string): Countryinterface Country {
name: string;
code: string;
flag: string;
}country- country code such as 'PL' or full country name eg. Poland
Example #1
import { getCountryData } from "@franekostrowski/country-utils";
const countryData = getCountryData("PL");
console.log(countryData);
// { name: "Poland", code: "PL", flag: "🇵🇱" }Example #2
import { getCountryData } from "@franekostrowski/country-utils";
const countryData = getCountryData("Sweden");
console.log(countryData);
// { name: "Sweden", code: "SE", flag: "🇸🇪" }getCountryCode
getCountryCode(countryName: string): stringExample
import { getCountryCode } from "@franekostrowski/country-utils";
const countryCode = getCountryCode("Poland");
console.log(countryCode);
// "PL"getCountryFlag
getCountryFlag(countryCode: string): stringExample
import { getCountryFlag } from "@franekostrowski/country-utils";
const countryFlag = getCountryFlag("PL");
console.log(countryFlag);
// "🇵🇱"getCountryName
getCountryName(countryCode: string): stringExample
import { getCountryName } from "@franekostrowski/country-utils";
const countryName = getCountryName("PL");
console.log(countryName);
// "Poland"