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

countrily

v1.5.2

Published

A country list and information library

Downloads

116

Readme

countrily

Inspired by the work of the authors of countryjs, this is a Node.js module for returning data about countries but can also be run in the browser unlike the original project. Use this to get a list of countries (country list) and their corresponding meta data

Table of Contents

Install

npm install countrily

Usage

To access one of the country properties available, you'll need to use one of the API methods listed below and pass a country in either way:

  • Using the ISO-alpha2 code: var country = new Country('NG', 'ISO2') or var country = new Country('NG') (defaults)
  • Using the ISO-alpha3 code: var country = new Country('NG', 'ISO3')
  • From this you can just use any of the methods: country.states().

API

.info()

Returns all available information for a specified country.

var Countrily = require('countrily');
var nigeria = new Countrily('NGA', 'ISO3'); // 'ISO2', 'ISO3', 'name'
var nigeria = new Countrily('NG');  // Defaults to ISO2
nigeria.info();
// returns object,
// {
//     "name": "Nigeria",
//     "altSpellings": ["NG", "NGA", "Federal Republic of Nigeria"],
//     "area": 923768,
//     "borders": ["BEN","CMR","TCD","NER"],
//     "callingCodes": ["234"],
//     "capital": "Abuja",
//     "currencies": ["NGN"],
//     "demonym": "Nigerian",
//     ...
// }

.states()

Returns all states/provinces for a specified country.

var Countrily = require('countrily');
var nigeria = Countrily('NG', 'ISO2'); // 'ISO2', 'ISO3', 'name'.
var nigeria = Countrily('NG')
nigeria.states();
// returns array of states,
// [
//  "Adamawa",
//  ...
// ]

.provinces()

Alias of .states()

.name()

Returns name for a specified country

var Countrily = require('countrily');
var nigeria = Countrily('NGA', 'ISO3'); // 'ISO2', 'ISO3', 'name'
var nigeria = Countrily('NG'); // Defaults to 'ISO2'
country.name() // Defaults to 'ISO2'
// returns string
// "Nigeria"

.altSpellings()

Returns alternate spellings for the name of a specified country

nigeria.altSpellings()
// returns array of strings, alternate names
// ["NG","Nijeriya","Naíjíríà","Federal Republic of Nigeria"]

.area()

Returns area (km²) for a specified country

nigeria.area()
// returns number of square kilometer area
// 923768

.borders()

Returns bordering countries (ISO3) for a specified country

nigeria.borders() // Defaults to 'ISO2'
// returns array of strings, ISO3 codes of countries that border the given country
// ["BEN","CMR","TCD","NER"]

.callingCodes()

Returns international calling codes for a specified country

nigeria.callingCodes() // Defaults to 'ISO2'
// returns array of calling code strings
// ["234"]

.capital()

Returns capital city for a specified country

nigeria.capital()
// returns string
// "Abuja"

.currencies()

Returns official currencies for a specified country

nigeria.currencies()
// returns array of strings, currencies
// ["NGN"]

.demonym()

Returns the demonyms for a specified country

nigeria.demonym()
// returns string, name of residents
// "Nigerian"

.flag() - INCOMPLETE

Returns SVG link of the official flag for a specified country

nigeria.flag()
// returns string URL of CC licensed svg flag

.geoJSON()

Returns geoJSON for a specified country

nigeria.geoJSON()
// returns object of GeoJSON data

.ISOcodes()

Returns ISO codes for a specified country

nigeria.ISOcodes()
// returns object of ISO codes
// {
//   "alpha2": "NG",
//   "alpha3": "NGA"
// }

.languages()

Returns official languages for a specified country

nigeria.languages()
// returns array of language codes
// ["en"]

.latlng()

Returns approx latitude and longitude for a specified country

nigeia.latlng();
// returns array, approx latitude and longitude for country
// [10,8]

.nativeName()

Returns the name of the country in its native tongue

nigeria.nativeName();
// returns string, name of country in native language
// "Nigeria"

.population()

Returns approximate population for a specified country

nigeria.population();
// returns number, approx population
// 178517000

.region()

Returns general region for a specified country

nigeria.region();
// returns string
// "Africa"

.subregion()

Returns a more specific region for a specified country

nigeria.subregion();
// returns string
// "West Africa"

.timezones()

Returns all timezones for a specified country

nigeria.timezones();
// returns array of timezones

.tld()

Returns official top level domains for a specified country

nigeria.tld();
// returns array of top level domains specific to the country
// [".ng"]

.translations()

Returns translations for a specified country name in popular languages

nigeria.translations();
// returns object of translations of country name in major languages
// {
//   "de": "Nigeria",
//   "es": "Nigeria",
//   "fr": "Nigeria",
//   "ja": "ナイジェリア",
//   "it": "Nigeria"
// }

.wiki()

Returns link to wikipedia page for a specified country

nigeria.wiki();
// returns string URL of wikipedia article on country
// "http://en.wikipedia.org/wiki/Nigeria"

Static methods

Two static methods are exposed to return all data and shortnames

.all()

Return all country data. This will be super big. Not recommended.

var Countrily = require('countrily');
Countrily.all();
// returns array of objects,
// [{
//     "name": "Nigeria",
//     "altSpellings": ["NG", "NGA", "Federal Republic of Nigeria"],
//     "area": 923768,
//     "borders": ["BEN","CMR","TCD","NER"],
//     "callingCodes": ["234"],
//     "capital": "Abuja",
//     "currencies": ["NGN"],
//     "demonym": "Nigerian",
//     ...
// },
// ...]

.shortnamesofall()

Return an array of all the shortnames (ISO2) of all the countries.

var Countrily = require('countrily');
Countrily.shortnamesofall();

.lean(field)

Return an array of field entered.

const Countrily = require('countrily');
Countrily.lean('name');

['Afghanistan',
  'Albania',
  'Algeria',
  'American Samoa',
  'Angola',
  'Anguilla',
  'Antigua and Barbuda',
  'Argentina',
  'Armenia',
  'Aruba',
  ...]

Test

  1. Make the changes you desire
  2. Ensure all changes have a new test in the test/ folder, and run:
npm test

Disclaimer

This is being maintained in the contributor's free time, and as such, may contain minor errors in regards to some countries. Most of the information included in this library is what is listed on Wikipedia. If there is an error, please let me know and I will do my best to correct it.

License (ISC)

Copyright (c) 2017, Timi Aiyemo [email protected]

Please see licence file.