1.2.0 β€’ Published 1 year ago

@franekostrowski/country-utils v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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"
1.2.0

1 year ago

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago