1.2.0 β’ Published 1 year ago
@franekostrowski/country-utils v1.2.0
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-utils
Or with yarn:
yarn add @franekostrowski/country-utils
Usage
getCountryData
getCountryData(country: string): Country
interface 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): string
Example
import { getCountryCode } from "@franekostrowski/country-utils";
const countryCode = getCountryCode("Poland");
console.log(countryCode);
// "PL"
getCountryFlag
getCountryFlag(countryCode: string): string
Example
import { getCountryFlag } from "@franekostrowski/country-utils";
const countryFlag = getCountryFlag("PL");
console.log(countryFlag);
// "π΅π±"
getCountryName
getCountryName(countryCode: string): string
Example
import { getCountryName } from "@franekostrowski/country-utils";
const countryName = getCountryName("PL");
console.log(countryName);
// "Poland"