Module:Emoji
Module:Emoji implements two functions:
- emocode
- 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
- 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}}→1f609{{#invoke:Emoji | emocode | grin}}→1f601{{#invoke:Emoji | emocode | 8ball}}→1f3b1{{#invoke:Emoji | emocode }}→1f603{{#invoke:Emoji | emoname | 1f62b}}→tired_face{{#invoke:Emoji | emoname }}→smiley
require ('strict');
local data = mw.loadData ('Module:Emoji/data');
--[[--------------------------< E M O C O D E >----------------------------------------------------------------
return the hexadecimal code associated with an emoji's name
{{#invoke:Emoji|emocode|smiley}} → 1f603
When the specified name does not exist in the data table, returns the unrecognized name
If a name is not provided, returns 'smiley' (1f603)
TODO: return error messages; don't camouflage the erroneous or missing input
]]
local function emocode (frame)
local emoji_name = mw.text.trim(frame.args[1] or "") -- make sure empty and missing parameters both become the empty string
emoji_name = emoji_name:lower(); -- down case because names in table are all lowercase
emoji_name = emoji_name:gsub ('%s+', '_'); -- replace whitespace with underscore
if '' == emoji_name then emoji_name = 'smiley' end -- use default value of 'smiley' if parameter is empty or missing
return data.emoji_hex_from_name_t[emoji_name] or emoji_name
end
--[[--------------------------< E M O N A M E >----------------------------------------------------------------
return the emoji's name associated with a particular hexadecimal code
{{#invoke:Emoji|emoname|1f603}} → smiley
When the specified hexadecimal code does not exist in the data table, returns the unrecognized code
If a hexadecimal code is not provided, returns '1f603' (smiley)
TODO: return error messages; don't camouflage the erroneous or missing input
]]
local function emoname (frame)
local emoji_code = mw.text.trim(frame.args[1] or "") -- make sure empty and missing parameters both become the empty string
emoji_code = emoji_code:lower(); -- down case because codes in table are all lowercase
if '' == emoji_code then emoji_code = '1f603' end -- use default value of '1f603' if parameter is empty or missing
return data.emoji_name_from_hex_t[emoji_code] or emoji_code
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
emocode = emocode,
emoname = emoname,
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.