fn

getCountryFlagByCode

v0.0.5

Convert an ISO 3166-1 alpha-2 country code (e.g. 'RU', 'us') into its flag emoji by mapping each letter to a Unicode regional indicator symbol. Case-insensitive; returns an empty string for anything that isn't two ASCII letters. Pure and environment-agnostic.

Example

ts
getCountryFlagByCode('RU'); // '🇷🇺'
getCountryFlagByCode('us'); // '🇺🇸'
getCountryFlagByCode('123'); // ''

Signature

ts
declare function getCountryFlagByCode(code: string): string;

Parameters

ParameterTypeDescription
codestringThe ISO 3166-1 alpha-2 code, e.g. 'US'

Returns

stringThe flag emoji (e.g. '🇺🇸'), or '' when the code is invalid