269 Followers
ยท
Follow

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 for post
Image for post
Thanks Giphy http://giphy.com/gifs/disneypixar-disney-pixar-11tTNkNy1SdXGg

But then you look at Slack, and that handles emoji with styleโ€ฆ

Image for post
Image for post

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

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store