Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
world-countries-capitals
Advanced tools
A simple NPM package to get capitals, currency, native language, famous_for etc. of all the countries in the world
Want to contribute to open source? Try solving our issues here
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:
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, 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'
},
];
```
To fetch a random country.
const wcc = require('world-countries-capitals')
console.log(wcc.getRandomCountry())
To get n 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'))
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.
FAQs
A simple NPM package to get capitals, currency, native language, famous_for etc. of all the countries in the world
The npm package world-countries-capitals receives a total of 578 weekly downloads. As such, world-countries-capitals popularity was classified as not popular.
We found that world-countries-capitals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.