Created
March 16, 2015 14:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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