UNPKG

iso-country

Version:
27 lines (26 loc) 908 B
"use strict"; function getEmoji(code) { return code.toUpperCase().replace(/./g, function (char) { return String.fromCodePoint(char.charCodeAt(0) + 127397); }); } function getUnicode(str) { if (str.length < 4) { return str.codePointAt(0).toString(16); } return str.codePointAt(0).toString(16) + ' ' + str.codePointAt(2).toString(16); } fetch('https://restcountries.eu/rest/v2/all') .then(function (result) { return result.json(); }) .then(function (countries) { var output = countries.map(function (country) { var emoji = getEmoji(country.alpha2Code); return { iso2: country.alpha2Code, iso3: country.alpha3Code, name: country.name, localName: country.nativeName, emoji: emoji, emojiCode: getUnicode(emoji).toUpperCase() }; }); console.log(JSON.stringify(output)); });