Emoji Shorts

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 😑

Angry emotions with emoji

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

How Slack handles emoji

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 ✊

https://npm.im/emoji-shorts

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

Back to home

Blog Logo

James D


Published