README
countries-db
This is a minimalistic library to work with countries data.
Usage
NodeJS
Install with npm or yarn:
npm install --save countries-db
Browser
Add the following script to your project (only ~9kb):
<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-db@latest/dist/index.js" type="text/javascript"></script>
<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-db@v1.2.0/dist/index.js" type="text/javascript"></script>
<!-- This will export a variable named "countriesDb": -->
<script type="text/javascript">
var data = countriesDb.getCountry('US');
console.log(data);
</script>
API
.getCountry(id, [property])
Returns a country referenced by its id
.
If the property
argument is specified, it will only return the value of that property.
Example
const countriesDB = require('countries-db');
const population = countriesDB.getCountry('MX', 'population');
console.log(population);
/*
Prints: 112468855
*/
const country = countriesDB.getCountry('MX');
console.log(country);
/*
Prints:
{
id: 'MX',
name: 'Mexico',
officialName: 'The United Mexican States',
emoji: '🇲🇽',
emojiUnicode: 'U+1F1F2 U+1F1FD',
iso2: 'MX',
iso3: 'MEX',
isoNumeric: '484',
geonameId: 3996063,
continentId: 'NA',
population: 112468855,
elevation: 2062,
areaSqKm: 1972550,
coordinates: {
latitude: 23,
longitude: -102
},
timezones: [
'America/Bahia_Banderas',
'America/Cancun',
'America/Chihuahua',
'America/Ensenada',
'America/Hermosillo',
'America/Matamoros',
'America/Mazatlan',
'America/Merida',
'America/Mexico_City',
'America/Monterrey',
'America/Ojinaga',
'America/Santa_Isabel',
'America/Tijuana'
],
domain: '.mx',
currencyCode: 'MXN',
currencyName: 'Peso',
postalCodeFormat: '#####',
postalCodeRegex: '^(\\d{5})