UNPKG

@legendaryrob/countrify

Version:

A package to assist in the disection of ISO-3166-1(country) and ISO-3166-2(subdivision) ISO standards.

20 lines (15 loc) 446 B
const allCountries = require('../lib/countries'); /** * @name getAlpha2 * @category Country Helpers * @summary Returns all the countries as an array of strings. */ const getAlpha2 = (search) => { const countries = allCountries(); const found = countries.find(country => country.name === search || country.alpha3 === search); if (found !== undefined) { return found.alpha2; } return undefined; }; module.exports = getAlpha2;