Module:Extract

From Irony Wiki
Revision as of 00:01, 16 July 2023 by Saucy (talk | contribs) (see if this helps fix things)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

-- Extracts certain types of strings from a larger string. Useful for passing data into Cargo tables.
local p = {}

-- Extracts the first instance of a number (a substring of continuous digits). Returns an empty string if none are found
function extractNumber(input)
	local match = mw.ustring.match(input, "%d+")
	if match == nil then
		return ""
	else
		return match
	end
end

function p.main(frame)
	if frame.args[1] == "number" then
		return extractNumber(frame.args[2])
	else
		return ""
	end
end

return p