Skip to content

kitsunies/emoji.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

77 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

emoji.lua πŸ’¬

A basic emoji support module for Lua πŸŒ™

Example

local emoji = require("emoji")

print(emoji.emojify("I :heart: :tea:!"))
--> "I ❀️ 🍡!"

Installation

Luarocks

If you are using luarocks, just run:

luarocks install emoji

Manual

Copy the emoji folder somewhere where your Lua interpreter will be able to find it and require it accordingly:

local emoji = require('emoji')

Interface

Methods

emoji.get

emoji.get("tea") -> "🍡"

Returns the emoji of the query

emoji.which

emoji.which("🍡") -> "tea"

Returns the name of an emoji

emoji.emojify

emoji.emojify("I :heart: :tea:!") -> "I ❀️ 🍡!"

Replaces all :emoji: with the actual emoji

emoji.unemojify

emoji.unemojify("I ❀️ 🍡!") -> "I :heart: :tea:!"

Replaces all the emojis with the emoji's tag

emoji.tone

emoji.tone("Teamwork! 🀝", emoji.tones.light) -> "Teamwork! 🀝🏻"

Finds a skin colour varient of an emoji

emoji.random

emoji.random() -> { emoji = "🌼", key = "blossom" }

Returns a random emoji + key table

emoji.search

emoji.search("coff") -> {{ emoji = "β˜•οΈ", key = "coffee" }, { emoji = "⚰", key = "coffin" }}

Returns a table of tables with matching emojis

emoji.find

emoji.find("🍡" | "tea") -> { emoji = "🍡", key = "tea" }

Returns a emoji + key table of the emoji

emoji.strip

emoji.strip("I see you... πŸ‘€") -> "I see you..."

Strips the string from emojis

emoji.replace

emoji.replace("I see you... πŸ‘€", function(emoji) return emoji.key end) -> "I see you... eyes"

Replaces emojis by a callback method

Options

missing

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 ⭐️"

format

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" />"

Testing

Install busted & luacheck luarocks install busted && luarocks install luacheck and run:

$ busted
$ luacheck src/emoji

License

This library is free software; You may redistribute and/or modify it under the terms of the MIT license. See LICENSE for details.