fix(utils): missing flags (#3194)

This commit is contained in:
Art 2023-03-15 09:20:41 +01:00 committed by GitHub
parent 0447a6cf5d
commit 93f8450ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 344 additions and 23 deletions

View File

@ -29,7 +29,6 @@ import { countryCodeToFlagEmoji, FALLBACK_FLAG } from './flag-emoji';
// 🇿
const cases = [
['AC', '🇦🇨'],
['AD', '🇦🇩'],
['AE', '🇦🇪'],
['AF', '🇦🇫'],
@ -38,11 +37,13 @@ const cases = [
['AL', '🇦🇱'],
['AM', '🇦🇲'],
['AO', '🇦🇴'],
['AQ', '🇦🇶'],
['AR', '🇦🇷'],
['AS', '🇦🇸'],
['AT', '🇦🇹'],
['AQ', '🇦🇶'],
['AU', '🇦🇺'],
['AW', '🇦🇼'],
['AX', '🇦🇽'],
['AZ', '🇦🇿'],
['BA', '🇧🇦'],
['BB', '🇧🇧'],
@ -57,10 +58,11 @@ const cases = [
['BM', '🇧🇲'],
['BN', '🇧🇳'],
['BO', '🇧🇴'],
['BQ', '🇧🇶'],
['BR', '🇧🇷'],
['BS', '🇧🇸'],
['BT', '🇧🇹'],
['BQ', '🇧🇶'],
['BV', '🇧🇻'],
['BW', '🇧🇼'],
['BY', '🇧🇾'],
['BZ', '🇧🇿'],
@ -76,19 +78,19 @@ const cases = [
['CM', '🇨🇲'],
['CN', '🇨🇳'],
['CO', '🇨🇴'],
['CP', '🇨🇵'],
['CR', '🇨🇷'],
['CU', '🇨🇺'],
['CV', '🇨🇻'],
['CW', '🇨🇼'],
['CX', '🇨🇽'],
['CY', '🇨🇾'],
['CZ', '🇨🇿'],
['DE', '🇩🇪'],
['DG', '🇩🇬'],
['DJ', '🇩🇯'],
['DK', '🇩🇰'],
['DM', '🇩🇲'],
['DO', '🇩🇴'],
['DZ', '🇩🇿'],
['EA', '🇪🇦'],
['EC', '🇪🇨'],
['EE', '🇪🇪'],
['EG', '🇪🇬'],
@ -114,10 +116,11 @@ const cases = [
['GM', '🇬🇲'],
['GN', '🇬🇳'],
['GP', '🇬🇵'],
['GQ', '🇬🇶'],
['GR', '🇬🇷'],
['GS', '🇬🇸'],
['GT', '🇬🇹'],
['GQ', '🇬🇶'],
['GU', '🇬🇺'],
['GW', '🇬🇼'],
['GY', '🇬🇾'],
['HK', '🇭🇰'],
@ -125,17 +128,17 @@ const cases = [
['HN', '🇭🇳'],
['HR', '🇭🇷'],
['HT', '🇭🇹'],
['IC', '🇮🇨'],
['HU', '🇭🇺'],
['ID', '🇮🇩'],
['IE', '🇮🇪'],
['IL', '🇮🇱'],
['IM', '🇮🇲'],
['IN', '🇮🇳'],
['IO', '🇮🇴'],
['IQ', '🇮🇶'],
['IR', '🇮🇷'],
['IS', '🇮🇸'],
['IT', '🇮🇹'],
['IQ', '🇮🇶'],
['JE', '🇯🇪'],
['JM', '🇯🇲'],
['JO', '🇯🇴'],
@ -159,6 +162,8 @@ const cases = [
['LR', '🇱🇷'],
['LS', '🇱🇸'],
['LT', '🇱🇹'],
['LU', '🇱🇺'],
['LV', '🇱🇻'],
['LY', '🇱🇾'],
['MA', '🇲🇦'],
['MC', '🇲🇨'],
@ -173,11 +178,14 @@ const cases = [
['MN', '🇲🇳'],
['MO', '🇲🇴'],
['MP', '🇲🇵'],
['MQ', '🇲🇶'],
['MR', '🇲🇷'],
['MS', '🇲🇸'],
['MT', '🇲🇹'],
['MQ', '🇲🇶'],
['MU', '🇲🇺'],
['MV', '🇲🇻'],
['MW', '🇲🇼'],
['MX', '🇲🇽'],
['MY', '🇲🇾'],
['MZ', '🇲🇿'],
['NA', '🇳🇦'],
@ -190,6 +198,7 @@ const cases = [
['NO', '🇳🇴'],
['NP', '🇳🇵'],
['NR', '🇳🇷'],
['NU', '🇳🇺'],
['NZ', '🇳🇿'],
['OM', '🇴🇲'],
['PA', '🇵🇦'],
@ -206,9 +215,11 @@ const cases = [
['PT', '🇵🇹'],
['PW', '🇵🇼'],
['PY', '🇵🇾'],
['QA', '🇶🇦'],
['RE', '🇷🇪'],
['RO', '🇷🇴'],
['RS', '🇷🇸'],
['RU', '🇷🇺'],
['RW', '🇷🇼'],
['SA', '🇸🇦'],
['SB', '🇸🇧'],
@ -227,9 +238,10 @@ const cases = [
['SR', '🇸🇷'],
['SS', '🇸🇸'],
['ST', '🇸🇹'],
['SV', '🇸🇻'],
['SX', '🇸🇽'],
['SY', '🇸🇾'],
['SZ', '🇸🇿'],
['TA', '🇹🇦'],
['TC', '🇹🇨'],
['TD', '🇹🇩'],
['TF', '🇹🇫'],
@ -243,10 +255,22 @@ const cases = [
['TO', '🇹🇴'],
['TR', '🇹🇷'],
['TT', '🇹🇹'],
['TV', '🇹🇻'],
['TW', '🇹🇼'],
['TZ', '🇹🇿'],
['QA', '🇶🇦'],
['UA', '🇺🇦'],
['UG', '🇺🇬'],
['UM', '🇺🇲'],
['US', '🇺🇸'],
['UY', '🇺🇾'],
['UZ', '🇺🇿'],
['VA', '🇻🇦'],
['VC', '🇻🇨'],
['VE', '🇻🇪'],
['VG', '🇻🇬'],
['VI', '🇻🇮'],
['VN', '🇻🇳'],
['VU', '🇻🇺'],
['WF', '🇼🇫'],
['WS', '🇼🇸'],
['YE', '🇾🇪'],
@ -254,6 +278,23 @@ const cases = [
['ZA', '🇿🇦'],
['ZM', '🇿🇲'],
['ZW', '🇿🇼'],
// UK
['ENGLAND', '🏴󠁧󠁢󠁥󠁮󠁧󠁿'],
['GB-ENG', '🏴󠁧󠁢󠁥󠁮󠁧󠁿'],
['ENG', '🏴󠁧󠁢󠁥󠁮󠁧󠁿'],
['SCOTLAND', '🏴󠁧󠁢󠁳󠁣󠁴󠁿'],
['GB-SCT', '🏴󠁧󠁢󠁳󠁣󠁴󠁿'],
['SCT', '🏴󠁧󠁢󠁳󠁣󠁴󠁿'],
['WALES', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['GB-WLS', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['WLS', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['CYMRU', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['GB-CYM', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['CYM', '🏴󠁧󠁢󠁷󠁬󠁳󠁿'],
['NORTHERN IRELAND', '🇬🇧'],
['GB-NIR', '🇬🇧'],
['NIR', '🇬🇧'],
['UK', '🇬🇧'],
// unknown
['AA', FALLBACK_FLAG],
['XX', FALLBACK_FLAG],

View File

@ -2,23 +2,303 @@ import compact from 'lodash/compact';
export const FALLBACK_FLAG = '🏳';
const KNOWN_CODES = `AC AD AE AF AG AI AL AM AO AR AS AT AQ AW AZ BA BB BD BE BF
BG BH BI BJ BL BM BN BO BR BS BT BQ BW BY BZ CA CC CD CF CG CH CI CK CL CM CN
CO CP CR CW CY CZ DE DG DJ DK DM DO DZ EA EC EE EG EH ER ES ET FI FJ FK FM FO
FR GA GB GD GE GF GG GH GI GL GM GN GP GR GS GT GQ GW GY HK HM HN HR HT IC ID
IE IL IM IN IO IR IS IT IQ JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB
LC LI LK LR LS LT LY MA MC MD ME MF MG MH MK ML MM MN MO MP MR MS MT MQ MW MY
MZ NA NC NE NF NG NI NL NO NP NR NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW
PY RE RO RS RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SY SZ TA TC
TD TF TG TH TJ TK TL TM TN TO TR TT TW TZ QA VG WF WS YE YT ZA ZM ZW`;
const KNOWN_CODES = [
'AD',
'AE',
'AF',
'AG',
'AI',
'AL',
'AM',
'AO',
'AQ',
'AR',
'AS',
'AT',
'AU',
'AW',
'AX',
'AZ',
'BA',
'BB',
'BD',
'BE',
'BF',
'BG',
'BH',
'BI',
'BJ',
'BL',
'BM',
'BN',
'BO',
'BQ',
'BR',
'BS',
'BT',
'BV',
'BW',
'BY',
'BZ',
'CA',
'CC',
'CD',
'CF',
'CG',
'CH',
'CI',
'CK',
'CL',
'CM',
'CN',
'CO',
'CR',
'CU',
'CV',
'CW',
'CX',
'CY',
'CZ',
'DE',
'DJ',
'DK',
'DM',
'DO',
'DZ',
'EC',
'EE',
'EG',
'EH',
'ER',
'ES',
'ET',
'FI',
'FJ',
'FK',
'FM',
'FO',
'FR',
'GA',
'GB',
'GD',
'GE',
'GF',
'GG',
'GH',
'GI',
'GL',
'GM',
'GN',
'GP',
'GQ',
'GR',
'GS',
'GT',
'GU',
'GW',
'GY',
'HK',
'HM',
'HN',
'HR',
'HT',
'HU',
'ID',
'IE',
'IL',
'IM',
'IN',
'IO',
'IQ',
'IR',
'IS',
'IT',
'JE',
'JM',
'JO',
'JP',
'KE',
'KG',
'KH',
'KI',
'KM',
'KN',
'KP',
'KR',
'KW',
'KY',
'KZ',
'LA',
'LB',
'LC',
'LI',
'LK',
'LR',
'LS',
'LT',
'LU',
'LV',
'LY',
'MA',
'MC',
'MD',
'ME',
'MF',
'MG',
'MH',
'MK',
'ML',
'MM',
'MN',
'MO',
'MP',
'MQ',
'MR',
'MS',
'MT',
'MU',
'MV',
'MW',
'MX',
'MY',
'MZ',
'NA',
'NC',
'NE',
'NF',
'NG',
'NI',
'NL',
'NO',
'NP',
'NR',
'NU',
'NZ',
'OM',
'PA',
'PE',
'PF',
'PG',
'PH',
'PK',
'PL',
'PM',
'PN',
'PR',
'PS',
'PT',
'PW',
'PY',
'QA',
'RE',
'RO',
'RS',
'RU',
'RW',
'SA',
'SB',
'SC',
'SD',
'SE',
'SG',
'SH',
'SI',
'SJ',
'SK',
'SL',
'SM',
'SN',
'SO',
'SR',
'SS',
'ST',
'SV',
'SX',
'SY',
'SZ',
'TC',
'TD',
'TF',
'TG',
'TH',
'TJ',
'TK',
'TL',
'TM',
'TN',
'TO',
'TR',
'TT',
'TV',
'TW',
'TZ',
'UA',
'UG',
'UM',
'US',
'UY',
'UZ',
'VA',
'VC',
'VE',
'VG',
'VI',
'VN',
'VU',
'WF',
'WS',
'YE',
'YT',
'ZA',
'ZM',
'ZW',
];
export const countryCodeToFlagEmoji = (countryCode: string) => {
const ENGLAND = '🏴󠁧󠁢󠁥󠁮󠁧󠁿';
const SCOTLAND = '🏴󠁧󠁢󠁳󠁣󠁴󠁿';
const WALES = '🏴󠁧󠁢󠁷󠁬󠁳󠁿';
const NORTHERN_IRELAND = '🇬🇧';
const UK = new Map([
['ENGLAND', ENGLAND],
['GB-ENG', ENGLAND],
['ENG', ENGLAND],
['SCOTLAND', SCOTLAND],
['GB-SCT', SCOTLAND],
['SCT', SCOTLAND],
['WALES', WALES],
['GB-WLS', WALES],
['WLS', WALES],
['CYMRU', WALES],
['GB-CYM', WALES],
['CYM', WALES],
['NORTHERN IRELAND', NORTHERN_IRELAND],
['GB-NIR', NORTHERN_IRELAND],
['NIR', NORTHERN_IRELAND],
['UNITED KINGDOM', '🇬🇧'],
['UK', '🇬🇧'],
]);
const EU = new Map([['EU', '🇪🇺']]);
const getCode = (countryCode: string): string => {
const code = countryCode.trim().toUpperCase();
const known = compact(KNOWN_CODES.split(' ').map((ch) => ch.trim()));
return code;
};
export const countryCodeToFlagEmoji = (countryCode: string): string => {
const code = getCode(countryCode);
const known = compact(KNOWN_CODES.map((ch) => ch.trim()));
if (known.includes(code)) {
return code.replace(/./g, (char) =>
String.fromCodePoint(0x1f1a5 + char.toUpperCase().charCodeAt(0))
);
}
if (UK.has(code)) {
return UK.get(code) as string;
}
if (EU.has(code)) {
return EU.get(code) as string;
}
return FALLBACK_FLAG;
};