Skip to content
Permalink
Browse files

convert Slack emoji to unicode

  • Loading branch information...
aaronpk committed Feb 5, 2017
1 parent 384e364 commit 541cc464e60e6146c305afd5efc521f6553f690c
Showing with 37,275 additions and 3 deletions.
  1. +24 −0 emoji.js
  2. +37,241 −0 emoji_pretty.json
  3. +4 −1 gateway.js
  4. +6 −2 package.json
@@ -0,0 +1,24 @@
const punycode = require('punycode');

var emoji_data = require('./emoji_pretty.json');

exports.slack_to_unicode = function(text) {

var emoji_re = /\:([a-zA-Z0-9\-_\+]+)\:(?:\:([a-zA-Z0-9\-_\+]+)\:)?/g;

var new_text = text;

// Find all Slack emoji in the message
while(match=emoji_re.exec(text)) {
var ed = emoji_data.find(function(el){
return el.short_name == match[1];
});
if(ed) {
var points = ed.unified.split("-");
points = points.map(function(p){ return parseInt(p, 16) });
new_text = new_text.replace(match[0], punycode.ucs2.encode(points));
}
}

return new_text;
}

1 comment on commit 541cc46

@arieljake-bluescape

This comment has been minimized.

Copy link

commented on 541cc46 Feb 17, 2019

Thank you, this was super helpful.

Please sign in to comment.
You can’t perform that action at this time.