javascript - Replace emoticons with emoji -
i've text, may include text emoticons (eg: ;)
, :(
). i'd replace these corresponding emoji unicode characters (😉
, 😞
) above example.
my intention run twimoji on text.
i know can find-and-replace, i'd rather use pre-build already.
any libraries implement this? believe list of common emoticons largest bit of work here.
not sure if there's library out there turns text emoticons unicode characters here's example of how possibly implement yourself.
var map = { "<3": "\u2764\ufe0f", "</3": "\ud83d\udc94", ":d": "\ud83d\ude00", ":)": "\ud83d\ude03", ";)": "\ud83d\ude09", ":(": "\ud83d\ude12", ":p": "\ud83d\ude1b", ";p": "\ud83d\ude1c", ":'(": "\ud83d\ude22" }; function escapespecialchars(regex) { return regex.replace(/([()[{*+.$^\\|?])/g, '\\$1'); } document.getelementbyid('textarea').oninput = function() { (var in map) { var regex = new regexp(escapespecialchars(i), 'gim'); this.value = this.value = this.value.replace(regex, map[i]); } };
Comments
Post a Comment