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

@saadixl/countries

v0.1.19

Published

List of countries by country code, currency, region, continent.

Downloads

11

Readme

countries

Get countries by country name, country code, currency, continent, capital.

How to install

$ npm install @saadixl/countries --save

or

$ yarn add @saadixl/countries

How to use

Include countries in your module

const countries = require('@saadixl/countries');

For getting info about one country

What can be passed as string parameter?

  • Country code, example: "BD"
  • Country name, example: "bangladesh"
  • ISO Country code, example: "SGP"
  • Capital name, example: "DhAka"

Note that the parameter is case insensitive

You can get information about a country by passing country code or country name or country iso code or capital as string parameter. For example, if you pass Bangladesh as a parameter like this:

countries("Bangladesh")

or you pass the country code of Bangladesh like:

countries("bd")

You will get the following object as result.

{ 
  capital: 'Dhaka',
  continentCode: 'AS',
  continentName: 'Asia',
  countryCodeISO: 'BGD',
  currencyCode: 'BDT',
  name: 'Bangladesh',
  names: [ 'Bangladesh', 'People Republic of Bangladesh' ],
  phoneCode: '880'
 }

Which means, it doesn't matter what format data you have an what format data you need, you will get it!

For getting a list of countries

What can be passed as config?

  • currency can be currency code, currency name
  • continent can be continent code, continent name

Note that you can pass both currency and continent together. At least one property as config is required.

Suppose, you need all the country codes of Europe or you need all the country names who uses USD. Firstly, you can pass a config object while calling countries. A config object can have currency and continent for now. Once you pass a config object, now you can call some methods like:

  • getAll()
  • getCountryCodes()
  • getISOCountryCodes()
  • getCountryNames()
  • getPhoneCodes()
  • getCapitals()

Or you can call getCapitals(property) where property can be any property inside the country object. For example if we really want to find all the country names who uses USD, we call:

countries({currency: "USD"})

It will return the following list:

[ 
  'American Samoa',
  'Bonaire, Sint Eustatius and Saba',
  'Ecuador',
  'Federated States of Micronesia',
  'Guam',
  'British Indian Ocean Territory',
  'Marshall Islands',
  'Northern Mariana Islands',
  'Puerto Rico',
  'Palau',
  'El Salvador',
  'Turks and Caicos Islands',
  'Timor-Leste',
  'United States Minor Outlying Islands',
  'United States of America',
  'British Virgin Islands',
  'Virgin Islands, U.S.' 
  ]

Just to make it little more interesting, we can try to find out all the country codes of the countries who uses USD as their currency but they are part of the Ocenia continent. To do that we call:

countries({currency: "USD", continent: "Oc"}).getCountryCodes()

It will return you the following array:

[ 'AS', 'FM', 'GU', 'MH', 'MP', 'PW', 'TL', 'UM' ]

I am planning to add region soon. I am developing this because I have not found everything in one place before. That's why taking things into own hands!