Created
April 5, 2017 01:04
-
-
Save robbie01/969148ac1739f1545c01dd727425f35e to your computer and use it in GitHub Desktop.
Convert text into emojis
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
/* | |
emojify.js 1.0.0 | |
by robbie0630 | |
Description: | |
converts text into Discord-compatible emojis | |
PLANNED FEATURES: | |
* needs more ES2015 | |
* needs more ES2016 | |
* test if argument is a string | |
* convert numbers to emojis using a dictionary | |
* instead of using the join(' ') kludge, check for regional_indicator conflicts with flag emojis | |
*/ | |
function emojify(str) { | |
return Array.prototype.map.call(str, (e, i, a) => { | |
if (/[aA][bB]/.test(e+a[i+1])) { | |
return ':ab:'; | |
} else if (/[oO]/.test(e)) { | |
return ':o2:'; | |
} else if (/[bB]/.test(e)) { | |
return ':b:' | |
} else if (/[a-zA-Z]/.test(e)) { | |
return ':regional_indicator_' + e.toLowerCase() + ':' | |
} else { | |
return e; | |
} | |
}).join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment