@data-sets/countries
v0.3.0
Published
Static data-set of countries, with additional methods for convenience.
Downloads
9
Readme
@data-sets/countries
A static list of countries to use in your own projects & services.
import countries from '@data-sets/countries';
// or
// const countries = require('@data-sets/countries');
console.log(countries.findByCode('US'));
// { id: 'Q30',
// name: 'United States of America',
// iso2: 'US',
// iso3: 'USA',
// phonePrefix: '+1',
// currencyId: 'Q4917',
// currencyCode: 'USD',
// population: '331449281',
// latlon: [ '-98.5795', '39.828175' ],
// emergencyPhone: '911',
// internetTlds: [ '.us' ],
// continentId: 'Q49',
// continentName: 'North America',
// capitalId: 'Q61',
// capitalName: 'Washington, D.C.' }
console.log(countries.findByCode('GB'));
// { id: 'Q145',
// name: 'United Kingdom',
// iso2: 'GB',
// iso3: 'GBR',
// phonePrefix: '+44',
// currencyId: 'Q25224',
// currencyCode: 'GBP',
// population: '67326569',
// latlon: [ '-2.0', '54.6' ],
// emergencyPhone: '112',
// internetTlds: [ '.uk', '.gb' ],
// continentId: 'Q46',
// continentName: 'Europe',
// capitalId: 'Q84',
// capitalName: 'London' }
Install
npm install --save @data-sets/countries
API
data
Import the complete list of countries, as an array, so you can filter
/find
/map
/reduce
as you please:
import { data } from '@data-sets/countries';
const selection = data.filter(({ currencyCode }) => {
return ['USD', 'GBP', 'EUR'].includes(currencyCode);
});
const countries = require('@data-sets/countries');
const selection = countries.data.filter(({ currencyCode }) => {
return ['USD', 'GBP', 'EUR'].includes(currencyCode);
});
findByCode
Get a country by their ISO 3166-1 alpha-2
or ISO 3166-1 alpha-3
code. Returns undefined
if the country is not found.
import { findByCode } from '@data-sets/countries';
const country = findByCode('US');
const countries = require('@data-sets/countries');
const country = countries.findByCode('USA');
Notes
- Data from a Wikidata SPARQL query.
- The raw data is available for you to review.
- View more data-sets available for use.
- Questions? Please open an issue!