Module:Texte

De Poképédia
local p = {}
 
function p.ouiparmi( frame )
    if mw.ustring.find(frame.args[1], "oui", 1, true) ~= nil then
        return "oui"
    end
    return "non"
end

function p.pluscourt( frame )
    if mw.ustring.len( frame.args[1] ) >= 22 then
        return mw.ustring.sub( frame.args[1], 1, 22 ) .. '…'
    else
        return frame.args[1]
    end

end

function p.donneelement( frame )
    return mw.text.split( frame.args[1], ", ", true )[tonumber(frame.args[2])]
end

function p.remplirTroisZeros(frame)
	local s = frame.args[1]
	if not s then return "000" end
	
	local s_split = mw.text.split(s, "-")
	local ans = ""
	local i = 1
	
	while s_split[i] do
		local s_i = s_split[i]
		
		if s_i:match("[0-9][0-9][0-9]")
		then
		elseif s_i:match("[0-9][0-9]")
		then s_i = mw.ustring.gsub(s_i, "([0-9][0-9])", "0%1")
		elseif s_i:match("[0-9]")
		then s_i = mw.ustring.gsub(s_i, "([0-9])", "00%1")
		end
		
		if i ~= 1
		then ans = ans .. "-"
		end
		
		ans = ans .. s_i
		i = i + 1
	end
	return ans
end

return p