New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

world-countries-capitals

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

world-countries-capitals - npm Package Compare versions

Comparing version 3.2.1 to 3.4.0

.github/CONTRIBUTING.md

27

data/tests/test.js

@@ -85,4 +85,27 @@ // import cheerio to web-scrape flag images

function roundTo(num, nearest = 1){
return Math.round(num/nearest)*nearest;
}
console.log("Areas Consistency Test");
var numberOfCountriesWithCorrectAreas = 0;
var totalCountries = countriesJSON.length;
for(var i = 0; i < totalCountries; i++){
var countryJSON = countriesJSON[i];
var areaInKm2 = countryJSON.area.km2;
var areaInMi2 = countryJSON.area.mi2;
var expectedAreaInMi2 = 0.386102*areaInKm2;
var roundingPlace = -3;
var roundedAreaInMi2 = roundTo(expectedAreaInMi2, Math.pow(10, roundingPlace));
while(roundedAreaInMi2){
var diff = Math.abs(roundedAreaInMi2 - areaInMi2);
if(diff<=1){
numberOfCountriesWithCorrectAreas += 1;
break;
}
roundingPlace += 1;
roundedAreaInMi2 = roundTo(expectedAreaInMi2, Math.pow(10, roundingPlace));
}
}
console.log(`Consistent: ${numberOfCountriesWithCorrectAreas}`);
console.log(`Total: ${totalCountries}\n`);

@@ -128,2 +128,118 @@ let data = require("./data/data.json");

const getCountriesByAlcoholProhibition = (prohibitionType) =>{
let value;
switch (prohibitionType) {
case "none":
value = "none";
break;
case "limited":
value = "limited";
break;
case "regional":
value = "regional";
break;
case "nationwide":
value = "nationwide";
break;
default:
throw new Error('Prohibition type must be "none", "limited", "regional" or "nationwide"');
}
return getCountriesByObject(value,"alcohol_prohibition");
}
/**
* Returns an array of objects, each containing `country`, `capital`, `currency`, `native_language`,
* `famous_for`, `phone_code`, `flag`, `drive_direction`, `continent`, `iso` and `tld`
* filtered by `continentCode`
* @param {string} continentCode The continent 2-letter code (not case-sensitive)
* @returns {Array} An array of country objects
*/
const getCountriesByContinent = (continentCode) => {
continentCode = continentCode.toLowerCase();
return data.filter(country => country.continent
.split("/")
.includes(continentCode)
);
};
/**
* Returns an array with object containing `country`, `capital`, `currency`, `native_language`,
* `famous_for`, `phone_code`, `flag`, `drive_direction`, `continent`, `iso` and `tld`
* filtered by specific `iso`
* @param {'numeric' | 'alpha_2' | 'alpha_3'} isoType The code of the country (ISO 3166-1 standard)
* @param {string} isoValue The ISO code value (not case-sensitive) of the country
* @returns {Array} An array with country object
*/
const getCountryDetailsByISO = (isoType, isoValue) => {
let type;
isoType = isoType.toLowerCase();
isoValue = isoValue.toLowerCase();
switch (isoType) {
case "numeric":
type = "numeric";
break;
case "alpha_2":
type = "alpha_2";
break;
case "alpha_3":
type = "alpha_3";
break;
default:
throw new Error("isoType must be 'numeric', 'alpha_2' or 'alpha_3'");
}
return data.filter(country => country.iso[type] === isoValue);
};
/**
* Returns an array of objects containing `country`, `capital`, `currency`, `native_language`,
* `famous_for`, `phone_code`, `flag`, `drive_direction`, `continent`, `iso` and `tld`
* filtered by `tld`
* @param {string} tldName The name (not case-sensitive) of the country code top-level domain
* @returns {Array} An array of country objects
*/
const getCountriesByTLD = (tldName) => {
tldName = tldName.toLowerCase();
return data.filter(country => country.tld
.split("/")
.includes(tldName)
);
};
/**
* Returns an array of objects containing all countries, each containing `country`, `capital`,
* `currency`, `native_language`, `famous_for`, and `phone_code`, `flag`, `drive_direction`
* and `constitutional_form` filtered by `constitutional_form`
* @param {string} constitutionalFormName Name of country constitutional form
* @returns {Array} An array of country objects
*/
const getCountriesByConstitutionalForm = (constitutionalFormName) => {
const result = data.filter((country) => {
return country.constitutional_form.includes(constitutionalFormName)
});
if (!result.length) {
throw new Error(
`No country was found! Available constitutional forms are:
'republic', 'constitutional monarchy', 'absolute monarchy' and 'n/a'
`);
}
return result;
}
/**
* Returns an array of objects containing all countries, each containing `country`, `capital`,
* `currency`, `native_language`, `famous_for`, `phone_code`, `flag` and `drive_direction` filtered by `is_landlocked`
* @param { Boolean } isLandLocked Country that is surrounded by one or more countries
* @returns {Array} An array of country objects
*/
const getCountriesByLandLock = (isLandLocked) => {
return data.filter( country => country.is_landlocked === isLandLocked);
};
module.exports = {

@@ -139,2 +255,8 @@ getRandomCountry,

getCountriesByDriveDirection,
getCountriesByAlcoholProhibition,
getCountriesByContinent,
getCountryDetailsByISO,
getCountriesByTLD,
getCountriesByConstitutionalForm,
getCountriesByLandLock,
};

2

