Emote (emote v0.1.1)

Small lib for converting emoticons and emoji names to emoji characters:

Works with emoji names:

iex> Emote.convert_text("my emoji game is :fire:")
"my emoji game is 🔥"

And emoticons (see lib/emoticons.txt for the list of supported ones):

iex> Emote.convert_text("my emoji game is :P")
"my emoji game is 😜"

You can also provide a list of images that can be used as custom emoji:

iex> Emote.convert_text("I can use images as custom emoji :favicon:", custom_emoji: %{"favicon" => "/favicon.ico"}) 
"I can use images as custom emoji <img class='emoji favicon' alt='favicon' title=':favicon:' src='/favicon.ico' />"

Or your own function to handle custom emoji:

> Emote.convert_text("I can define my own function to handle custom emoji :fire:",
   custom_fn: fn word -> 
    case lookup_my_custom_emoji(word) do
      %{label: label, url: url} ->
          " <img alt='#{label || word}' title='#{label}' class='emoji' data-emoji='#{word}' src='#{url}' /> "
          
      _nil_ ->
          word
      end
   end
  )

Known limitation:

  • Emojis combined together don't work, ex.: ":woo:pile_of_poo:hoo:" would not convert.

License

WTFPL, as originally forked from https://github.com/danigulyas/smile

Summary

Functions

Converts text in a way that it replaces any mapped emojis or emoticons with the equivalent emojis characters or images, including custom emoji

Converts an emoticon or emoji name to emoji, including custom emoji. Simply returns the input when an emoji is not found.

Converts an emoticon or emoji name to emoji.

Functions

Link to this function

convert_text(text, opts \\ [])

Converts text in a way that it replaces any mapped emojis or emoticons with the equivalent emojis characters or images, including custom emoji

Link to this function

convert_word(text, opts \\ [])

Converts an emoticon or emoji name to emoji, including custom emoji. Simply returns the input when an emoji is not found.

Converts an emoticon or emoji name to emoji.

Returns nil if no matching emoji is found.

If you need support for custom emoji, use convert_word/2 instead.

iex> lookup(":face_with_ok_gesture:")
"🙆"

iex> lookup("face_with_ok_gesture")
"🙆"

iex> lookup("unknown_emoji")
nil