Fortnite Esports Wiki
Advertisement

Edit the documentation or categories for this module.


local bool_false = { ['false'] = true, ['no'] = true, [''] = true }

local lang = mw.getLanguage('en')

local p = {}

function p.norm(v)
	if not v then
		return false
	elseif bool_false[lang:lc(v)] then
		return false
	end
	return v
end

function p.lookupVars(str, lookup_tbl, skipdefault)
	-- for rolenames etc. if a default table is supplied, this will be
	-- returned with priority over lookup.DEFAULT in the case of no match
	local vars = str and lookup_tbl[lang:lc(str)]
	if not vars then
		if skipdefault then
			return nil
		end
		return lookup_tbl.DEFAULT
	end
	if type(vars) == 'string' then
		vars = lookup_tbl[vars]
	end
	return vars
end

function p.merge(norm)
	local f = mw.getCurrentFrame()
	local origArgs = f.args
	local parentArgs = f:getParent().args

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

function p.overwrite(origArgs, parentArgs, norm)
	if type(origArgs) ~= 'table' then
		norm = origArgs
		local f = mw.getCurrentFrame()
		origArgs = f.args
		parentArgs = f:getParent().args
	end
	local args = {}
	
	for k, v in pairs(parentArgs) do
		v = mw.text.trim(v)
		if norm and v ~= '' then
			args[k] = p.norm(v)
		elseif v ~= '' then
			args[k] = v
		end
	end
	
	for k, v in pairs(origArgs) do
		v = mw.text.trim(tostring(v))
		if norm and v ~= '' then
			args[k] = p.norm(v)
		elseif v ~= '' then
			args[k] = v
		end
	end
	
	return args
end

function p.numberedArgsToTable(args, argname, disallowUnnamedFirst)
	local i = 1
	local tbl = {}
	if args[argname] and not disallowUnnamedFirst then
		tbl[1] = args[argname]
		i = 2
	end
	while args[argname .. i] do
		tbl[i] = args[argname .. i]
		i = i + 1
	end
	if not next(tbl) then
		return nil
	end
	return tbl
end
return p
Advertisement