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

rest-countries-ts

v0.0.1

Published

A TS variation for the rest-countries-node Node.js wrapper library around the API provided by https://restcountries.com from @fegoa89

Downloads

3

Readme

Build Status npm version

Rest Country Node

A Node.js wrapper library around the API provided by https://restcountries.com. Using API version 3.1.

Available methods

getAll()

findByName()

findByFullName()

findByIsoCountryCode()

findByIsoCountryCodes()

findByCurrency()

findByLanguageCode()

findByCapitalCity()

findByCallingCode()

findByRegion()

getAllGroupedByRegion()

getAllGroupedBySubRegion()

findCountryFlagByCountryName()

findCountryByForeignName()

getNearestCountryToPosition()

getAllGroupedByTimezone()

getCountriesByTimezone()

Usage

var RestCountries = require('rest-countries-node');
restCountries = new RestCountries;

getAll

Returns all countries information:

restCountries.getAll()
  .then(response => {
    /*...*/
  });

findByName

Search by country name. It can be the native name or partial name:

restCountries.findByName('france')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "FR",
          "alpha3Code": "FRA",
          "altSpellings": [
            "FR",
            "French Republic",
            "République française"
          ],
          ...
        }
      ]
    */
  });

findByFullName

Search by country full name:

restCountries.findByFullName('france')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "FR",
          "alpha3Code": "FRA",
          "altSpellings": [
            "FR",
            "French Republic",
            "République française"
          ],
          ...
        }
      ]
    */
  });

findByIsoCountryCode

Search by ISO 3166-1 2-letter or 3-letter country code:

restCountries.findByIsoCountryCode('bg')
  .then(response => {
    /*
      {
        "alpha2Code": "BG",
        "alpha3Code": "BGR",
        "altSpellings": [
          "BG",
          "Republic of Bulgaria",
          "Република България"
        ],
        ...
      }
    */
  });

findByIsoCountryCodes

Search by list of ISO 3166-1 2-letter or 3-letter country codes:

restCountries.findByIsoCountryCodes('pl;gb;it')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "PL",
          "alpha3Code": "POL",
          "altSpellings": [
            "PL",
            "Republic of Poland",
            "Rzeczpospolita Polska"
          ],
          ...
        },
        {
          "alpha2Code": "GB",
          "alpha3Code": "GBR",
          "altSpellings": [
            "GB",
            "UK",
            "Great Britain"
          ],
          ...
        },
        {
          "alpha2Code": "IT",
          "alpha3Code": "ITA",
          "altSpellings": [
            "IT",
            "Italian Republic",
            "Repubblica italiana"
          ],
          ...
        }
      ]
    */
  });

findByCurrency

Search by ISO 4217 currency code:

restCountries.findByCurrency('pln')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "PL",
          "alpha3Code": "POL",
          "altSpellings": [
            "PL",
            "Republic of Poland",
            "Rzeczpospolita Polska"
          ],
          ...
        }
      ]
    */
  });

findByLanguageCode

Search by ISO 639-1 language code:

restCountries.findByLanguageCode('italian')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "VA",
          "alpha3Code": "VAT",
          "altSpellings": [
            "Sancta Sedes",
            "Vatican",
            "The Vatican"
          ],
          ...
        },
        {
          "alpha2Code": "IT",
          "alpha3Code": "ITA",
          "altSpellings": [
            "IT",
            "Italian Republic",
            "Repubblica italiana"
          ],
          ...
        }
      ]
    */
  });

findByCapitalCity

Search by capital city:

restCountries.findByCapitalCity('tallinn')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "EE",
          "alpha3Code": "EST",
          "altSpellings": [
            "EE",
            "Eesti",
            "Republic of Estonia",
            "Eesti Vabariik"
          ],
          ...
        }
      ]
    */
  });

findByCallingCode

Search by calling code:

restCountries.findByCallingCode('377')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "MC",
          "alpha3Code": "MCO",
          "altSpellings": [
            "MC",
            "Principality of Monaco",
            "Principauté de Monaco"
          ],
          ...
        }
      ]
    */
  });

findByRegion

Search by region (Africa, Americas, Asia, Europe, Oceania) :

restCountries.findByRegion('oceania')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "AS",
          "alpha3Code": "ASM",
          "altSpellings": [
            "AS",
            "Amerika Sāmoa",
            "Amelika Sāmoa",
            "Sāmoa Amelika"
          ],
          ...
        },
        ...
      ]
    */
  });

getAllGroupedBySubRegion

Returns a list of countries grouped by subregions:

restCountries.getAllGroupedBySubRegion()
  .then(response => {
    /*
      { "southern-europe":
        [
          {
            "alpha2Code": "ES",
            "alpha3Code": "ESP",
            "altSpellings": [
              "ES",
              "Kingdom of Spain",
              "Reino de España"
            ],
            ...
          },
          ...
        ],
        "south-america":
        [
          {
            "alpha2Code": "CO",
            "alpha3Code": "COL",
            "altSpellings": [
              "CO",
              "Republic of Colombia",
              "República de Colombia"
            ],
            ...
          },
          ...
        ],
        ...
      }
    */
  });

getAllGroupedByRegion

Returns a list of countries grouped by regions:

restCountries.getAllGroupedByRegion()
  .then(response => {
    /*
      {
        "europe": [
          {
            "alpha2Code": "ES",
            "alpha3Code": "ESP",
            "altSpellings": [
              "ES",
              "Kingdom of Spain",
              "Reino de España"
            ],
            ...
          },
          {
            "alpha2Code": "DE",
            "alpha3Code": "DEU",
            "altSpellings": [
              "DE",
              "Federal Republic of Germany",
              "Bundesrepublik Deutschland"
            ],
          }
        ],
        "americas": [
          {
            "alpha2Code": "CO",
            "alpha3Code": "COL",
            "altSpellings": [
              "CO",
              "Republic of Colombia",
              "República de Colombia"
            ],
            ...
          }
        ]
      }

    */
  });

findCountryFlagByCountryName

Returns the flag for a given country :

restCountries.findCountryFlagByCountryName('Spain')
  .then(response => {
    /*
      {
        "countryName": "Spain",
        "flag": "https://restcountries.com/data/esp.svg"
      }
    */
  });

findCountryByForeignName

Returns the flag for a given country :

restCountries.findCountryByForeignName('スペイン')
  .then(response => {
    /*
      {
        "alpha2Code": "ES",
        "alpha3Code": "ESP",
        "altSpellings": [
          "ES",
          "Kingdom of Spain",
          "Reino de España"
        ],
        ...
      }
    */
  });

getNearestCountryToPosition

Returns the nearest country to the input lat/lon:

restCountries.getNearestCountryToPosition({lat: 50.0, lon: 9.0})
  .then(response => {
    /*
      {
        "alpha2Code": "DE",
        "alpha3Code": "DEU",
        "altSpellings": [
          "DE",
          "Federal Republic of Germany",
          "Bundesrepublik Deutschland"
        ],
        ...
      }
    */
  });

getAllGroupedByTimezone

Returns a list of countries grouped by timezone:

restCountries.getAllGroupedByTimezone()
  .then(response => {
    /*
      {
        "UTC": [
          {
            "alpha2Code": "ES",
            "alpha3Code": "ESP",
            "altSpellings": [
              "ES",
              "Kingdom of Spain",
              "Reino de España"
            ],
            ...
          }
        ],
        "UTC+01:00": [
          {
            "alpha2Code": "ES",
            "alpha3Code": "ESP",
            "altSpellings": [
              "ES",
              "Kingdom of Spain",
              "Reino de España"
            ],
            ...
          },
          {
            "alpha2Code": "DE",
            "alpha3Code": "DEU",
            "altSpellings": [
              "DE",
              "Federal Republic of Germany",
              "Bundesrepublik Deutschland"
            ],
            ...
          }
        ],
        "UTC-05:00": [
          {
            "alpha2Code": "CO",
            "alpha3Code": "COL",
            "altSpellings": [
              "CO",
              "Republic of Colombia",
              "República de Colombia"
            ],
            ...
          }
        ]
      }
    */
  });

getCountriesByTimezone

Returns a list of countries that belong to a timezone:

restCountries.getCountriesByTimezone('UTC-05:00')
  .then(response => {
    /*
      {
        "UTC-05:00": [
          {
            "alpha2Code": "CO",
            "alpha3Code": "COL",
            "altSpellings": [
              "CO",
              "Republic of Colombia",
              "República de Colombia"
            ],
            ...
          }
        ]
      }
    */
  });