Module:Eicons

local trim = mw.text.trim

local function parameter(parameter, base) if parameter == 'y' or parameter == 'yes' then return true end if parameter == 'n' or parameter == 'no' then return false end return base end

local function getVersionInfo(raw) if not raw or raw == '' then return false, false, false, false, false, false else return raw:find('d'),raw:find('c'),raw:find('o'),raw:find('m'),raw:find('3'),raw:find('j') end end

local function eicons(vd, vc, vo, vm, v3, vj, _small, _link) local link = '' local size local result='' if vd then space = true if _link then link = 'Desktop Version history' end if _small then size = '12' else size = '16' end result = result .. ''	end if vc then if space then result = result .. '&thinsp;' end space = true if _link then link = 'Console version' end if _small then size = '13' else size = '17' end result = result .. ''	end if vj then if space then result = result .. '&thinsp;' end space = true if _link then link = 'Old-gen console version#Japanese Release' end if _small then size = '12' else size = '16' end result = result .. ''	end if vo then if space then result = result .. '&thinsp;' end space = true if _link then link = 'Old-gen console version' end if _small then size = 'x12' else size = 'x16' end result = result .. ''	end if vm then if space then result = result .. '&thinsp;' end space = true if _link then link = 'Mobile Version' end if _small then size = 'x12' else size = 'x16' end result = result .. ''	end if v3 then if space then result = result .. '&thinsp;' end if _link then link = '3DS version' end if _small then size = '24' else size = '32' end result = result .. ''	end return result end

local getArg = function(key, frame) local value = frame.args[key] if not value then return nil end value = mw.text.trim(value) if value == '' then return nil else return value end end

-- main return object return {

simple = function(frame) local _versions = getArg(1, frame) local _small = getArg('small', frame) local _link = getArg('link', frame) if not _versions or versions=='dcom3' or versions=='dcom3j' then return '' else local vd,vc,vo,vm,v3,vj = getVersionInfo(_versions) return mw.text.tag('span',{class='eico'}, eicons(vd, vc, vo, vm, v3, vj, _small, _link)) end end,

go = function(frame) local _versions = getArg(1, frame) local _small = getArg('small', frame) local _desktop = getArg('desktop', frame) local _console = getArg('console', frame) local _oldgen = getArg('old-gen', frame) local _mobile = getArg('mobile', frame) local _3ds = getArg('3ds', frame) local _japan = getArg('japan', frame) local _invert = getArg('invert', frame) local _link = getArg('link', frame) local vd,vc,vo,vm,v3,vj = getVersionInfo(_versions)

if _invert then vd = not vd		vc = not vc		vo = not vo		vm = not vm		v3 = not v3		vj = false end

if vd and vc and vo and vm and v3 then vd = false vc = false vo = false vm = false v3 = false vj = false end

vd = parameter(_desktop, vd) vc = parameter(_console, vc) vo = parameter(_oldgen, vo) vm = parameter(_mobile, vm) v3 = parameter(_3ds, v3) vj = parameter(_japan, vj)

if vd or vc or vo or vm or v3 or vj then return mw.text.tag('span',{class='eico'}, eicons(vd, vc, vo, vm, v3, vj, _small, _link)) else return '' end end,

icons = function(versions, _small, frame, _link) -- _link at last for historical compatibility if not versions or versions=='' or versions=='dcom3' or versions=='dcom3j' then return '' end local vd,vc,vo,vm,v3,vj = getVersionInfo(versions) return eicons(vd, vc, vo, vm, v3, vj, _small, _link) end,

eil = function(frame) local args = frame:getParent.args local _arg1 = trim(args[1] or '') local _arg2 = trim(args[2] or '') if _arg2 == '' then _arg2 = nil end local text if _arg2 then -- intuitive pluralism -- The comparisons are performed in order, so putting the more common ones in front gives the best performance. if _arg2 == 's' then local suffix1 = _arg1:sub(-1) -- cache for better performance. local suffix2 = _arg1:sub(-2) -- cache for better performance. if suffix1 == 'y' then if suffix2 == 'ay' or suffix2 == 'ey' or suffix2 == 'iy' or suffix2 == 'oy' or suffix2 == 'uy' then text = _arg1 .. 's'                -- eg. ray->rays else text = _arg1:sub(1, -2) .. 'ies'   -- eg. firefly->fireflies end elseif suffix2 == 'fe'then text = _arg1:sub(1, -3) .. 'ves'       -- eg. knife->knives elseif suffix1 == 'f' and suffix2 ~= 'ff' then text = _arg1:sub(1, -2) .. 'ves'       -- eg. wolf->wolves, leaf->leaves, but buff->buffs else text = _arg1 .. 's'			end elseif _arg2 == 'es' then text = _arg1 .. 'es' elseif _arg2 == 'ies' then text = _arg1:sub(1, -2) .. 'ies' elseif _arg2 == 'ves' then if _arg1:sub(-2) == 'fe' then text = _arg1:sub(1, -3) .. 'ves'   --replace last 2 letters, e.g. knife->knives elseif _arg1:sub(-1) == 'f' or _arg1:sub(-2) ~= 'ff' then text = _arg1:sub(1, -2) .. 'ves'   --replace last letter, e.g. wolf-wolves, leaf->leaves, but buff->buffs end else text = _arg2 end else text = _arg1 end local str = ' '

if trim(args['nolink'] or ) ~=  or trim(args['nl'] or ) ~=  or frame:preprocess() ~=  then str = str .. text else if _arg1 == text then str = str .. .._arg1.. else str = str .. ..text.. end end

local _eicons = trim(args['eicons'] or '') if _eicons ~= '' then str = str .. _eicons else local versions = frame:preprocess('') if versions~='' and versions~='dcom3' and versions~='dcom3j' then local _small = trim(args['small'] or frame:preprocess() or ) if _small:sub(1,1) == 'n' then _small = nil end local _iconlink = trim(args['iconlink'] or frame:preprocess() or ) if _iconlink == '' then _iconlink = nil end local vd,vc,vo,vm,v3,vj = getVersionInfo(versions) str = str .. ' ' .. eicons(vd, vc, vo, vm, v3, vj, _small, _iconlink) ..' ' end end str = str .. ' '	return str end,

}