Module:Args

return { getRaw = function (key) local frame = mw.getCurrentFrame return frame.args[key] or frame:getParent.args[key] or nil end,

-- return trimmed input value, if not keep_blank, it will return nil when input == ''(invoked with |arg= ) get = function(key, keep_blank) local frame = mw.getCurrentFrame local value = frame.args[key] or frame:getParent.args[key] or nil if value then value = mw.text.trim(value) if value ~= '' or keep_blank then return value end end return nil end,

-- return a bool value, with two modes: -- default mode: if the input flag matches a negative word, return false. otherwise, return true. -- strict mode: if the input flag matches a positive word, return true. if it matches a negative word, return false. if neither, return nil. getFlag = function(key, strict) local frame = mw.getCurrentFrame local flagWord = frame.args[key] or frame:getParent.args[key] or nil -- Normalize string if flagWord then flagWord = mw.text.trim(flagWord):lower end -- Affirmative and negative keywords placed here for reducing redundancy local affirmative = { "1", "y", "yes", "on", "t", "true" } local negative = { "0", "n", "no", "off", "f", "false" } -- Default values local matchAffirmative = false local matchNegative = false -- Check against the lists for key, value in pairs(affirmative) do -- For all the values/"items" in the list, do this: if value == flagWord then matchAffirmative = true end -- You dont want to add an else, since otherwise only the last item would count. end -- No need to check this if the above returns true. if not matchAffirmative then for key, value in pairs(negative) do -- For all the values/"items" in the list, do this: if value == flagWord then matchNegative = true end -- You dont want to add an else, since otherwise only the last item would count. end end if strict then if matchAffirmative then return true else if matchNegative then return false end return nil end else if matchNegative then return false else return true end end end, -- option = {trim=true, keep_blank=false} getAll = function(option) option = option or {} local trim = option['trim'] or true local keep_blank = option['keep_blank'] or false

local frame = mw.getCurrentFrame

local args = frame.args local parent_args = frame:getParent.args for k, v in pairs(args) do			parent_args[k] = v		end result = {} for k, v in pairs(parent_args) do			if trim then v = mw.text.trim(v) end if keep_blank then result[k] = v			else if v ~= '' then result[k] = v				end end end

return result end, }