Ensure that you have Node.js and npm installed. If you dont have Node.js or npm, you can download and install it here.
Before you can start using this package in your project, you need to import it. It can be imported as follows:
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.
To fetch country by capital.
Get details of a country with its name.
Fetch the details of country, with language.
This project is licensed under the MIT License, Copyright (c) 2020 Vikrant Bhat.