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

View File

@ -2,23 +2,303 @@ import compact from 'lodash/compact';
export const FALLBACK_FLAG = '🏳'; 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 const KNOWN_CODES = [
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 'AD',
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 'AE',
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 'AF',
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 'AG',
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 'AI',
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 'AL',
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 'AM',
TD TF TG TH TJ TK TL TM TN TO TR TT TW TZ QA VG WF WS YE YT ZA ZM ZW`; '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 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)) { if (known.includes(code)) {
return code.replace(/./g, (char) => return code.replace(/./g, (char) =>
String.fromCodePoint(0x1f1a5 + char.toUpperCase().charCodeAt(0)) 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; return FALLBACK_FLAG;
}; };