npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iā€™ve always been into building performant and accessible sites, but lately Iā€™ve been taking it extremely seriously. So much so that Iā€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iā€™m making an attempt to offer the best experience to those who visit them. If youā€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, šŸ‘‹, Iā€™m Ryan HefnerĀ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youā€™re interested in other things Iā€™m working on, follow me on Twitter or check out the open source projects Iā€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonā€“ish.

Open Software & Tools

This site wouldnā€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you šŸ™

Ā© 2024 ā€“Ā Pkg Stats / Ryan Hefner

country-data-codes

v4.2.0

Published

Easy and Simple Country Data and Code Management solutionšŸ¤·

Downloads

2,494

Readme

Country Data Codes

A node js package to get country data including country name, code, currency information, emoji etc.

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:

  • id The unique id number for the array

  • name The english name for the country

  • isoAlpha2 The ISO 3166-1 alpha 2 code

  • isoAlpha3 The ISO 3166-1 alpha 3 code

  • isoNumeric The ISO 3166-1 numeric

  • currency An object with currency info.

  • flag Country flag base64 data

  • languages An array of ISO 639-2 codes for languages.

  • countryCallingCodes The international call prefixes for this country.

  • emoji The emoji of country's flag.

Installation

$ npm i country-data-codes
import { getCountryList } from "country-data-codes";
or
const { getCountryList } = require("country-data-codes")

Example

console.log(getCountryList()); //Returns all country list

Methods

getCurrency(countryCode)

Returns the country's currency info by providing country code.

Example

import { getCurrency, GetCurrencyTypes } from "country-data-codes";

const currencyInfo: GetCurrencyTypes = getCurrency("BD"); // Here country code can be isoAlpha2 or isoAlpha3

console.log(currencyInfo)

Return values-

  • name currency name
  • code currency code
  • symbol currency symbol

getCallingCode(countryCode)

Returns the country's calling code. It returns an array of string.

Example

import { getCallingCode, GetCallingCodeTypes } from "country-data-codes";

const dialingCode: GetCallingCodeTypes = getCallingCode("BD")

console.log(dialingCode) // Give the country code(isoAlpha2 or isoAlpha3)
//{
  code: "880",
  format: "+880",
  flag: "" //Base64 flash data
}

getLanguages(countryCode)

Returns the country's languages. It returns an array of string;

Example

import { getLanguages } from "country-data-codes";

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 "country-data-codes";

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 "country-data-codes";

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 "country-data-codes";

const phone = removeDialCode("+8801611994404")

//undefined or
//01611994403

Issues or correction

If you face any issues to any function or see any wrong information about country, please let me know.

Stay in touch

License

country-data-codes MIT licensed.