Skip to content

Documentation / @andrew_l/toolkit / isoToFlagEmoji

Function: isoToFlagEmoji() ​

isoToFlagEmoji(iso): string

Converts a two-letter ISO country code (e.g., 'US') to the corresponding flag emoji. If the input is not a valid two-letter country code, it returns the original string.

Parameters ​

iso ​

string

The two-letter ISO country code.

Returns ​

string

  • The corresponding country flag emoji or the original input if it's invalid.

Example ​

ts
isoToFlagEmoji("US"); // Returns: 🇺🇸
isoToFlagEmoji("GB"); // Returns: 🇬🇧
isoToFlagEmoji("DE"); // Returns: 🇩🇪
isoToFlagEmoji("xyz"); // Returns: "xyz" (invalid code)