package.json
{
"name": "world-countries-capitals",
"version": "3.2.1",
"version": "3.4.0",
"description": "A simple NPM package to get capitals, currency, native language, famous_for etc. of all the countries in the world",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,388 +0,391 @@

_Want to *contribute* to open source? Try solving our issues [here](https://github.com/bhatvikrant/world-countries-capitals/issues)_
![world-countries-capitals][ASSET_LOGO]
# world-countries-capitals
A simple [npm](https://www.npmjs.com/package/world-countries-capitals) package to get capital, currency, native language, etc. of all the countries in the world.
[![Release version][BADGE_NPM_RELEASE]][URL_NPM]
![NPM downloads][BADGE_NPM_DOWNLOADS]
[![Bundle minified size][BADGE_BUNDLE_SIZE]][URL_BUNDLEPHOBIA]
<br>
![GitHub watchers][BADGE_GH_WATCHERS]
![GitHub stars][BADGE_GH_STARS]
![GitHub forks][BADGE_GH_FORKS]
[![GitHub issues][BADGE_GH_ISSUES]][URL_GH_ISSUES]
[![GitHub pull requests][BADGE_GH_PULL_REQUESTS]][URL_GH_PULL_REQUESTS]
![world-countries-capitals](assets/world-countries-capitals.gif)
[![License][BADGE_LICENSE]][LICENSE]
[![Rate on Openbase](https://badges.openbase.io/js/rating/world-countries-capitals.svg)](https://openbase.io/js/world-countries-capitals?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
[![Openbase rating][BADGE_OPENBASE_RATING]][URL_OPENBASE]
[Demo](https://codesandbox.io/s/wcc-demo-tux1b)
---
[Docs](https://bhatvikrant.github.io/world-countries-capitals/)
## Table of Contents
## Installation
1. [Introduction][URL_INTRODUCTION]
2. [Demos][URL_DEMOS]
3. [Installation][URL_INSTALLATION]
4. [How to use][URL_HOW_TO_USE]
5. [Data model][URL_DATA_MODEL]
6. [Available methods][URL_AVAILABLE_METHODS]
7. [Contributing][URL_CONTRIBUTING]
8. [Core Team][URL_CORE_TEAM]
9. [License][URL_LICENSE]
[![npm install](http://img.shields.io/badge/npm-install-blue.svg?style=for-the-badge&logo=npm)](https://docs.npmjs.com/getting-started/installing-npm-packages-locally) [![Node.js](http://img.shields.io/badge/Node-JS-teal.svg?style=for-the-badge&logo=node.js)](https://nodejs.org/en/) [![Node.js](https://img.shields.io/npm/v/world-countries-capitals?logo=npm&label=world-countries-capitals&style=for-the-badge)](https://www.npmjs.com/package/world-countries-capitals)
---
`world-countries-capital` is a [Node.js](https://nodejs.org/en/) module, and can be installed using the npm package manager.
## Introduction
Ensure that you have Node.js and npm installed. If you don't have Node.js or npm, you can download and install it [here](https://nodejs.org/en/download/).
> **World-Countries-Capitals** is _JavaScript_ Library that give access to static data
> of all countries in the world.
Installation is done using the **[`npm install`](https://docs.npmjs.com/getting-started/installing-npm-packages-locally)** command on the terminal if you are on Linux / MacOS or on Command Prompt if you are using Windows:
Currently available data for each country is:
- **country** - country name
- **capital** - capital city
- **currency** - currency that is used
- **native_language** - list of official languages that are used in country
- **famous_for** - list of things that makes country famous for
- **phone_code** - country dial-in (calling) code
- **flag** - image of country flag
- **drive_direction** - drive direction
- **alcohol_prohibition** - status of alcohol prohibition
- **area** - country size (square kilometers and square miles)
- **continent** - 2-letter code of continent where the country is
- **iso** - country ISO 3166-1 code (numeric, alpha-2, alpha-3)
- **tld** - country code top-level domain
- **constitutional_form** - official political system
- **language_codes** - list of langauge codes (combination of _ISO 639-1_ and _ISO 3166-1 alpha-2_)
- **is_landlocked** - information whether country is surrounded by one or more countries
[![NPM](https://nodei.co/npm/world-countries-capitals.png?compact=true)](https://nodei.co/npm/world-countries-capitals/)
You can check all changes in the project at [releases page on Github][URL_GH_RELEASES]
or in [changelog][DOC_CHANGELOG].
## Importing
Feel free to give this project a ⭐️&nbsp; if it helped you! 🤗
Before you can start using this package in your project, you need to import it. It can be imported as follows:
[↑ Back to menu][URL_TOC]
```javascript
const wcc = require("world-countries-capitals");
```
## Usage
This section contains nt to _contribute_ to open source? Try solving our issues [here](https://github.com/bhatvikrant/world-countries-capitals/issues)\_
- `getAllCountryDetails()` <br>
This method returns an **array of objects** containing all countries, each containing **country**, **capital**, **currency**, **native_language**, **famous for**, **phone_code**, and its **flag**.
```javascript
[
{
"country": "afghanistan",
"capital": "kabul",
"currency": "afghani",
"native_language": ["dari persian", "pashto"],
"famous_for": "rugs, taliban",
"phone_code": "+93",
"flag": "https://flagpedia.net/data/flags/h80/af.png"
},
{
"country": "albania",
"capital": "tirane",
"currency": "lek",
"native_language": ["albanian"],
"famous_for" : "mother teresa",
"phone_code": "+355",
"flag": "https://flagpedia.net/data/flags/h80/al.png"
},
...
]
```
- `getAllCountries()` <br>
This method returns an **array** conatining the **names** of all countries.
```javascript
[
"afghanistan",
"albania",
"algeria",
"andorra",
"angola",
...
]
```
---
- `getCountriesByLanguage(languageSpoken)` <br>
This method returns an **array of objects**, each containing **country**, **capital**, **currency**, **native_language**, **famous_for**, **phone_code**, and **flag** sorted by the _languageSpoken_ passed in as a parameter.<br>
Response for getCountiesByLanguage('Hindi')
## Demos
```javascript
[
{
country: "fiji",
capital: "suva",
currency: "fijian dollar",
native_language: ["english", "bau fijian", "hindi"],
famous_for: "friendly people and heavenly tropical islands",
phone_code: "+679",
flag: "https://flagpedia.net/data/flags/h80/fj.png",
},
{
country: "india",
capital: "new delhi",
currency: "indian rupee",
native_language: ["hindi", "english"],
famous_for: "bollywood, yoga, hinduism, food and diversity",
phone_code: "+91",
flag: "https://flagpedia.net/data/flags/h80/in.png",
},
];
```
Here are demos/examples created by community ❤️
---
- [Vue.js demo](https://codesandbox.io/s/wcc-demo-tux1b)
- Search countries by a selected field
- Created by [@leodrk](https://github.com/leodrk)
- `getCountryDetailsByName(countryName)` <br>
This method returns an **array of objects**, each containing **country**, **capital**, **currency**, **native_language**, **famous_for**, **phone_code**, and **flag** sorted by the _name of the country_ passed in as a parameter.<br>
Response for getCountryDetailsByName('india')
[↑ Back to menu][URL_TOC]
```javascript
[
{
country: "india",
capital: "new delhi",
currency: "indian rupee",
native_language: ["hindi", "english"],
famous_for: "bollywood, yoga, hinduism, food and diversity",
phone_code: "+91",
flag: "https://flagpedia.net/data/flags/h80/in.png"
},
];
```
---
- `getCountryDetailsByCapital(capital)` <br>
This method returns an **array of objects**, each containing **country**, **capital**, **currency**, **native_language**, **famous_for**, **phone_code**, and **flag** sorted by the _capital_ .<br>
Response for getCountryDetailsByCapital('delhi')
## Installation
```javascript
[
{
country: "india",
capital: "new delhi",
currency: "indian rupee",
native_language: ["hindi", "english"],
famous_for: "bollywood, yoga, hinduism, food and diversity",
phone_code: "+91",
flag: "https://flagpedia.net/data/flags/h80/in.png"
},
];
```
Install with [NPM][URL_NPM]:
```
npm install world-countries-capitals
```
---
Install with [Yarn][URL_YARN]:
```
yarn add world-countries-capitals
```
- `getRandomCountry()` <br>
This method returns a random country everytime.
[↑ Back to menu][URL_TOC]
```bash
» node app.js
tuvalu
» node app.js
bhutan
» node app.js
saudi arabia
```
***Note*** : *app.js is the file containing the function call.*
---
- `getNRandomCountriesData(n)` <br>
This method returns an array having **n** number of random country objects, each object containing **country**, **capital**, **currency**, **native_language**, **famous_for**, **phone_code**, and **flag**.<br>
Sample response for n = 3
## How to use
```javascript
[
{
country: "burundi",
capital: "bujumbura",
currency: "burundi franc",
native_language: ["kirundi", "french"],
famous_for: "wildlife and greenery",
phone_code: "+257",
flag: "https://flagpedia.net/data/flags/h80/bi.png"
},
{
country: "palau",
capital: "melekeok",
currency: "united states dollar",
native_language: ["english", "palauan"],
famous_for: "jellyfish lake",
phone_code: "+680",
flag: "https://flagpedia.net/data/flags/h80/pw.png"
},
{
country: "dominican republic",
capital: "santo domingo",
currency: "dominican peso",
native_language: ["spanish"],
famous_for: "blue ocean water, white-sand beaches and beautiful resorts",
phone_code: "+1-809, +1-829, +1-849",
flag: "https://flagpedia.net/data/flags/h80/do.png"
},
];
```
Depends which way you choose to [install this package][URL_INSTALLATION],
there might be a different way to use it.
---
- _CommonJS_:
```js
// 1. Load _wcc_ Package
const wcc = require('world-countries-capitals')
- `getCountriesByFamousFor(famousThing)` <br>
This method returns an array of objects, each object containing **country**, **capital**, **currency**, **native_language**, **famouse_for**, **phone_code**, and **flag** sorted by the _famousThing_ passed as the parameter.<br>
Response for getCountriesByFamousFor('oil')
// 2. Use any _wcc_ Method
const randomCountryName = wcc.getRandomCountry()
```javascript
[
{
country: 'algeria',
capital: 'algiers',
currency: 'algerian dinar',
native_language: ['arabic', 'tamazight', 'french'],
famous_for: 'oil and gas reserves',
phone_code: '+213',
flag: "https://flagpedia.net/data/flags/h80/dz.png"
},
{
country: 'angola',
capital: 'luanda',
currency: 'kwanza',
native_language: ['portuguese'],
famous_for: 'oil',
phone_code: '+244',
flag: "https://flagpedia.net/data/flags/h80/ao.png"
},
{
country: 'bahrain',
capital: 'manama',
currency: 'bahraini dinar',
native_language: ['arabic'],
famous_for: 'oil, pearls and world heritage sites',
phone_code: '+973',
flag: "https://flagpedia.net/data/flags/h80/bh.png"
},
{
country: 'bulgaria',
capital: 'sofia',
currency: 'lev',
native_language: ['bulgarian'],
famous_for: 'lavender oil and the rose valley',
phone_code: '+359',
flag: "https://flagpedia.net/data/flags/h80/bg.png"
},
{
country: 'central african republic',
capital: 'bangui',
currency: 'central african cfa franc',
native_language: ['sango', 'french'],
famous_for: 'diamonds, gold, oil and uranium',
phone_code: '+236',
flag: "https://flagpedia.net/data/flags/h80/cf.png"
},
{
country: 'norway',
capital: 'oslo',
currency: 'norwegian krone',
native_language: ['norwegian'],
famous_for: 'oil, fjords, mountains and midnight sun',
phone_code: '+47',
flag: "https://flagpedia.net/data/flags/h80/no.png"
},
];
```
// 3. Play with returned data
console.log(randomCountryName) // Possible output: 'poland'
```
# Example Use Cases
[↑ Back to menu][URL_TOC]
#### Example #1
> To fetch a `random` country.
```javascript
const wcc = require("world-countries-capitals");
console.log(wcc.getRandomCountry());
```
---
### Example #2
## Data model
> To get the `count` of random countries.
```javascript
const wcc = require("world-countries-capitals");
console.log(wcc.getNRandomCountriesData(3));
Type definition of each `Country {Object}`:
```js
/**
* @typedef {Object} Country
* @property {String} country - Country name
* @property {String} capital - Capital city name
* @property {String} currency - Currency name
* @property {String[]} native_language - Array or native languages
* @property {String} famous_for - Comma separated favourites
* @property {String} phone_code - Phone prefix
* @property {String} flag - Flag image
* @property {String} drive_direction - Drive direction
* @property {String} alcohol_prohibition - Alcohol prohibition status
* @property {Object} area - Country size
* @property {Number} area.km2 - Country size in square kilometers
* @property {Number} area.mi2 - Country size in square miles
* @property {String} continent - Continent that country belong to
* @property {Object} iso - ISO 3166-1 standard codes
* @property {String} iso.numeric - 3-digit code
* @property {String} iso.alpha_2 - 2-letter code
* @property {String} iso.alpha_3 - 3-letter code
* @property {String} tld - Country code top-level domain
* @property {String} constitutional_form - Name of official political system
* @property {String[]} language_codes - Array of language codes
* @property {Boolean} is_landlocked - Is country surrounded by one or more countries
*/
```
---
### Example #3
> To fetch a `country` by its capital.
```javascript
const wcc = require("world-countries-capitals");
console.log(wcc.getCountryDetailsByCapital("delhi"));
Sample `Country {Object}`:
```js
{
country: 'poland',
capital: 'warsaw',
currency: 'zloty',
native_language: ['polish'],
famous_for: 'pierogi and potatoes',
phone_code: '+48',
flag: 'https://flagpedia.net/data/flags/h80/pl.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: {
km2: 312696,
mi2: 120733,
},
continent: 'eu',
iso: {
numeric: '616',
alpha_2: 'pl',
alpha_3: 'pol',
},
tld: '.pl',
constitutional_form: 'republic',
language_codes: ['pl-PL'],
is_landlocked: false
}
```
**Note :** the name of the capital (in this case, 'delhi') is **not** case sensitive and can be uppercase or lowercase and the response will remain the same.
[↑ Back to menu][URL_TOC]
---
### Example #4
## Available methods
> Get the details of a `country` with its name.
After [importing _world-countries-capitals_ Package][URL_HOW_TO_USE],
you have access to methods listed below:
```javascript
const wcc = require("world-countries-capitals");
```js
/*
* Get list of all country names
* @returns {String[]}
*/
wcc.getAllCountries()
```
console.log(wcc.getCountryDetailsByName("India"));
```js
/*
* Get all countries with details
* @returns {Country[]}
*/
wcc.getAllCountryDetails()
```
**Note :** the name of the country (in this case, 'India') is _not_ case sensitive and can be uppercase or lowercase and the response will remain the same.
```js
/*
* Get random country name
* @returns {String}
*/
wcc.getRandomCountry()
```
---
```js
/*
* Get specific amount of random countries
* @param {Number} amount - amount of countries to get
* @returns {Country[]}
*/
wcc.getNRandomCountriesData(amount)
// Example: wcc.getNRandomCountriesData(3)
### Example #5
```
> Fetch the `details of country`, with language.
```js
/*
* Get country details by its name
* @param {String} name - country name
* @returns {Country}
*/
wcc.getCountryDetailsByName(name)
// Example: wcc.getCountryDetailsByName('poland')
```
```javascript
const wcc = require("world-countries-capitals");
```js
/*
* Get country details by its capital city
* @param {String} capital - name of capital city
* @returns {Country}
*/
wcc.getCountryDetailsByCapital(capital)
// Example: wcc.getCountryDetailsByCapital('warsaw')
```
console.log(wcc.getCountiesByLanguage("hindi"));
```js
/*
* Get all countries by specific language
* @param {String} language - language name
* @returns {Country[]}
*/
wcc.getCountriesByLanguage(language)
// Example: wcc.getCountriesByLanguage('polish')
```
**Note :** the language (in this case, 'hindi') is _not_ case sensitive and can be uppercase or lowercase and the response will remain the same.
```js
/*
* Get all countries that are famous for specific thing
* @param {String} famousThing - thing that makes country famous for
* @returns {Country[]}
*/
wcc.getCountriesByFamousFor(famousThing)
// Example: wcc.getCountriesByFamousFor('pierogi')
```
---
```js
/*
* Get all countries by specific drive direction
* @param {String} direction - drive direction (one of: 'left', 'right')
* @returns {Country[]}
*/
wcc.getCountriesByDriveDirection(direction)
// Example: wcc.getCountriesByDriveDirection('left')
```
### Example #6
```js
/*
* Get all countries by alcohol prohibition type
* @param {String} type - prohibition type (one of: 'none', 'limited', 'regional', 'nationwide')
* @returns {Country[]}
*/
wcc.getCountriesByAlcoholProhibition(type)
// Example: wcc.getCountriesByAlcoholProhibition('nationwide')
```
> Fetch all `countries'` details.
```js
/*
* Get all countries that are located on specific continent
* @param {String} code - 2-letter continent code (one of: 'AF', 'AN', 'AS', 'EU', 'NA', 'OC', 'SA')
* @returns {Country[]}
*/
wcc.getCountriesByContinent(code)
// Example: wcc.getCountriesByContinent('eu')
```
```javascript
const wcc = require("world-countries-capitals");
```js
/*
* Get country found by one of _ISO 3166-1_ code type
* @param {String} isoType - ISO type (one of: 'numeric', 'alpha-2', 'alpha-3')
* @param {String} isoValue - ISO code of specific country that match to `isoType`
* @returns {Country}
*/
wcc.getCountryDetailsByISO(isoType, isoValue)
// Example: wcc.getCountryDetailsByISO('numeric', '616')
```
console.log(wcc.getAllCountryDetails());
```js
/*
* Get all countries by specific _ccTLD_
* @param {String} tld - name of the _country code top-level domain_ (including `.` character)
* @returns {Country[]}
*/
wcc.getCountriesByTLD(tld)
// Example: wcc.getCountriesByTLD('.pl')
```
---
```js
/*
* Get all countries by specific constitutional form
* @param {String} form - name of country constitutional form
* @returns {Country[]}
*/
wcc.getCountriesByConstitutionalForm(form)
// Example: wcc.getCountriesByConstitutionalForm('republic')
```
### Example #7
```js
/*
* Get all countries that are surrounded by one or more countries
* @param {Boolean} isLandLocked - is country landlocked
* @returns {Country[]}
*/
wcc.getCountriesByLandLock(isLandLocked)
// Example: wcc.getCountriesByLandLock(true)
```
> Get all the `names` of all countries.
❗️ All params are **NOT** case sensitive so no matter how argument looks,
the response will remain the same.
```javascript
const wcc = require("world-countries-capitals");
[↑ Back to menu][URL_TOC]
console.log(wcc.getAllCountries());
```
---
### Example #8
## Contributing
> Get the details of all `countries` that are famous for '_something_'.
Contributions, issues and feature requests are always welcome!
```javascript
const wcc = require("world-countries-capitals");
Feel free to check our [issues page][URL_GH_ISSUES] to see all open issues.
If this is your first time contributing to _Open Source_ project,
check out the [contributing guidelines][DOC_CONTRIBUTING] first.
console.log(wcc.getCountriesByFamousFor("oil"));
```
You can also suggest a new feature by [creating an issue][URL_GH_NEW_ISSUE].
Please wait for confirmation before working on it.
[↑ Back to menu][URL_TOC]
---
## Demo
## Core team
In this [Vue.js demo](https://codesandbox.io/s/wcc-demo-tux1b), the package methods are used to search countries by a selected field (name, capital, language, famous for)
### Vikrant Bhat
[![Vikrant Bhat GitHub profile](
https://img.shields.io/github/followers/bhatvikrant?style=flat&logo=github&logoColor=181717&label=GitHub&labelColor=FFFFFF&color=181717
)](https://github.com/bhatvikrant)
[![Vikrant Bhat Twitter profile](
https://img.shields.io/twitter/follow/vikrantbhat1022?style=flat&logo=twitter&logoColor=1DA1F2&label=Twitter&labelColor=FFFFFF&color=1DA1F2
)](https://twitter.com/vikrantbhat1022)
[![Vikrant Bhat LinkedIn profile](
https://img.shields.io/static/v1?style=flat&logo=linkedin&logoColor=0077B5&label=LinkedIn&labelColor=FFFFFF&color=0077B5&message=Vikrant%20Bhat
)](https://linkedin.com/in/vikrant-bhat-2b6221189)
<br>
[![Vikrant Bhat personal website](
https://img.shields.io/static/v1?style=flat&label=Website&labelColor=FFFFFF&color=333333&message=underreacted.netlify.app
)](https://underreacted.netlify.app)
---
### Damian Szczypka
[![Damian Szczypka GitHub profile](
https://img.shields.io/github/followers/sthiepaan?style=flat&logo=github&logoColor=181717&label=GitHub&labelColor=FFFFFF&color=181717
)](https://github.com/sthiepaan)
[![Damian Szczypka Twitter profile](
https://img.shields.io/twitter/follow/sthiepaan?style=flat&logo=twitter&logoColor=1DA1F2&label=Twitter&labelColor=FFFFFF&color=1DA1F2
)](https://twitter.com/sthiepaan)
[![Damian Szczypka LinkedIn profile](
https://img.shields.io/static/v1?style=flat&logo=linkedin&logoColor=0077B5&label=LinkedIn&labelColor=FFFFFF&color=0077B5&message=Damian%20Szczypka
)](https://linkedin.com/in/damianszczypka)
<br>
[![Damian Szczypka personal website](
https://img.shields.io/static/v1?style=flat&label=Website&labelColor=FFFFFF&color=333333&message=damianszczypka.com
)](http://damianszczypka.com)
## Want to contribute to our project?
If you'd like to see everyone who contributed to this project,
view the [contributions page][URL_GH_CONTRIBUTORS]!
<br>
Thank you to everyone who contributes! 🙌
Please check our issues **[here](https://github.com/bhatvikrant/world-countries-capitals/issues)** !
[↑ Back to menu][URL_TOC]
![](https://img.shields.io/github/contributors/bhatvikrant/world-countries-capitals) ![](https://img.shields.io/github/forks/bhatvikrant/world-countries-capitals?style=social) ![](https://img.shields.io/github/stars/bhatvikrant/world-countries-capitals?style=social)
**Note :** If you are addressing an issue that requires modification of code, remember to execute the tests, using the command **[`npm test`](https://docs.npmjs.com/cli/test)**. It ensures that things are working as they should.
---

@@ -392,14 +395,43 @@

![GitHub license](https://img.shields.io/github/license/bhatvikrant/world-countries-capitals.svg?style=for-the-badge&logo=github)
Copyright &copy; 2020 [Vikrant Bhat](https://github.com/bhatvikrant).
<br>
This project is [MIT][LICENSE] licensed.
This project is licensed under the MIT License, Copyright (c) 2020 Vikrant Bhat.
[↑ Back to menu][URL_TOC]
---
## Let's Connect
[![Twitter Follow](https://img.shields.io/twitter/follow/vikrantbhat1022.svg?style=for-the-badge&logo=twitter)](https://twitter.com/vikrantbhat1022) [![GitHub followers](https://img.shields.io/github/followers/bhatvikrant.svg?label=Follow&style=for-the-badge&logo=github)](https://github.com/bhatvikrant/) [![LinkedIn](https://img.shields.io/static/v1.svg?label=connect&message=@vikrantbhat&color=success&logo=linkedin&style=for-the-badge&logoColor=white&colorA=blue)](https://www.linkedin.com/in/vikrant-bhat-2b6221189/)
<hr>
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://github.com/bhatvikrant/world-countries-capitals) [![forthebadge](https://forthebadge.com/images/badges/made-with-javascript.svg)](https://github.com/bhatvikrant/world-countries-capitals) [![forthebadge](https://forthebadge.com/images/badges/makes-people-smile.svg)](https://github.com/bhatvikrant/world-countries-capitals) [![forthebadge](https://forthebadge.com/images/badges/check-it-out.svg)](https://github.com/bhatvikrant/world-countries-capitals)
[ASSET_LOGO]: assets/world-countries-capitals.gif
[BADGE_NPM_RELEASE]: https://img.shields.io/npm/v/world-countries-capitals?style=flat&logo=npm&label=version
[BADGE_NPM_DOWNLOADS]: https://img.shields.io/npm/dt/world-countries-capitals?style=flat&logo=npm
[BADGE_BUNDLE_SIZE]: https://img.shields.io/bundlephobia/min/world-countries-capitals?style=flat&
[BADGE_GH_WATCHERS]: https://img.shields.io/github/watchers/bhatvikrant/world-countries-capitals?style=flat&logo=github
[BADGE_GH_STARS]: https://img.shields.io/github/stars/bhatvikrant/world-countries-capitals?style=flat&logo=github
[BADGE_GH_FORKS]: https://img.shields.io/github/forks/bhatvikrant/world-countries-capitals?style=flat&logo=github
[BADGE_GH_ISSUES]: https://img.shields.io/github/issues/bhatvikrant/world-countries-capitals?style=flat&logo=github
[BADGE_GH_PULL_REQUESTS]: https://img.shields.io/github/issues-pr/bhatvikrant/world-countries-capitals?style=flat&logo=github
[BADGE_LICENSE]: https://img.shields.io/npm/l/world-countries-capitals?style=flat
[BADGE_OPENBASE_RATING]: https://badges.openbase.io/js/rating/world-countries-capitals.svg
[DOC_CHANGELOG]: CHANGELOG.md
[DOC_CONTRIBUTING]: .github/CONTRIBUTING.md
[LICENSE]: LICENSE
[URL_TOC]: #table-of-contents
[URL_INTRODUCTION]: #introduction
[URL_DEMOS]: #demos
[URL_INSTALLATION]: #installation
[URL_HOW_TO_USE]: #how-to-use
[URL_DATA_MODEL]: #data-model
[URL_AVAILABLE_METHODS]: #available-methods
[URL_CONTRIBUTING]: #contributing
[URL_CORE_TEAM]: #core-team
[URL_LICENSE]: #license
[URL_NPM]: https://www.npmjs.com/package/world-countries-capitals
[URL_YARN]: https://yarnpkg.com/package/world-countries-capitals
[URL_UNPKG]: https://unpkg.com/world-countries-capitals
[URL_BUNDLEPHOBIA]: https://bundlephobia.com/result?p=world-countries-capitals
[URL_GH_ISSUES]: https://github.com/bhatvikrant/world-countries-capitals/issues
[URL_GH_NEW_ISSUE]: https://github.com/bhatvikrant/world-countries-capitals/issues/new
[URL_GH_PULL_REQUESTS]: https://github.com/bhatvikrant/world-countries-capitals/pulls
[URL_GH_RELEASES]: https://github.com/bhatvikrant/world-countries-capitals/releases
[URL_GH_CONTRIBUTORS]: https://github.com/bhatvikrant/world-countries-capitals/graphs/contributors
[URL_OPENBASE]: https://openbase.io/js/world-countries-capitals

@@ -20,10 +20,25 @@ describe("The index", () => {

expect(countryApi.getCountryDetailsByCapital("kabul")[0]).toEqual({
country: "afghanistan",
capital: "kabul",
currency: "afghani",
native_language: ["dari persian", "pashto"],
famous_for: "rugs, taliban",
phone_code: "+93",
flag: "https://flagpedia.net/data/flags/h80/af.png",
drive_direction: "right",
"country": "afghanistan",
"capital": "kabul",
"currency": "afghani",
"native_language": ["dari persian", "pashto"],
"famous_for": "rugs, taliban",
"phone_code": "+93",
"flag": "https://flagpedia.net/data/flags/h80/af.png",
"drive_direction": "right",
"alcohol_prohibition": "nationwide",
"area": {
"km2": 652864,
"mi2": 252072
},
"continent": "as",
"iso": {
"numeric": "004",
"alpha_2": "af",
"alpha_3": "afg"
},
"tld": ".af",
"constitutional_form": "republic",
"language_codes": ["fa-AF", "ps-AF"],
"is_landlocked": true
});

@@ -36,10 +51,25 @@ });

expect(countryApi.getCountryDetailsByName("albania")[0]).toEqual({
country: "albania",
capital: "tirane",
currency: "lek",
native_language: ["albanian"],
famous_for: "mother teresa",
phone_code: "+355",
flag: "https://flagpedia.net/data/flags/h80/al.png",
drive_direction: "right",
"country": "albania",
"capital": "tirane",
"currency": "lek",
"native_language": ["albanian"],
"famous_for": "mother teresa",
"phone_code": "+355",
"flag": "https://flagpedia.net/data/flags/h80/al.png",
"drive_direction": "right",
"alcohol_prohibition": "none",
"area": {
"km2": 28748,
"mi2": 11100
},
"continent": "eu",
"iso": {
"numeric": "008",
"alpha_2": "al",
"alpha_3": "alb"
},
"tld": ".al",
"constitutional_form": "republic",
"language_codes": ["sq-AL"],
"is_landlocked": false
});

@@ -58,10 +88,25 @@ });

expect(countryApi.getCountriesByLanguage("bosnian")[0]).toEqual({
country: "bosnia and herzegovina",
capital: "sarajevo",
currency: "convertible mark",
native_language: ["bosnian", "croatian", "serbian"],
famous_for: "natural environment and cultural heritage",
phone_code: "+387",
flag: "https://flagpedia.net/data/flags/h80/ba.png",
drive_direction: "right",
"country": "bosnia and herzegovina",
"capital": "sarajevo",
"currency": "convertible mark",
"native_language": ["bosnian", "croatian", "serbian"],
"famous_for": "natural environment and cultural heritage",
"phone_code": "+387",
"flag": "https://flagpedia.net/data/flags/h80/ba.png",
"drive_direction": "right",
"alcohol_prohibition": "none",
"area": {
"km2": 51209,
"mi2": 19772
},
"continent": "eu",
"iso": {
"numeric": "070",
"alpha_2": "ba",
"alpha_3": "bih"
},
"tld": ".ba",
"constitutional_form": "republic",
"language_codes": ["bs-BA", "hr-BA", "sr-BA"],
"is_landlocked": false
});

@@ -141,2 +186,874 @@ });

});
describe("The getCountriesByAlcoholProhibition", () => {
const results = countryApi.getCountriesByAlcoholProhibition("nationwide");
const expectedResults = [
{
country: 'afghanistan',
capital: 'kabul',
currency: 'afghani',
native_language: [ 'dari persian', 'pashto' ],
famous_for: 'rugs, taliban',
phone_code: '+93',
flag: 'https://flagpedia.net/data/flags/h80/af.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 652864, mi2: 252072 },
continent: 'as',
iso: { numeric: '004', alpha_2: 'af', alpha_3: 'afg' },
tld: '.af',
constitutional_form: 'republic',
language_codes: [ 'fa-AF', 'ps-AF' ],
is_landlocked: true
},
{
country: 'brunei',
capital: 'bandar seri begawan',
currency: 'brunei dollar',
native_language: [ 'malay' ],
famous_for: 'gorgeous mosques and islamic architecture',
phone_code: '+673',
flag: 'https://flagpedia.net/data/flags/h80/bn.png',
drive_direction: 'left',
alcohol_prohibition: 'nationwide',
area: { km2: 5765, mi2: 2226 },
continent: 'as',
iso: { numeric: '096', alpha_2: 'bn', alpha_3: 'brn' },
tld: '.bn',
constitutional_form: 'absolute monarchy',
language_codes: [ 'ms-BN' ],
is_landlocked: false
},
{
country: 'djibouti',
capital: 'djibouti',
currency: 'djiboutian franc',
native_language: [ 'arabic', 'french' ],
famous_for: 'amazing landscapes, limestone vents and flamingos',
phone_code: '+253',
flag: 'https://flagpedia.net/data/flags/h80/dj.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 23200, mi2: 9000 },
continent: 'af',
iso: { numeric: '262', alpha_2: 'dj', alpha_3: 'dji' },
tld: '.dj',
constitutional_form: 'republic',
language_codes: [ 'ar-DJ', 'fr-DJ' ],
is_landlocked: false
},
{
country: 'iran',
capital: 'tehran',
currency: 'rial',
native_language: [ 'persian' ],
famous_for: 'nuclear weapon, shia muslims, poetry, persian carpet',
phone_code: '+98',
flag: 'https://flagpedia.net/data/flags/h80/ir.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 1648195, mi2: 636372 },
continent: 'as',
iso: { numeric: '364', alpha_2: 'ir', alpha_3: 'irn' },
tld: '.ir',
constitutional_form: 'republic',
language_codes: [ 'fa-IR' ],
is_landlocked: false
},
{
country: 'kuwait',
capital: 'kuwait city',
currency: 'kuwaiti dollar',
native_language: [ 'arabic', 'english' ],
famous_for: "victim of saddam's invasion",
phone_code: '965',
flag: 'https://flagpedia.net/data/flags/h80/kw.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 17818, mi2: 6880 },
continent: 'as',
iso: { numeric: '414', alpha_2: 'kw', alpha_3: 'kwt' },
tld: '.kw',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'ar-KW', 'en-KW' ],
is_landlocked: false
},
{
country: 'libya',
capital: 'tripoli',
currency: 'libyan dinar',
native_language: [ 'arabic' ],
famous_for: 'sahara desert',
phone_code: '+218',
flag: 'https://flagpedia.net/data/flags/h80/ly.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 1759540, mi2: 679360 },
continent: 'af',
iso: { numeric: '434', alpha_2: 'ly', alpha_3: 'lby' },
tld: '.ly',
constitutional_form: 'n/a',
language_codes: [ 'ar-LY' ],
is_landlocked: false
},
{
country: 'mauritania',
capital: 'nouakchott',
currency: 'ouguiya',
native_language: [ 'arabic' ],
famous_for: 'large reserves of iron ore, copper, and gypsum',
phone_code: '+222',
flag: 'https://flagpedia.net/data/flags/h80/mr.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 1030700, mi2: 398000 },
continent: 'af',
iso: { numeric: '478', alpha_2: 'mr', alpha_3: 'mrt' },
tld: '.mr',
constitutional_form: 'republic',
language_codes: [ 'ar-MR' ],
is_landlocked: false
},
{
country: 'saudi arabia',
capital: 'riyadh',
currency: 'saudi riyal',
native_language: [ 'arabic' ],
famous_for: 'strict rules, wahhabism, mecca and madina',
phone_code: '+966',
flag: 'https://flagpedia.net/data/flags/h80/sa.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 2149690, mi2: 830000 },
continent: 'as',
iso: { numeric: '682', alpha_2: 'sa', alpha_3: 'sau' },
tld: '.sa',
constitutional_form: 'absolute monarchy',
language_codes: [ 'ar-SA' ],
is_landlocked: false
},
{
country: 'somalia',
capital: 'mogadishu',
currency: 'somali shilling',
native_language: [ 'somali', 'arabic' ],
famous_for: 'frankincense and myrrh',
phone_code: '+252',
flag: 'https://flagpedia.net/data/flags/h80/so.png',
drive_direction: 'right',
alcohol_prohibition: 'nationwide',
area: { km2: 637657, mi2: 246201 },
continent: 'af',
iso: { numeric: '706', alpha_2: 'so', alpha_3: 'som' },
tld: '.so',
constitutional_form: 'republic',
language_codes: [ 'so-SO' ],
is_landlocked: false
}
];
it("returns the details of all countries where nationwide alcohol prohibition is applicable", () => {
expect(results).toEqual(expectedResults);
});
it("returns the total number of countries where no alcohol prohibition is applicable", () => {
expect(countryApi.getCountriesByAlcoholProhibition("none").length).toEqual(176);
});
});
describe("The getCountryDetailsByCapital when given a capital", () => {
it("returns the details of countries with that capital", () => {
expect(countryApi.getCountryDetailsByCapital("kabul")[0]).toEqual({
"country": "afghanistan",
"capital": "kabul",
"currency": "afghani",
"native_language": ["dari persian", "pashto"],
"famous_for": "rugs, taliban",
"phone_code": "+93",
"flag": "https://flagpedia.net/data/flags/h80/af.png",
"drive_direction": "right",
"alcohol_prohibition": "nationwide",
"area": {
"km2": 652864,
"mi2": 252072
},
"continent": "as",
"iso": {
"numeric": "004",
"alpha_2": "af",
"alpha_3": "afg"
},
"tld": ".af",
"constitutional_form": "republic",
"language_codes": ["fa-AF", "ps-AF"],
"is_landlocked": true
});
});
});
describe("The getCountryDetailsByName when given a country's name", () => {
it("returns the countries with that name", () => {
expect(countryApi.getCountryDetailsByName("albania")[0]).toEqual({
"country": "albania",
"capital": "tirane",
"currency": "lek",
"native_language": ["albanian"],
"famous_for": "mother teresa",
"phone_code": "+355",
"flag": "https://flagpedia.net/data/flags/h80/al.png",
"drive_direction": "right",
"alcohol_prohibition": "none",
"area": {
"km2": 28748,
"mi2": 11100
},
"continent": "eu",
"iso": {
"numeric": "008",
"alpha_2": "al",
"alpha_3": "alb"
},
"tld": ".al",
"constitutional_form": "republic",
"language_codes": ["sq-AL"],
"is_landlocked": false
});
});
});
describe("The getCountriesByDriveDirection when given a country's drive direction", () => {
it("returns the countries that use this driving direction", () => {
expect(countryApi.getCountriesByDriveDirection("left").length).toBe(46);
});
});
describe("The getCountriesByLanguage when given a language", () => {
it("returns countries with that language being their native language", () => {
expect(countryApi.getCountriesByLanguage("bosnian")[0]).toEqual({
"country": "bosnia and herzegovina",
"capital": "sarajevo",
"currency": "convertible mark",
"native_language": ["bosnian", "croatian", "serbian"],
"famous_for": "natural environment and cultural heritage",
"phone_code": "+387",
"flag": "https://flagpedia.net/data/flags/h80/ba.png",
"drive_direction": "right",
"alcohol_prohibition": "none",
"area": {
"km2": 51209,
"mi2": 19772
},
"continent": "eu",
"iso": {
"numeric": "070",
"alpha_2": "ba",
"alpha_3": "bih"
},
"tld": ".ba",
"constitutional_form": "republic",
"language_codes": ["bs-BA", "hr-BA", "sr-BA"],
"is_landlocked": false
});
});
});
describe("The getAllCountryDetails", () => {
it("returns the details of all countries", () => {
expect(countryApi.getAllCountryDetails().length).toEqual(196);
});
});
describe("The getAllCountries", () => {
it("returns all of the countries", () => {
expect(countryApi.getAllCountries().length).toEqual(196);
});
});
describe("The getCountriesByFamousFor", () => {
const actualCountries = countryApi.getCountriesByFamousFor("oil");
const expectedCountries = [
{
country: "algeria",
capital: "algiers",
currency: "algerian dinar",
native_language: ["arabic", "tamazight", "french"],
famous_for: "oil and gas reserves",
phone_code: "+213",
},
{
country: "angola",
capital: "luanda",
currency: "kwanza",
native_language: ["portuguese"],
famous_for: "oil",
phone_code: "+244",
},
{
country: "bahrain",
capital: "manama",
currency: "bahraini dinar",
native_language: ["arabic"],
famous_for: "oil, pearls and world heritage sites",
phone_code: "+973",
},
{
country: "bulgaria",
capital: "sofia",
currency: "lev",
native_language: ["bulgarian"],
famous_for: "lavender oil and the rose valley",
phone_code: "+359",
},
{
country: "central african republic",
capital: "bangui",
currency: "central african cfa franc",
native_language: ["sango", "french"],
famous_for: "diamonds, gold, oil and uranium",
phone_code: "+236",
},
{
country: "norway",
capital: "oslo",
currency: "norwegian krone",
native_language: ["norwegian"],
famous_for: "oil, fjords, mountains and midnight sun",
phone_code: "+47",
},
];
it("returns countries famous for oil", () => {
expect(
testUtils.countryArraysAreEqual(actualCountries, expectedCountries)
).toBeTrue();
});
});
describe("The getCountriesByContinent", () => {
const africaCountries = countryApi.getCountriesByContinent("AF");
const europeCountries = countryApi.getCountriesByContinent("eu");
const oceaniaCountries = countryApi.getCountriesByContinent("oc");
const expectedOceaniaCountries = [
{
country: 'australia',
capital: 'canberra',
currency: 'australian dollar',
native_language: [ 'english' ],
famous_for: 'koalas and kangaroos',
phone_code: '+61',
flag: 'https://flagpedia.net/data/flags/h80/au.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 7692024, mi2: 2969907 },
continent: 'oc',
iso: { numeric: '036', alpha_2: 'au', alpha_3: 'aus' },
tld: '.au',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-AU' ],
is_landlocked: false
},
{
country: 'fiji',
capital: 'suva',
currency: 'fijian dollar',
native_language: [ 'english', 'bau fijian', 'hindi' ],
famous_for: 'friendly people and heavenly tropical islands',
phone_code: '+679',
flag: 'https://flagpedia.net/data/flags/h80/fj.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 18272, mi2: 7055 },
continent: 'oc',
iso: { numeric: '242', alpha_2: 'fj', alpha_3: 'fji' },
tld: '.fj',
constitutional_form: 'republic',
language_codes: [ 'en-FJ', 'fj-FJ' ],
is_landlocked: false
},
{
country: 'kiribati',
capital: 'tarawa atoll',
currency: 'kiribati dollar',
native_language: [ 'english', 'gilbertese' ],
famous_for: 'flyfishing, scuba diving and astounding seabird wildlife',
phone_code: '+686',
flag: 'https://flagpedia.net/data/flags/h80/ki.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 811, mi2: 313 },
continent: 'oc',
iso: { numeric: '296', alpha_2: 'ki', alpha_3: 'kir' },
tld: '.ki',
constitutional_form: 'republic',
language_codes: [ 'en-KI' ],
is_landlocked: false
},
{
country: 'marshall islands',
capital: 'majuro',
currency: 'united states dollar',
native_language: [ 'marshallese', 'english' ],
famous_for: 'being fierce and hostile to strangers',
phone_code: '+692',
flag: 'https://flagpedia.net/data/flags/h80/mh.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 181, mi2: 70 },
continent: 'oc',
iso: { numeric: '584', alpha_2: 'mh', alpha_3: 'mhl' },
tld: '.mh',
constitutional_form: 'republic',
language_codes: [ 'en-MH', 'mh-MH' ],
is_landlocked: false
},
{
country: 'federal states of micronesia',
capital: 'palikir',
currency: 'united states dollar',
native_language: [ 'english' ],
famous_for: 'manta rays, eco-tourism',
phone_code: '+691',
flag: 'https://flagpedia.net/data/flags/h80/fm.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 702, mi2: 271 },
continent: 'oc',
iso: { numeric: '583', alpha_2: 'fm', alpha_3: 'fsm' },
tld: '.fm',
constitutional_form: 'republic',
language_codes: [ 'en-FM' ],
is_landlocked: false
},
{
country: 'nauru',
capital: 'yaren',
currency: 'australian dollar',
native_language: [ 'english', 'nauran' ],
famous_for: 'islands of banaba',
phone_code: '+674',
flag: 'https://flagpedia.net/data/flags/h80/nr.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 21, mi2: 8.1 },
continent: 'oc',
iso: { numeric: '520', alpha_2: 'nr', alpha_3: 'nru' },
tld: '.nr',
constitutional_form: 'republic',
language_codes: [ 'en-NR', 'na-NR' ],
is_landlocked: false
},
{
country: 'new zealand',
capital: 'wellington',
currency: 'new zealand dollar',
native_language: [ 'english' ],
famous_for: 'national rugby team',
phone_code: '+64',
flag: 'https://flagpedia.net/data/flags/h80/nz.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 270467, mi2: 104428 },
continent: 'oc',
iso: { numeric: '554', alpha_2: 'nz', alpha_3: 'nzl' },
tld: '.nz',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-NZ' ],
is_landlocked: false
},
{
country: 'palau',
capital: 'melekeok',
currency: 'united states dollar',
native_language: [ 'english', 'palauan' ],
famous_for: 'jellyfish lake',
phone_code: '+680',
flag: 'https://flagpedia.net/data/flags/h80/pw.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 459, mi2: 177 },
continent: 'oc',
iso: { numeric: '585', alpha_2: 'pw', alpha_3: 'plw' },
tld: '.pw',
constitutional_form: 'republic',
language_codes: [ 'en-PW' ],
is_landlocked: false
},
{
country: 'papa new guinea',
capital: 'port moresby papa',
currency: 'papa new guinean kina',
native_language: [ 'english', 'tok pisin', 'hiri motu' ],
famous_for: 'scuba diving and marine diversity',
phone_code: '+675',
flag: 'https://flagpedia.net/data/flags/h80/pg.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 462840, mi2: 178700 },
continent: 'oc',
iso: { numeric: '598', alpha_2: 'pg', alpha_3: 'png' },
tld: '.pg',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-PG' ],
is_landlocked: false
},
{
country: 'samoa',
capital: 'apia',
currency: 'tala',
native_language: [ 'samoan', 'english' ],
famous_for: 'samoan culture, music, dance and visual arts',
phone_code: '+685',
flag: 'https://flagpedia.net/data/flags/h80/ws.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 2842, mi2: 1097 },
continent: 'oc',
iso: { numeric: '882', alpha_2: 'ws', alpha_3: 'wsm' },
tld: '.ws',
constitutional_form: 'republic',
language_codes: [ 'en-WS', 'sm-WS' ],
is_landlocked: false
},
{
country: 'solomon islands',
capital: 'honiara',
currency: 'solomon islands dollar',
native_language: [ 'solomons pijin' ],
famous_for: 'world war 2',
phone_code: '+677',
flag: 'https://flagpedia.net/data/flags/h80/sb.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 28896, mi2: 11157 },
continent: 'oc',
iso: { numeric: '090', alpha_2: 'sb', alpha_3: 'slb' },
tld: '.sb',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-SB' ],
is_landlocked: false
},
{
country: 'tonga',
capital: "nuku'alofa",
currency: "pa'anga",
native_language: [ 'tongan', 'english' ],
famous_for: 'graceful and dignified dancing of the kingdom',
phone_code: '+676',
flag: 'https://flagpedia.net/data/flags/h80/to.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 747, mi2: 288 },
continent: 'oc',
iso: { numeric: '776', alpha_2: 'to', alpha_3: 'ton' },
tld: '.to',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-TO', 'to-TO' ],
is_landlocked: false
},
{
country: 'tuvalu',
capital: 'vaiaku',
currency: 'tuvaluan dollar',
native_language: [ 'tuvaluan', 'english' ],
famous_for: 'seafaring skills',
phone_code: '+668',
flag: 'https://flagpedia.net/data/flags/h80/tv.png',
drive_direction: 'left',
alcohol_prohibition: 'none',
area: { km2: 26, mi2: 10 },
continent: 'oc',
iso: { numeric: '798', alpha_2: 'tv', alpha_3: 'tuv' },
tld: '.tv',
constitutional_form: 'constitutional monarchy',
language_codes: [ 'en-TV' ],
is_landlocked: false
},
{
country: 'vanuatu',
capital: 'port-vila',
currency: 'vanuatu vatu',
native_language: [ 'bislama', 'english', 'french' ],
famous_for: "vanuatu's underwater world",
phone_code: '+978',
flag: 'https://flagpedia.net/data/flags/h80/vu.png',
drive_direction: 'right',
alcohol_prohibition: 'none',
area: { km2: 12189, mi2: 4706 },
continent: 'oc',
iso: { numeric: '548', alpha_2: 'vu', alpha_3: 'vut' },
tld: '.vu',
constitutional_form: 'republic',
language_codes: [ 'bi-VU', 'en-VU', 'fr-VU' ],
is_landlocked: false
},
];
const asiaCountries = countryApi.getCountriesByContinent("as");
const [russiaCountry] = countryApi.getCountryDetailsByName("russia");
it("returns correct amount of africa countries (uppercase)", () => {
expect(africaCountries.length).toBe(55);
});
it("returns correct amount of europe countries", () => {
expect(europeCountries.length).toBe(47);
});
it("returns all oceania countries", () => {
expect(oceaniaCountries).toEqual(expectedOceaniaCountries);
});
it("returns the same country using 'eu' or 'as' continent", () => {
expect(europeCountries).toContain(jasmine.objectContaining(russiaCountry));
expect(asiaCountries).toContain(jasmine.objectContaining(russiaCountry));
});
});
describe("The getCountryDetailsByISO", () => {
const [numericCountry] = countryApi.getCountryDetailsByISO("numeric", "616");
const [alpha2Country] = countryApi.getCountryDetailsByISO("ALPHA_2", "PL");
const [alpha3Country] = countryApi.getCountryDetailsByISO("alpha_3", "pol");
const expectedCountry = {
country: "poland",
capital: "warsaw",
currency: "zloty",
native_language: ["polish"],
famous_for: "pierogi and potatoes",
phone_code: "+48",
flag: "https://flagpedia.net/data/flags/h80/pl.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
km2: 312696,
mi2: 120733,
},
continent: "eu",
iso: {
numeric: "616",
alpha_2: "pl",
alpha_3: "pol",
},
tld: ".pl",
constitutional_form: "republic",
language_codes: ["pl-PL"],
is_landlocked: false,
};
it("returns correct country using numeric ISO", () => {
expect(numericCountry).toEqual(expectedCountry);
});
it("returns correct country using Alpha-2 ISO (uppercase)", () => {
expect(alpha2Country).toEqual(expectedCountry);
});
it("returns correct country using Alpha-3 ISO", () => {
expect(alpha3Country).toEqual(expectedCountry);
});
});
describe("The getCountriesByTLD", () => {
const [dotPLCountry] = countryApi.getCountriesByTLD(".pl");
const expectedDotPLCountry = {
country: "poland",
capital: "warsaw",
currency: "zloty",
native_language: ["polish"],
famous_for: "pierogi and potatoes",
phone_code: "+48",
flag: "https://flagpedia.net/data/flags/h80/pl.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
km2: 312696,
mi2: 120733,
},
continent: "eu",
iso: {
numeric: "616",
alpha_2: "pl",
alpha_3: "pol",
},
tld: ".pl",
constitutional_form: "republic",
language_codes: ["pl-PL"],
is_landlocked: false,
};
const dotRSCountries = countryApi.getCountriesByTLD(".RS");
const expectedDotRSCountries = [
{
country: "kosovo",
capital: "pristina",
currency: "euro",
native_language: ["albanian", "serbian"],
famous_for: "mountains and wine",
phone_code: "+383",
flag: "https://flagpedia.net/data/flags/h80/xk.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
km2: 10887,
mi2: 4203,
},
continent: "eu",
iso: {
numeric: "383",
alpha_2: "xk",
alpha_3: "xkx",
},
tld: ".rs",
constitutional_form: "republic",
language_codes: ["sr-XK", "sq-XK"],
is_landlocked: true,
},
{
country: "serbia",
capital: "belgrade",
currency: "serbian dinar",
native_language: ["serbian"],
famous_for: "culture, history, delicious cuisine, and nightlife",
phone_code: "+381",
flag: "https://flagpedia.net/data/flags/h80/rs.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
km2: 88361,
mi2: 34116,
},
continent: "eu",
iso: {
numeric: "688",
alpha_2: "rs",
alpha_3: "srb"
},
tld: ".rs",
constitutional_form: "republic",
language_codes: ["sr-RS"],
is_landlocked: true,
},
];
const [dotUKCountry] = countryApi.getCountriesByTLD(".uk");
const expectedDotUKCountry = {
country: "united kingdom",
capital: "london",
currency: "pound sterling",
native_language: ["english"],
famous_for: "david beckham, fish and chips, big ben, red buses, black cabs, oasis, blur, the beatles, london and tea",
phone_code: "+44",
flag: "https://flagpedia.net/data/flags/h80/gb.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
km2: 242495,
mi2: 93628,
},
continent: "eu",
iso: {
numeric: "826",
alpha_2: "gb",
alpha_3: "gbr",
},
tld: ".gb/.uk",
constitutional_form: "constitutional monarchy",
language_codes: ["en-GB"],
is_landlocked: false,
};
const [dotGBCountry] = countryApi.getCountriesByTLD(".GB");
it("returns correct country using '.pl' domain", () => {
expect(dotPLCountry).toEqual(expectedDotPLCountry);
});
it("returns correct countries using '.RS' (uppercase) domain", () => {
expect(dotRSCountries).toEqual(expectedDotRSCountries);
});
it("returns correct country using '.uk' domain", () => {
expect(dotUKCountry).toEqual(expectedDotUKCountry);
});
it("returns the same country using '.uk' or '.GB' (uppercase) domain", () => {
expect(dotUKCountry).toEqual(dotGBCountry);
});
});
describe("The getCountriesByConstitutionalForm", () => {
const republicCountries = countryApi.getCountriesByConstitutionalForm("republic");
const monarchyCountries = countryApi.getCountriesByConstitutionalForm("monarchy");
const absoluteMonarchyCountries = countryApi
.getCountriesByConstitutionalForm("absolute monarchy");
const constitutionalMonarchyCountries = countryApi
.getCountriesByConstitutionalForm("constitutional monarchy");
it("returns the countries that have 'republic' constitutional form", () => {
expect(republicCountries.length).toBe(148);
});
it("returns the countries that have 'monarchy' constitutional form", () => {
expect(monarchyCountries.length).toBe(44);
});
it("returns the countries that have 'absolute monarchy' constitutional form", () => {
expect(absoluteMonarchyCountries.length).toBe(6);
});
it("returns the countries that have 'constitutional monarchy' constitutional form", () => {
expect(constitutionalMonarchyCountries.length)
.toBe(monarchyCountries.length - absoluteMonarchyCountries.length);
});
});
describe("The getAllCountriesByLandlock", () => {
const landLockedCountries = countryApi.getCountriesByLandLock(true);
const notLandLockedCountries = countryApi.getCountriesByLandLock(false);
it("returns all the landlocked countries", () => {
expect(landLockedCountries.length).toEqual(45);
});
it("returns all the countries which are not landlocked", () => {
expect(notLandLockedCountries.length).toEqual(151);
});
it("returns countries with isLandLocked set to true", () => {
expect(landLockedCountries[0]).toEqual({
country: "afghanistan",
capital: "kabul",
currency: "afghani",
native_language: ["dari persian", "pashto"],
famous_for: "rugs, taliban",
phone_code: "+93",
flag: "https://flagpedia.net/data/flags/h80/af.png",
drive_direction: "right",
alcohol_prohibition: 'nationwide',
continent: "as",
iso: {
numeric: "004",
alpha_2: "af",
alpha_3: "afg",
},
tld: ".af",
constitutional_form: "republic",
language_codes: ["fa-AF", "ps-AF"],
area: {
"km2": 652864,
"mi2": 252072,
},
is_landlocked: true,
});
});
it("returns countries with isLandLocked set to false", () => {
expect(notLandLockedCountries[0]).toEqual({
country: "albania",
capital: "tirane",
currency: "lek",
native_language: ["albanian"],
famous_for: "mother teresa",
phone_code: "+355",
flag: "https://flagpedia.net/data/flags/h80/al.png",
drive_direction: "right",
alcohol_prohibition: 'none',
area: {
"km2": 28748,
"mi2": 11100,
},
continent: "eu",
iso: {
numeric: "008",
alpha_2: "al",
alpha_3: "alb",
},
tld: ".al",
constitutional_form: "republic",
language_codes: ["sq-AL"],
is_landlocked: false,
});
});
});
});

@@ -34,2 +34,2 @@ function countriesAreEqual(actualCountry, expectedCountry) {

countryArraysAreEqual
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc