UNPKG

baseui

Version:

A React Component library implementing the Base design language

28 lines (26 loc) 896 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.iso2FlagEmoji = iso2FlagEmoji; /* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ // country code regex const ISO_REGEX = /^[a-z]{2}$/i; // offset between uppercase ascii and regional indicator symbols const OFFSET = 127397; // convert country code to corresponding emoji flag function iso2FlagEmoji(iso) { if (!ISO_REGEX.test(iso)) { const type = typeof iso; if (process.env.NODE_ENV !== "production") { console.warn(`iso argument must be an ISO 3166-1 alpha-2 string, but got '${type === 'string' ? iso : type}' instead.`); } return; } const chars = Array.from(iso.toUpperCase()).map(char => char.charCodeAt(0) + OFFSET); return String.fromCodePoint(...chars); }