Hello everyone,
Today, I would like to share a neat trick that I've recently used in one of my projects. As you may or may not know, it's possible to use Unicode to combine various emojis together to create a new one. For example, taking the 'person' emoji and adding a 'skin color' emoji can give us a person that corresponds to the correct skin color.
Interestingly, this can also be applied to emojis that represent regional letters. For example, if I take the letter 'F' and then the letter 'R', it automatically gives the French flag. This works with all ISO codes for different countries. So, if you need to display a flag in an application, rather than searching for PNGs or an icon library corresponding to the different flags, you can use this trick.
This is also faster to load for the user.
Start by taking the ISO code and split it into individual letters. Convert the string into an array of letters.
Convert these letters into their ASCII position.
After getting the position, use the remainder of division by 32. The goal is to start the alphabet from 1 (i.e., 'A' or 'a' is 1, 'B' or 'b' is 2, and so on). Doing modulo 32 allows us to get 1 for lowercase and uppercase 'a', which is quite convenient. Also take the position of the regional letter 'a', subtract 1, and add this number to what we got previously. This converts the lowercase or uppercase 'a' into the Unicode 'a' version.
https://www.isthisthingon.org/unicode/in...lyph=1F1E6
Now that we have these numbers, we can convert them back into letters using the 'fromCodePoint' method.
Finally, we can use the 'join' function to recreate a string composed of these two letters. As if by magic, the French flag appears!
I hope you found this trick useful!
Today, I would like to share a neat trick that I've recently used in one of my projects. As you may or may not know, it's possible to use Unicode to combine various emojis together to create a new one. For example, taking the 'person' emoji and adding a 'skin color' emoji can give us a person that corresponds to the correct skin color.
Interestingly, this can also be applied to emojis that represent regional letters. For example, if I take the letter 'F' and then the letter 'R', it automatically gives the French flag. This works with all ISO codes for different countries. So, if you need to display a flag in an application, rather than searching for PNGs or an icon library corresponding to the different flags, you can use this trick.
This is also faster to load for the user.
Start by taking the ISO code and split it into individual letters. Convert the string into an array of letters.
Code
.split('')Convert these letters into their ASCII position.
Code
.map(letter => letter.charCodeAt(0));After getting the position, use the remainder of division by 32. The goal is to start the alphabet from 1 (i.e., 'A' or 'a' is 1, 'B' or 'b' is 2, and so on). Doing modulo 32 allows us to get 1 for lowercase and uppercase 'a', which is quite convenient. Also take the position of the regional letter 'a', subtract 1, and add this number to what we got previously. This converts the lowercase or uppercase 'a' into the Unicode 'a' version.
https://www.isthisthingon.org/unicode/in...lyph=1F1E6
Code
.map(letter => (letter % 32) + 0x1F1E5);Now that we have these numbers, we can convert them back into letters using the 'fromCodePoint' method.
Code
.map(code => String.fromCodePoint(code));Finally, we can use the 'join' function to recreate a string composed of these two letters. As if by magic, the French flag appears!
Code
.join('');
console.log(flag); // 🇫🇷I hope you found this trick useful!
Code
function isoToFlag(code) {
return code
.split('')
.map(letter => (letter.charCodeAt(0) % 32) + 0x1F1E5)
.map(n => String.fromCodePoint(n))
.join('')
}
console.log(isoToFlag("FR")); // Outputs: 🇫🇷
console.log(isoToFlag("BE")); // Outputs: 🇧🇪
console.log(isoToFlag("CA")); // Outputs: 🇨🇦
console.log(isoToFlag("US")); // Outputs: 🇺🇸![[Image: vibesignature.gif]](https://i.ibb.co/8LvxwtYQ/vibesignature.gif)
“Whatever Your Mind Can Conceive and Believe, It Can Achieve.” – Napoleon Hill





![[Image: O444cFs.jpg]](https://i.ibb.co/c2rr5jw/O444cFs.jpg)

