local emoji = require("emoji")
print(emoji.emojify("I :heart: :tea:!"))
--> "I β€οΈ π΅!"
If you are using luarocks, just run:
luarocks install emoji
Copy the emoji folder somewhere where your Lua interpreter will be able to find it and require it accordingly:
local emoji = require('emoji')
emoji.get("tea") -> "π΅"
Returns the emoji of the query
emoji.which("π΅") -> "tea"
Returns the name of an emoji
emoji.emojify("I :heart: :tea:!") -> "I β€οΈ π΅!"
Replaces all :emoji: with the actual emoji
emoji.unemojify("I β€οΈ π΅!") -> "I :heart: :tea:!"
Replaces all the emojis with the emoji's tag
emoji.tone("Teamwork! π€", emoji.tones.light) -> "Teamwork! π€π»"
Finds a skin colour varient of an emoji
emoji.random() -> { emoji = "πΌ", key = "blossom" }
Returns a random emoji + key table
emoji.search("coff") -> {{ emoji = "βοΈ", key = "coffee" }, { emoji = "β°", key = "coffin" }}
Returns a table of tables with matching emojis
emoji.find("π΅" | "tea") -> { emoji = "π΅", key = "tea" }
Returns a emoji + key table of the emoji
emoji.strip("I see you... π") -> "I see you..."
Strips the string from emojis
emoji.replace("I see you... π", function(emoji) return emoji.key end) -> "I see you... eyes"
Replaces emojis by a callback method
emoji.emojify(str, missing)
As second argument, emojify
takes an handler to parse unknown emojis. Provide a function to add your own handler:
local missing = function(tag)
return tag:upper()
end)
local emojified = emoji.emojify('I :unknown_emoji: :star:', onMissing);
--> emojified: "I UNKNOWN_EMOJI βοΈ"
emoji.emojify(str, missing, format)
As third argument, emojify
takes an handler to wrap parsed emojis. Provide a function to place emojis in custom elements, and to apply your custom styling:
local format = function(emoji)
return '<img alt="' .. emoji.emoji .. '" src="' .. emoji.key .. '.png />'
end)
local emojified = emoji.emojify("I :heart: :tea:", nil, format)
--> emojified: "I <img alt="β€οΈ" src="heart.png" /> <img alt="π΅" src="tea.png" />"
Install busted & luacheck luarocks install busted && luarocks install luacheck
and run:
$ busted
$ luacheck src/emoji
This library is free software; You may redistribute and/or modify it under the terms of the MIT license. See LICENSE for details.