Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
country-list-js
Advanced tools
<script src="/path/to/country.min.js"></script>
or
npm install --save country-list-js
var country = new Country;
var found = country.find('BD', country.FIND_BY_ISO_ALPHA_2);
var found = country.find('BGD', country.FIND_BY_ISO_ALPHA_3);
var found = country.find('Bangladesh', country.FIND_BY_NAME);
var found = country.find('Capital', country.FIND_BY_CAPITAL);
var found = country.find('BDT', country.FIND_BY_CURRENCY);
var found = country.find('880', country.FIND_BY_PHONE_NUMBER);
The search option can also be hard coded as following
country.FIND_BY_ALPHA_2 = 1
country.FIND_BY_ALPHA_3 = 2
country.FIND_BY_NAME = 3
country.FIND_BY_CAPITAL = 4
country.FIND_BY_CURRENCY = 5
country.FIND_BY_PHONE_NUMBER = 6
country.find('BD', country.FIND_BY_ISO_ALPHA_2);
can be written as country.find('BD', 1);
If the country was not found, the variable found
will be null
.
The return value of all of those above will be similar to the following
{
continent: "Asia",
name: "Bangladesh",
code: {
iso_alpha_2: "BD",
iso_alpha_3: "BGD"
},
capital: "Dhaka",
currency: {
code: "BDT",
symbol: "Tk",
decimal: "2"
},
dialing_code: "880"
}
Once the search has been made, if the country was found, the information is stored in the instance. We can retrieve the information without having to search again.
var found = country.info();
var name = country.info('name'); //Bangladesh
var iso_alpha_2 = country.info('iso_alpha_2'); //BD
var iso_alpha_3 = country.info('iso_alpha_3'); //BGD
var continent = country.info('continent'); //Asia
var capital = country.info('capital'); //Dhaka
var currency = country.info('currency'); //{ code: "BDT", symbol: "Tk", decimal: "2"}
currency.code //BDT
currency.symbol //Tk
currency.decimal //2
var dialing_code = country.info('dialing_code'); //880
Added static methods since 2.0.0
import Country, {findByName, findByPhoneNumber} from 'country-list-js';
const country = Country.findByName('Bangladesh');
const country = findByName('Bangladesh');
const country = findByPhoneNumber('+8801333333333');
Available functions
getInstance
findByISOAlpha2
findByISOAlpha3
findByName
findByCapital
findByCurrency
findByPhoneNumber
(Thanks to @ekkis)npm run test
npm run build
FAQs
Country list with ISO2, ISO3 code, continent, capital, dialing code
We found that country-list-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.