UNPKG

1.91 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.iso2FlagEmoji = iso2FlagEmoji;
7
8function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
9
10function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
11
12function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
13
14function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
15
16function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
17
18/*
19Copyright (c) 2018-2020 Uber Technologies, Inc.
20
21This source code is licensed under the MIT license found in the
22LICENSE file in the root directory of this source tree.
23*/
24// country code regex
25var ISO_REGEX = /^[a-z]{2}$/i; // offset between uppercase ascii and regional indicator symbols
26
27var OFFSET = 127397; // convert country code to corresponding emoji flag
28
29function iso2FlagEmoji(iso) {
30 if (!ISO_REGEX.test(iso)) {
31 var type = _typeof(iso);
32
33 if (process.env.NODE_ENV !== "production") {
34 console.warn("iso argument must be an ISO 3166-1 alpha-2 string, but got '".concat(type === 'string' ? iso : type, "' instead."));
35 }
36
37 return;
38 }
39
40 var chars = Array.from(iso.toUpperCase()).map(function (char) {
41 return char.charCodeAt(0) + OFFSET;
42 });
43 return String.fromCodePoint.apply(String, _toConsumableArray(chars));
44}
\No newline at end of file