Jump to content

Module:Emoji: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
does this work?
No edit summary
Line 1: Line 1:
require ('strict');
local p= {}


local data = mw.loadData ('Module:Emoji/data');
function p.emocode(frame)

local emotbl = mw.loadData ('Module:Emoji/data').emotbl

local emoname = mw.text.trim(frame.args[1] or "") -- make sure empty and missing parameters both become the empty string
--[[--------------------------< E M O C O D E >----------------------------------------------------------------
if '' == emoname then emoname = 'smiley' end -- use default value of 'smiley' if parameter is empty or missing

return emotbl[emoname] or emoname
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
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
end



function p.emoname(frame)
--[[--------------------------< E M O N A M E >----------------------------------------------------------------
local emorevtbl = mw.loadData('Module:Emoji/data/revtable')['emorevtbl']

local emocode = mw.text.trim(frame.args[1] or "") -- make sure empty and missing parameters both become the empty string
return the emoji's name associated with a particular hexadecimal code
if '' == emocode then emocode = '1f603' end -- use default value of '1f603' if parameter is empty or missing

return emorevtbl[emocode] or emocode
{{#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
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
end



return p
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

return {
emocode = emocode,
emoname = emoname,
}

Revision as of 19:54, 10 March 2024

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
	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
	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,
	}