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

restcountries-wrapper

v2.0.1

Published

A simple API wrapper for the API at https://restcountries.eu

Downloads

3

Readme

Restcountries-wrapper

Hi there 👋
This is a simple implementation of the data provided by https://restcountries.eu. This implementation works completely without dependencies and also has TypeScript support! 🎉

ℹ The package was previously an API Wrapper for Restcountries, but I soon noticed that the data there has not been updated in last 4 years. So I decided instead of straining their servers for data, I'd maintain a copy of them in the package. The local data is what is used in the package

Import

  • ES6 Import
import { RestCountryWrapper } from "restcountries-wrapper";

const wrapper = new RestCountryWrapper();
  • Node.js
const { RestCountryWrapper } = require("restcountries-wrapper");

const wrapper = new RestCountryWrapper;

Using the Package

  1. Import the class as shown in Import

  2. Initialise the class (also shown)

  3. Use one of the methods as documented below.

Methods

Note ℹ: All of the boolean values are always false

  • getAllCountries

    • Gets all the data
  • getCountryByName

    • Parameters
      • query (Type: string): The name of the country you want to search for
      • sort (Type: boolean): Whether you want the array to be sorted by the length of the name of the country
      • fullText (Type: boolean): Whether the query provided is the full name of the country
    • It uses regex to find match in the country's name, nativeName, altSpellings, isoCodes & translations
  • getCountryByLanguage

    • Parameters
      • query: You already know what it does
      • sort: You already know what it does
    • It uses regex ~~again~~ to find matches in language's ISO Codes, name & nativeName
  • getCountryByCapital

    • Parameters
      • query: Here we go again?
      • sort: I guess we go again, always sorts countries by COUNTRY NAME though
    • It uses regex to match with capital name ~~here we go again~~
  • getCountryByISOCode

    • Parameters
      • query: Only accepts ISO Codes now, because the first one might be too all encompassing
      • sort: Same thing all the time
    • It uses regex to match with ISO Country Codes only
  • getCountryByRegion

    • Parameters
      • query: The type has been set, please check it out in your editor [For lazy people, here is are the types]
      type Region = "Africa" | "Americas" | "Asia" | "Europe" | "Oceania";
      • sort: Usual Fare By Now NGL
    • Still uses regex because some people who use JS might misspell and regex, why not? Its better NGL
  • getCountryBySubRegion

    • It is a new addition, was not present in the API
    • Parameters
      • query: Usual stuff
      • sort: Sort countries by name length
  • getCountryByCurrencyCode

    • Gets countries by currency codes
    • Parameters
      • query: Usual query
      • sort: How many times to I tell this 🤨
  • getCountryByCallingCode

    • Gets countries by their calling code (Doesn't matter if you use + in the calling code query)
    • Parameters
      • query: Usual Query, no need to provide + of calling code
      • No sort here
  • getCountryByRegionalBloc

    • Gets countries by their regional bloc, works on both codes and Name and Other Acronyms and Alt names
    • Parameters
      • query: Name of regional bloc
      • sort: 🎉 It is back into action 😀
  • getCountryByTLD

    • New Not present in RestCountries API!
    • Parameters
      • query: No need to provide the . in the TLD, I do that for ya!
      • No sort here ~~again~~

Response Type

All Responses come in the form of type Country[]

  • Example Output
[
	{
	  "name": "Afghanistan",
	  "topLevelDomain": [
			".af",
	  ],
	  "alpha2Code": "AF",
	  "alpha3Code": "AFG",
	  "callingCodes": [
			"93",
	  ],
	  "capital": "Kabul",
	  "altSpellings": [
			"AF",
			"Afġānistān",
	  ],
	  "region": "Asia",
	  "subregion": "Southern Asia",
	  "population": 27657145,
	  "latlng": [
			33,
			65,
	  ],
	  "demonym": "Afghan",
	  "area": 652230,
	  "gini": 27.8,
	  "timezones": [
			"UTC+04:30",
	  ],
	  "borders": [
			"IRN",
			"PAK",
			"TKM",
			"UZB",
			"TJK",
			"CHN",
	  ],
	  "nativeName": "افغانستان",
	  "numericCode": "004",
	  "currencies": [
			{
		  "code": "AFN",
		  "name": "Afghan afghani",
		  "symbol": "؋",
			},
	  ],
	  "languages": [
			{
		  "iso639_1": "ps",
		  "iso639_2": "pus",
		  "name": "Pashto",
		  "nativeName": "پښتو",
			},
			{
		  "iso639_1": "uz",
		  "iso639_2": "uzb",
		  "name": "Uzbek",
		  "nativeName": "Oʻzbek",
			},
			{
		  "iso639_1": "tk",
		  "iso639_2": "tuk",
		  "name": "Turkmen",
		  "nativeName": "Türkmen",
			},
	  ],
	  "translations": {
			"de": "Afghanistan",
			"es": "Afganistán",
			"fr": "Afghanistan",
			"ja": "アフガニスタン",
			"it": "Afghanistan",
			"br": "Afeganistão",
			"pt": "Afeganistão",
			"nl": "Afghanistan",
			"hr": "Afganistan",
			"fa": "افغانستان",
	  },
	  "flag": "https://restcountries.eu/data/afg.svg",
	  "regionalBlocs": [
			{
		  "acronym": "SAARC",
		  "name": "South Asian Association for Regional Cooperation",
		  "otherAcronyms": [],
		  "otherNames": [],
			},
	  ],
	  "cioc": "AFG",
	}
]

All of the types used are exported from the package as well (for TypeScript users only), and all responses will be of this format, with possibly more objects or none.

Contact & Stuff

  • All the credit for the data goes to Restcountries
  • Need any help regarding the package? Contact me on Discord on tag SpiderBro#8604. I'll try to help as much as I can!
  • For any suggestions or additions to the package, you can go to the linked GitHub Repository. For Issues, click here & for Pull Requests, click here
  • And finally, sorry for the 🗑 Version 1, I previously made (this might be trash too for all I know), I'd made that when I was just getting into TypeScript, so I messed up big time