Skip to content

Instantly share code, notes, and snippets.

@WisdomSky
Created February 14, 2024 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WisdomSky/0615edbcf5b429ab26b837c236fb0d98 to your computer and use it in GitHub Desktop.
Save WisdomSky/0615edbcf5b429ab26b837c236fb0d98 to your computer and use it in GitHub Desktop.
Convert Alphabet Text Into Regional Indicator Unicode Character Using Javascript

Code

function alphaToRegionalIndicator(text) {

    text = text.toLocaleUpperCase().split('');

    let output = "";

    for (const char of text) {
        const code = char.charCodeAt(0) - 65;

        if (code >= 0 && code <= 25) {
            output += String.fromCodePoint(127462 + code)
        } else {
            output += char;
        }
    }

    return output;
}

Example

console.log(alphaToRegionalIndicator('hEllo World'));

Output

🇭🇪🇱🇱🇴 🇼🇴🇷🇱🇩
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment