Sometimes, when you work with emojis 😎😍🤖🌎✊ they can be a real pain in the ass. One physical symbol can equal up to four Unicode characters, so when counting strings & encoding emojis into a valid format for your favourite legacy database, these fun little icons can physically make you 😡
But then you look at Slack, and that handles emoji with style…
I love how Slack handles emoji. Transforming
:tada: into 🎉 and
:sunglasses: into 😎 and so on. So, the engineer within me decided to find a NPM module to do this for me.
And after several hours, the closest I could find was Mojier, published two years ago, which mapped emojis to their shortcodes and back again. But being two years out of date means the library was half-complete, and the lookups were slow (
for(var p in emoji)), so ten minutes later I had emoji-shorts online ✊
Plenty of services love to use the emoji shortcodes in plain-text markup, so this library aims to simplify that process for you, making 😎 become :sunglasses:, 💡 to :bulb:, etc. There's an amazing list of shortcodes here if you want to explore them.
Using this to translate strings containing emoji is easy:
var emoji = require('emoji-shorts'); console.log(emoji.toPlain('These violent delights have violent ends 😈')); // These violent delights have violent ends :smiling_imp: console.log(emoji.toRich('The most elegant parts of me weren\'t written by you :thinking:')); // The most elegant parts of me weren't written by you 🤔
The emojis & relevant short-codes came from Github themselves, with a little post-processing to make the lookups a little faster. Ideally this would be used when saving user-input & when fetching user-input, so your ORM / database engine of choice is none the wiser 😉
If you have any questions, or you wish to submit a PR (of which all are welcome, we all ❤️ emojis!) then please feel free to get involved: https://github.com/car-throttle/emoji-shorts
In the meantime, Merry Christmas 🎄🎁🎅