Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Last active April 23, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/22bd0b0a5900032ee3d834e6b7698a7c to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/22bd0b0a5900032ee3d834e6b7698a7c to your computer and use it in GitHub Desktop.
A text formatter that replaces text with matching emoji
function format(text) {
const emojimap = {
"❀️": "love",
"πŸ˜‚": "laughing",
"😍": "awesome",
"πŸ‘": "great",
"😭": "crying",
"😊": "smiling",
"😘": "kiss",
"πŸ”₯": "fire",
"πŸ₯Ί": "aww",
"πŸ˜‰": "winking",
"😎": "cool",
"πŸ€”": "thinking",
"🀷": "shrug",
"πŸ‘Œ": "ok",
"πŸ˜’": "boring",
"😩": "weary",
"😁": "grinning",
"πŸ™Œ": "praise",
"✨": "sparkles",
"πŸ‘€": "look",
"πŸ™": "thanks",
"πŸ’•": "cute",
"πŸ’”": "heartbroken",
"πŸ€—": "hugging",
"πŸ‘": "clapping",
"🀫": "shushing",
"πŸ’―": "100",
"🏠": "home",
"🌳": "tree",
"πŸ–οΈ": "beach",
"⛰️": "mountain",
"🎒": "rollercoaster",
"πŸ€": "basketball",
"🏊": "swimming",
"🍲": "food",
"🍷": "wine",
"🍺": "beer",
"πŸ›οΈ": "shopping",
"🚴": "cycling",
"πŸ“–": "reading",
"β›ͺ": "church",
"πŸ•": "synagogue",
"πŸ•Œ": "mosque"
};
let formattedText = text;
// loop through the emojiMap and replace any matching word or phrase with the associated emoji
for (const [word, emoji] of Object.entries(emojiMap)) {
formattedText = formattedText.replace(new RegExp(word, "gi"), emoji);
}
return formattedText;
}
@dnnsmnstrr
Copy link
Author

dnnsmnstrr commented Apr 23, 2023

Generated by ChatGPT with this prompt:


function format(text) {
    return text.trim();
} 

Instead of trimming the text, Replace the text with matching emoji .```

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