Want to contribute to open source? Try solving our issues here
A simple npm package to get capital, currency, native language, etc. of all the countries in the world.
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 don't 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:
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');
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, 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()
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, phone_code, and flag 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", 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" } ];
-
getCountryDetailsByName(countryName)
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.
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", flag: "https://flagpedia.net/data/flags/h80/in.png" }, ]; ```
-
getCountryDetailsByCapital(capital)
This method returns an array of objects, each containing country, capital, currency, native_language, famous_for, phone_code, and flag 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", flag: "https://flagpedia.net/data/flags/h80/in.png" }, ]; ```
-
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, phone_code, and flag.
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", 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" }, ]; ```
-
getCountriesByFamousFor(famousThing)
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.
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', 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" }, ]; ```
To fetch a random country.
const wcc = require('world-countries-capitals');
console.log(wcc.getRandomCountry());
To get count
random countries.
const wcc = require('world-countries-capitals');
console.log(wcc.getNRandomCountriesData(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.
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.
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.
Fetch all countries' details.
const wcc = require('world-countries-capitals');
console.log(wcc.getAllCountryDetails());
Get all the names of all countries.
const wcc = require('world-countries-capitals');
console.log(wcc.getAllCountries());
Get the details of all countries that are famous for 'something'.
const wcc = require('world-countries-capitals');
console.log(wcc.getCountriesByFamousFor('oil'));
In this Vue.js demo, the package methods are used to search countries by a selected field (name, capital, language, famous for)
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.
This project is licensed under the MIT License, Copyright (c) 2020 Vikrant Bhat.