Emoji Shorts
πŸ‚

Emoji Shorts

Published At
December 19, 2016

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 😑

image

But then you look at Slack, and that handles emoji with style…

image

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 ✊

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 πŸŽ„πŸŽπŸŽ