Created
May 24, 2018 17:54
-
-
Save satyapendem/23f9b51613623883a320f0895ed22457 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
emojiToUnicode=function (str){ | |
var emojiRegexp = /([\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2694-\u2697]|\uD83E[\uDD10-\uDD5D])/g; | |
if(!str) | |
return; | |
try{ | |
var new_str= str.match(emojiRegexp); | |
for(var emoj in new_str){ | |
var emojmessage = new_str[emoj]; | |
var index = str.indexOf(emojmessage); | |
if(index === -1) | |
continue; | |
emojmessage = "\\u" + emojmessage.charCodeAt(0).toString(16) + "\\u" + emojmessage.charCodeAt(1).toString(16); | |
str = str.substr(0, index) + emojmessage + str.substr(index + 2); | |
} | |
return str; | |
}catch(err){ | |
console.error("error in emojiToUnicode"+err.stack); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment