What is country-list?
The country-list npm package provides a simple way to get a list of countries and their corresponding ISO 3166-1 alpha-2 codes. It is useful for applications that need to display country names, validate country codes, or convert between country names and codes.
What are country-list's main functionalities?
Get all countries
This feature allows you to retrieve a list of all countries along with their ISO 3166-1 alpha-2 codes.
const countries = require('country-list')().getData();
console.log(countries);
Get country name by code
This feature allows you to get the name of a country by providing its ISO 3166-1 alpha-2 code.
const countryList = require('country-list')();
const countryName = countryList.getName('US');
console.log(countryName);
Get country code by name
This feature allows you to get the ISO 3166-1 alpha-2 code of a country by providing its name.
const countryList = require('country-list')();
const countryCode = countryList.getCode('United States');
console.log(countryCode);
Add a custom country
This feature allows you to add a custom country to the list with a specified code and name.
const countryList = require('country-list')();
countryList.add({ code: 'XX', name: 'New Country' });
console.log(countryList.getData());
Remove a country
This feature allows you to remove a country from the list by providing its ISO 3166-1 alpha-2 code.
const countryList = require('country-list')();
countryList.remove('XX');
console.log(countryList.getData());
Other packages similar to country-list
i18n-iso-countries
The i18n-iso-countries package provides a comprehensive list of countries with support for multiple languages. It allows you to get country names and codes, and also supports translations for country names in various languages. Compared to country-list, it offers more extensive localization features.
country-data
The country-data package provides detailed information about countries, including their names, codes, currencies, and regions. It offers more detailed data compared to country-list, making it suitable for applications that need more than just country names and codes.
countries-list
The countries-list package provides a list of countries with their names, codes, and other related information. It is similar to country-list but includes additional data such as country calling codes and regions.
country-list
Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.
Uses data from http://data.okfn.org/data/country-list
Example
var countries = require('country-list')();
console.log(countries.getName('IS'));
console.log(countries.getCode('Iceland'));
Methods
Usage:
var countries = require('country-list')();
All input is case-insensitive.
getName(code)
Expects a two-digit country code.
Returns the name for that country.
If not found, it returns undefined
.
getCode(name)
Expects the English country name.
Returns the code for that country.
If not found, it returns undefined
.
getNames()
Returns an array of all country names.
getCodes()
Returns an array of all country codes.
getNameList()
Returns a key-value object of all countries using the name as key.
getCodeList()
Returns a key-value object of all countries using the code as key.
getData()
Returns an array of all country information, in the same format as it gets imported.
Install
npm install country-list
License
MIT