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 etc. of all the countries in the world

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
695
increased by17.6%
Maintainers
1
Weekly downloads
 
Created
Source
Want to contribute to open source? check issues here.

world-countries-capitals

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

world-countries-capitals

Website

Getting started

NPM

$ npm i world-countries-capitals --save

Installation

NPM INSTALL NODE JS NODE JS

This is a Node.js module available through the npm registry.

Before using, download and install Node.js.

Installation is done using the npm install command:

$ npm i world-countries-capitals --save

Importing

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

Usage

  • getAllCountryDetails() This method returns an array of objects of all countries, each containing country, capital, currency and native_language.
    [
        {
            "country": "Afghanistan",
            "capital": "Kabul",
            "currency": "Afghani",
            "native_language": "Dari Persian, Pashto"
        },
        {
            "country": "Albania",
            "capital": "Tirane",
            "currency": "Lek",
            "native_language": "Albanian"
        },

        ...
    ]

  • getAllCountries() This method returns an array of names of all countries.
    [
        'Afghanistan',
        'Albania',
        'Algeria',
        'Andorra',
        'Angola',
        'Antigua & Barbuda',
        'Argentina',
        'Armenia',
        'Australia',
        'Austria',
        'Azerbaijan',
        ...
    ]

  • getCountiesByLanguage(languageSpoken) This method returns an array of objects, each containing country, capital, currency and native_language sorted by the languageSpoken.

Response for languageSpoken = 'Hindi'

[
	{
		country: 'Fiji',
		capital: 'Suva',
		currency: 'Fijian Dollar',
		native_language: 'english, bau fijian, hindi',
	},
	{
		country: 'India',
		capital: 'New Delhi',
		currency: 'Indian Rupee',
		native_language: 'hindi, english',
	},
];

  • getCountryDetailsByName(countryName) This method returns an array of objects, each containing country, capital, currency and native_language sorted by the name of the country .

Response for countryName = 'india'

[
	{
		country: 'india',
		capital: 'New Delhi',
		currency: 'Indian Rupee',
		native_language: 'Hindi, English',
	},
];

  • getCountryDetailsByCapital(capital) This method returns an array of objects, each containing country, capital, currency and native_language sorted by the capital .

Response for capital = 'delhi'

[
	{
		country: 'India',
		capital: 'new delhi',
		currency: 'Indian Rupee',
		native_language: 'Hindi, English',
	},
];

  • getRandomCountry() This method returns a random country everytime.
» node app.js
Tuvalu

» node app.js
Bhutan

» node app.js
Saudi Arabia
where app.js is the file containing the function call.

  • getNRandomCountriesData(n) This method returns an array having n random country objects, each object containing country, capital, currency and native_language.

Response for n = 3

[
	{
		country: 'Burundi',
		capital: 'Bujumbura',
		currency: 'Burundi Franc',
		native_language: 'Kirundi, French',
	},
	{
		country: 'Palau',
		capital: 'Melekeok',
		currency: 'United States Dollar',
		native_language: 'English, Palauan',
	},
	{
		country: 'Dominican Republic',
		capital: 'Santo Domingo',
		currency: 'Dominican Peso',
		native_language: 'Spanish',
	},
];

Examples

#1

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

console.log(wcc.getRandomCountry());

#2

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

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

#3

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

console.log(wcc.getCountryDetailsByCapital('delhi'));
in this example the parameter (capital), which has to be a string can be a written in uppercase/lowercase etc. the response will be the same.

#4

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

console.log(wcc.getCountryDetailsByName('India'));
in this example the parameter (countryName), which has to be a string can be a written in uppercase/lowercase etc. the response will be the same.

#5

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

console.log(wcc.getCountiesByLanguage('hindi'));
in this example the parameter (languageSpoken), which has to be a string can be a written in uppercase/lowercase etc. the response will be the same.

#6

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

console.log(wcc.getAllCountryDetails());

#7

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

console.log(wcc.getAllCountries());

Want to contribute?

Please check issues here!


License

GitHub license


Let's get connected

Twitter Follow

GitHub followers

LinkedIn


forthebadge forthebadge forthebadge forthebadge

Keywords

FAQs

Package last updated on 08 Feb 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