Module:Emoji

From blackwiki
Revision as of 20:45, 23 March 2019 by blackwiki>Qzekrom (Create module with help from User:RexxS)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Module:Emoji implements two functions:

emocode 
It takes one unnamed parameter, the name of the emoji, and returns the hex code for the corresponding emoji. If no name is supplied it uses "smiley" as the default (and returns 1f603).
emoname 
It takes one unnamed parameter, the hex code of the emoji, and returns the name for the corresponding emoji. If no name is supplied it uses "1f603" as the default (and returns smiley).

It stores the mapping from name to code in Module:Emoji/data, which internally generates the reverse lookup table from code to name.

Examples

  • {{#invoke:Emoji | emocode | wink}}wink
  • {{#invoke:Emoji | emocode | grin}}1f600
  • {{#invoke:Emoji | emocode | 8ball}}8ball
  • {{#invoke:Emoji | emocode }}263A
  • {{#invoke:Emoji | emoname | 1f62b}}Script error: The function "emoname" does not exist.
  • {{#invoke:Emoji | emoname }}Script error: The function "emoname" does not exist.



local emotbl = {
	grin   = "1f600",
	beam   = "1f601",
	joy    = "1f602",
	-- and so on ...
	smiley = "263A"
}

local p= {}

function p.emocode(frame)
	local emoname = mw.text.trim(frame.args[1] or "smiley")
	return emotbl[emoname] or emoname
end

return p