Created
December 15, 2020 15:59
-
-
Save HZ-labs/418b48d807a042aa6c9db6aa7343b489 to your computer and use it in GitHub Desktop.
Переводит русский в новые эмодзи слэка (Slack, alphabet, emoji)
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
function transliterateToEmoji(text) { | |
const keys = { | |
а: "a", | |
б: "b", | |
в: "v", | |
г: "g", | |
д: "d", | |
е: "e", | |
ё: "e", | |
ж: "j", | |
з: "z", | |
и: "i", | |
к: "k", | |
л: "l", | |
м: "m", | |
н: "n", | |
о: "o", | |
п: "p", | |
р: "r", | |
с: "s", | |
т: "t", | |
у: "u", | |
ф: "f", | |
х: "h", | |
ц: "c", | |
ч: "ch", | |
ш: "sh", | |
щ: "sh", | |
ы: "y", | |
э: "e", | |
ю: "u", | |
я: "ya", | |
ь: "`", | |
}; | |
const emojiKeys = { | |
"?": ":alphabet-yellow-question:", | |
"!": ":alphabet-yellow-exclamation:", | |
" ": " ", | |
}; | |
return text | |
.toLowerCase() | |
.split("") | |
.map((char) => keys[char] || char) | |
.map((el) => { | |
if (/[a-z]/i.test(el)) { | |
return `:alphabet-yellow-${el}:`; | |
} | |
return emojiKeys[el] || el; | |
}) | |
.join(""); | |
} | |
copy(transliterateToEmoji("Дима, ты наверное не поставил на телефон эти эмодзи")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment