Module:ProcessArgs

From OSDev.wiki
Jump to navigation Jump to search

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

local p = {}

function p.norm( args )
	local result = {}
	for k, v in pairs ( args ) do
		v = mw.text.trim( tostring( v ) )
		if v ~= '' then
			result[k] = v
		end
	end
	return result
end

function p.merge( layers, norm )
	if layers == nil then
		local f = mw.getCurrentFrame()
		layers = { f.args, f:getParent().args }
	end
	if norm == nil then
		norm = true
	end
	local result = {}
	for i, layer in ipairs (layers) do
		for k, v in pairs (layer) do
			v = mw.text.trim( tostring( v ) )
			if not norm or v ~= '' then
				result[k] = v
			end
		end
	end
	return result
end

return p