Skip to content

Instantly share code, notes, and snippets.

@jeshuamaxey
Created February 25, 2021 16:14
Show Gist options
  • Save jeshuamaxey/d2a1017234dcbafcf11371f78791fe95 to your computer and use it in GitHub Desktop.
Save jeshuamaxey/d2a1017234dcbafcf11371f78791fe95 to your computer and use it in GitHub Desktop.
Converts arbitrary string into slack-compatible emoji letters
const gimmeSweetEmojis = (input) => {
let output = "";
input
.split("")
.map(l => l.toLowerCase())
.forEach(letter => {
if (letter.match(/[a-z]/i)) output += `:alphabet-yellow-${letter}: `
else output += letter;
})
return output
}
gimmeSweetEmojis("hello sinead")
@tl-dan-wong
Copy link

:alphabet-yellow-d: :alphabet-yellow-u: :alphabet-yellow-d: :alphabet-yellow-e: :alphabet-yellow-t: :alphabet-yellow-h: :alphabet-yellow-e: :alphabet-yellow-s: :alphabet-yellow-p: :alphabet-yellow-a: :alphabet-yellow-c: :alphabet-yellow-i: :alphabet-yellow-n: :alphabet-yellow-g:

@neilwashere
Copy link

I think you'll find this is even more obnoxious

const gimmeSweetEmojis = (input) => {
    const whiteOrYellow = (int_or_bust) =>
        int_or_bust % 2 === 0 ? "yellow" : "white"

    return input
        .split("")
        .reduce((output, character, index) => {
            if (character.match(/[a-z]/i)) {
                output += `:alphabet-${whiteOrYellow(index)}-${character}: `
            } else if (character.match(/\s/)) {
                output += "  " // double but whatevs
            }
            else output += character
            return output
        }, "").trimEnd()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment