Skip to content

Instantly share code, notes, and snippets.

@tripulse
Created May 12, 2019 17:21
Show Gist options
  • Select an option

  • Save tripulse/a6f6e60b0375037f9ca098cc9cb680d7 to your computer and use it in GitHub Desktop.

Select an option

Save tripulse/a6f6e60b0375037f9ca098cc9cb680d7 to your computer and use it in GitHub Desktop.
The emote-transform API in JavaScript. Transforms normal-English text to Emotes.
/**
* (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(' ')
);
};
@tripulse
Copy link
Copy Markdown
Author

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).

@tripulse
Copy link
Copy Markdown
Author

tripulse commented Aug 22, 2020

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