Huge News!Announcing our $40M Series B led by Abstract Ventures.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

A simple NPM package to get capitals, currency, native language, famous_for etc. of all the countries in the world

  • 3.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Want to contribute to open source? Try solving our issues here

world-countries-capitals

A simple NPM package to get capital, currency, native language, etc. of all the countries in the world.

world-countries-capitals

Demo

Docs

Installation

NPM INSTALL NODE JS NODE JS

world-countries-capital is a Node.js module, and can be installed using the npm package manager.

Ensure that you have Node.js and npm installed. If you dont have Node.js or npm, you can download and install it here.

Installation is done using the npm install command on the terminal if you are on Linux / MacOS or on Command Prompt if you are using Windows:

NPM

Importing

Before you can start using this package in your project, you need to import it. It can be imported as follows:

const wcc = require('world-countries-capitals');

Usage

This section contains information about various functions that are currently supported.

  • getAllCountryDetails()
    This method returns an array of objects containing all countries, each containing country, capital, currency, native_language, famous for, and its phone_code.

    	```javascript
    	[
    		{
    			"country": "afghanistan",
    			"capital": "kabul",
    			"currency": "afghani",
    			"native_language": ["dari persian", "pashto"],
    			"famous_for": "rugs, taliban",
    			"phone_code": "+93"
    		},
    		{
    			"country": "albania",
    			"capital": "tirane",
    			"currency": "lek",
    			"native_language": ["albanian"],
    			"famous_for" : "mother teresa",
    			"phone_code": "+355"
    		},
    		...
    	]
    	```
    
  • getAllCountries()
    This method returns an array conatining the names of all countries.

    	```javascript
    	[
    		"afghanistan",
    		"albania",
    		"algeria",
    		"andorra",
    		"angola",
    		...
    	]
    	```
    
  • getCountiesByLanguage(languageSpoken)
    This method returns an array of objects, each containing country, capital, currency, native_language, famous_for, and phone_code sorted by the languageSpoken passed in as a parameter.
    Response for getCountiesByLanguage('Hindi')

    [
    	{
    		country: "fiji",
    		capital: "suva",
    		currency: "fijian dollar",
    		native_language: ["english", "bau fijian", "hindi"],
    		famous_for: "friendly people and heavenly tropical islands",
    		phone_code: "+679"
    	},
    	{
    		country: "india",
    		capital: "new delhi",
    		currency: "indian rupee",
    		native_language: ["hindi", "english"],
    		famous_for: "bollywood, yoga, hinduism, food and diversity",
    		phone_code: "+91"
    	}
    ];
    
  • getCountryDetailsByName(countryName)
    This method returns an array of objects, each containing country, capital, currency, native_language, famous_for and phone_code sorted by the name of the country passed in as a parameter.
    Response for getCountryDetailsByName('india')

    	```javascript
    	[
    		{
    			country: "india",
    			capital: "new delhi",
    			currency: "indian rupee",
    			native_language: ["hindi", "english"],
    			famous_for: "bollywood, yoga, hinduism, food and diversity",
    			phone_code: "+91"
    		},
    	];
    	```
    
  • getCountryDetailsByCapital(capital)
    This method returns an array of objects, each containing country, capital, currency and native_language sorted by the capital .
    Response for getCountryDetailsByCapital('delhi')

    	```javascript
    	[
    		{
    			country: "india",
    			capital: "new delhi",
    			currency: "indian rupee",
    			native_language: ["hindi", "english"],
    			famous_for: "bollywood, yoga, hinduism, food and diversity",
    			phone_code: "+91"
    		},
    	];
    	```
    
  • getRandomCountry()
    This method returns a random country everytime.

    	```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)
    This method returns an array having n number of random country objects, each object containing country, capital, currency, native_language, famous_for, and phone_code.
    Sample response for n = 3

    	```javascript
    	[
    		{
    			country: "burundi",
    			capital: "bujumbura",
    			currency: "burundi franc",
    			native_language: ["kirundi", "french"],
    			famous_for: "wildlife and greenery",
    			phone_code: "+257"
    		},
    		{
    			country: "palau",
    			capital: "melekeok",
    			currency: "united states dollar",
    			native_language: ["english", "palauan"],
    			famous_for: "jellyfish lake",
    			phone_code: "+680"
    		},
    		{
    			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"
    		},
    	];
    	```
    
  • getCountriesByFamousFor(famousThing)
    This method returns an array of objects, each object containing country, capital, currency, native_language, famouse_for and phone_code sorted by the famousThing passed as the parameter.
    Response for getCountriesByFamousFor('oil')

    	```javascript
    	[
    		{
    			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'
    		},
    	];
    	```
    

Example Use Cases

Example #1

To fetch a random country.

const wcc = require('world-countries-capitals');

console.log(wcc.getRandomCountry());
Example #2

To get n random countries.

const wcc = require('world-countries-capitals');

console.log(wcc.getNRandomCountriesData(3));
Example #3

To fetch country by capital.

const wcc = require('world-countries-capitals');

console.log(wcc.getCountryDetailsByCapital('delhi'));

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.

Example #4

Get details of a country with its name.

const wcc = require('world-countries-capitals');

console.log(wcc.getCountryDetailsByName('India'));

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.

Example #5

Fetch the details of country, with language.

const wcc = require('world-countries-capitals');

console.log(wcc.getCountiesByLanguage('hindi'));

Note : the language (in this case, 'hindi') is not case sensitive and can be uppercase or lowercase and the response will remain the same.

Example #6

Fetch all countries' details.

const wcc = require('world-countries-capitals');

console.log(wcc.getAllCountryDetails());
Example #7

Get all the names of all countries.

const wcc = require('world-countries-capitals');

console.log(wcc.getAllCountries());
Example #8

Get the details of all countries that are famous for 'something'.

const wcc = require('world-countries-capitals');

console.log(wcc.getCountriesByFamousFor('oil'));

Demo

In this Vue.js demo, the package methods are used to search countries by a selected field (name, capital, language, famous for)

Want to contribute to our project?

Please check our issues here !

Note : If you are addressing an issue that requires modification of code, remember to execute the tests, using the command npm test. It ensures that things are working as they should.


License

GitHub license

This project is licensed under the MIT License, Copyright (c) 2020 Vikrant Bhat.


Let's Connect

Twitter Follow GitHub followers LinkedIn


forthebadge forthebadge forthebadge forthebadge

Keywords

FAQs

Package last updated on 10 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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