Created
May 12, 2019 17:21
-
-
Save tripulse/a6f6e60b0375037f9ca098cc9cb680d7 to your computer and use it in GitHub Desktop.
The emote-transform API in JavaScript. Transforms normal-English text to Emotes.
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
| /** | |
| * (c) Copyright 2019 nullptr. | |
| * | |
| * This program is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation, either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
| */ | |
| var characterRefrences = {}; | |
| var codePoints = { | |
| start: 97, | |
| end: 97+26 | |
| }; | |
| for(var c = codePoints.start; c < codePoints.end; ++c) { | |
| /* The character which is converted from a double. */ | |
| var char = String.fromCharCode(c); | |
| /* Assign each char with a markdown emoji identifier. */ | |
| characterRefrences[char] = `:regional_indicator_${char}:`; | |
| } | |
| function emoteTransform(str) { | |
| return ( | |
| Array | |
| .from(str.toLowerCase(), char => | |
| /* Checkpoint for whether the char is not in the | |
| * specified code-point or not. */ | |
| (characterRefrences[char] ? characterRefrences[char] : char) | |
| ).join(' ') | |
| ); | |
| }; |
Author
Author
This is the Python equivalent of this old shit.
char_to_emoji = dict(((c, f':regional_indicator_{c}:')
for c in map(chr, range(97, 123))))
def emoji_text(s):
return ' '.join(char_to_emoji.get(c) or c for c in s)
# emoji_text("Hello World")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is mainly designed to transform "letters" into "emotes" and works with (Discord, Github). No additional dictionary of emotes is required until its usage is limited to (Discord, Github).
The behaviour is mimicked on a Python code (not attached yet).