Created
July 4, 2019 11:55
-
-
Save theory-of-soul/220dfe7a7f383325510be31ffb0d362e to your computer and use it in GitHub Desktop.
Javascript : convert country code to emoji flag by Stan Larroque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assume the country_code is a ISO 3166-1 alpha-2 string (eg: "US") | |
function country2emoji(country_code) { | |
var OFFSET = 127397; | |
var cc = country_code.toUpperCase(); | |
function _toConsumableArray(arr) { | |
if (Array.isArray(arr)) { | |
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { | |
arr2[i] = arr[i]; | |
} | |
return arr2; | |
} else { | |
return Array.from(arr); | |
} | |
} | |
return /^[A-Z]{2}$/.test(cc) ? String.fromCodePoint.apply(String, _toConsumableArray([].concat(_toConsumableArray(cc)).map(function (c) { | |
return c.charCodeAt() + OFFSET; | |
}))) : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment