Jump to content

Module:StringUtil

From Shark's Hypothetical Weather
Revision as of 09:18, 2 May 2025 by Sharkius (talk | contribs) (Created page with "local p = {} -- Removes "EF" prefix and "+" suffix, e.g., EF3+ → 3 function p.stripEFPlus(frame) local input = frame.args[1] or "" return input:gsub("^EF", ""):gsub("%+$", "") end -- Removes "EF" prefix only, e.g., EF3+ → 3+ function p.stripEFPrefix(frame) local input = frame.args[1] or "" return input:gsub("^EF", "") end -- Adds "+" if the input ends in "+", else returns empty function p.plusSuffix(frame) local input = frame.args[1] or "" if input:match("%+...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:StringUtil/doc

local p = {}

-- Removes "EF" prefix and "+" suffix, e.g., EF3+ → 3
function p.stripEFPlus(frame)
	local input = frame.args[1] or ""
	return input:gsub("^EF", ""):gsub("%+$", "")
end

-- Removes "EF" prefix only, e.g., EF3+ → 3+
function p.stripEFPrefix(frame)
	local input = frame.args[1] or ""
	return input:gsub("^EF", "")
end

-- Adds "+" if the input ends in "+", else returns empty
function p.plusSuffix(frame)
	local input = frame.args[1] or ""
	if input:match("%+$") then
		return "+"
	else
		return ""
	end
end

return p