Module:Extract

From Irony Wiki
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