Skip to content

Instantly share code, notes, and snippets.

@kevinrenskers
Created March 16, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinrenskers/da3bd3cdfcff94290f7f to your computer and use it in GitHub Desktop.
Save kevinrenskers/da3bd3cdfcff94290f7f to your computer and use it in GitHub Desktop.
A simple emoticonize filter for AngularJS: translates emoticon codes and smileys to emoji
angular.module('components.filters').filter('emoticonize', function emoticonize() {
'use strict';
// Try to stick to the emoticon codes as used by GitHub, Campfire, Basecamp, Flowdock, Slack.. etc.
// See http://www.emoji-cheat-sheet.com for a list.
var table = {
'πŸ”₯': [':fire:'],
'πŸ’©': [':shit:', ':hankey:', ':poop:'],
'πŸ™': [':pray:'],
'πŸ˜‰': [':wink:', ';)', ';-)'],
'πŸ˜„': [':smile:', ':)', ':-)'],
'😊': [':blush:'],
'😺': [':smiley_cat:'],
'😸': [':smile_cat:'],
'πŸ˜–': [':confounded:'],
'😳': [':flushed:'],
'😍': [':heart_eyes:'],
'πŸ‘½': [':alien:'],
'πŸ‘Š': [':facepunch:', ':punch:'],
'πŸ‘': [':clap:'],
'😎': [':sunglasses:', '8)', '8-)'],
'πŸ˜†': [':laughing:'],
'πŸ˜€': [':grinning:', ':D', ':-D'],
'πŸ˜ƒ': [':smiley:', '=D', '=-D'],
'😁': [':grin:'],
'😠': ['>:(', '>:-(', ':angry:'],
'πŸ˜‘': [':|', ':-|', ':expressionless:'],
'πŸ˜•': [':confused:', ':/', ':-/'],
'πŸ˜›': [':stuck_out_tongue:', ':p', ':-p', ':P', ':-P'],
'😜': [':stuck_out_tongue_winking_eye:', ';p', ';-p', ';P', ';-P'],
'😝': [':stuck_out_tongue_closed_eyes:'],
'😞': [':disappointed:', ':(', ':-('],
'πŸ˜’': [':unamused:'],
'😒': [':\'(', ':\'-(', ':cry:'],
'πŸ˜‚': [':joy:'],
'😭': [':sob:'],
'πŸ˜“': [':sweat:'],
'😱': [':scream:', ':o', ':O', ':-o', ':-O'],
'😰': [':cold_sweat:'],
'😨': [':fearful:'],
'😢': [':no_mouth:'],
'πŸ˜—': [':kissing:'],
'😚': [':kissing_closed_eyes:'],
'πŸ˜™': [':kissing_smiling_eyes:'],
'😟': [':worried:'],
'πŸ˜‡': [':innocent:'],
'😑': [':rage:'],
'😷': [':mask:'],
'πŸ‘': ['(y)', '(Y)', ':thumbsup:', ':+1:'],
'πŸ‘Ž': ['(n)', '(N)', ':thumbsdown:', ':-1:'],
'πŸ’›': ['<3', ':yellow_heart:', ':heart:'],
'πŸ’₯': [':boom:', ':collision:'],
'✨': [':sparkles:']
};
function _escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
}
function _replaceAll(string, find, replace) {
var pre = '(^|[\\s\\0])';
return string.replace(new RegExp(pre+'('+_escapeRegExp(find)+')', 'g'), ' '+replace);
}
return function(text, showEmoticons) {
if (!text || !showEmoticons) {
return text;
}
_.forEach(table, function(emoticons, emoji) {
_.forEach(emoticons, function(emoticon) {
text = _replaceAll(text, emoticon, emoji);
});
});
return text;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment