@siamf/iso3166
v4.3.2
Published
A tiny, zero-dependency dataset and utilities for ISO-3166 country codes (alpha-2/alpha-3/numeric) and names. Lookup by code or name, validate inputs, and map between formats—fast and tree-shakeable.
Maintainers
Readme
@siamf/iso3166
A tiny, zero-dependency dataset and utilities for ISO-3166 country codes (alpha-2/alpha-3/numeric) and names. Lookup by code or name, validate inputs, and map between formats—fast and tree-shakeable.
Introduction
A simple but useful functional node packages with all country data. It includes all useful country data gives several function to complete your project.
Countries
The data currently provided for each country is:
idThe unique id number for the arraynameThe english name for the countryisoAlpha2The ISO 3166-1 alpha 2 codeisoAlpha3The ISO 3166-1 alpha 3 codeisoNumericThe ISO 3166-1 numericcurrencyAn object with currency info.codeThe ISO 4217 currency codesnameThe currency namesymbolThe currency symbol
languagesAn array of ISO 639-2 codes for languages.countryCallingCodesThe international call prefixes for this country.emojiThe emoji of country's flag.
Installation
$ npm i @siamf/iso3166import { getCountryList } from "@siamf/iso3166";
or
const { getCountryList } = require("@siamf/iso3166")Example
console.log(getCountryList()); //Returns all country listMethods
getCurrency(countryCode)
Returns the country's currency info by providing country code.
Example
import { getCurrency, GetCurrencyTypes } from "@siamf/iso3166";
const currencyInfo: GetCurrencyTypes = getCurrency("BD"); // Here country code can be isoAlpha2 or isoAlpha3
console.log(currencyInfo)Return values-
namecurrency namecodecurrency codesymbolcurrency symbol
getCallingCode(countryCode)
Returns the country's calling code. It returns an array of string.
Example
import { getCallingCode, GetCallingCodeTypes } from "@siamf/iso3166";
const dialingCode: GetCallingCodeTypes = getCallingCode("BD")
console.log(dialingCode) // Give the country code(isoAlpha2 or isoAlpha3)
//{
code: "880",
format: "+880",
flag: "" //Flagmedia flag URL
}getLanguages(countryCode)
Returns the country's languages. It returns an array of string;
Example
import { getLanguages } from "@siamf/iso3166";
console.log(getLanguages("BD")) // Give the country code(isoAlpha2 or isoAlpha3)
//["ben"]getFlagBase64(countryCode)
Returns the country's flag image as base64 data
Example
import { getFlagBase64 } from "@siamf/iso3166";
const flag = getFlagBase64("BD") // Give the country code(isoAlpha2 or isoAlpha3)
//<img src=`data:image/png;base64, ${flag}`/>lookup(query)
You can search and find any country's data by any parameter, like-
- by
name: You can search and find data by country name - by
countryCode: You can search and find data by country code - by
callingCode: You can search and find data by country calling code - by
currencyName: You can search and find data by country currency name - by
currencyCode: You can search and find data by country currency code - by
currencySymbol: You can search and find data by country currency symbol - by
isoNumeric: You can search and find data by country iso numeric
Example
import { lookup, CountryDataTypes } from "@siamf/iso3166";
const data: CountryDataTypes = lookup({name: "Bangladesh"})
const data: CountryDataTypes = lookup({countryCode: "BD"})
const data: CountryDataTypes = lookup({callingCode: "+880"})
const data: CountryDataTypes = lookup({currencyName: "taka"})
const data: CountryDataTypes = lookup({currencyCode: "BDT"})
const data: CountryDataTypes = lookup({currencySymbol: "৳"})removeDialCode()
You can remove dial code from a phone number and get a string value.
Example
import { removeDialCode } from "@siamf/iso3166";
const phone = removeDialCode("+8801611994404")
//undefined or
//01611994403Issues or correction
If you face any issues to any function or see any wrong information about country, please let me know.
