Module:Arguments

--- Wrapper for Arguments. Parses frames from regulated template parameters. -- -- @module             Arguments -- @see                Arguments from Fandom Developers Wiki -- @release            beta -- @class              utility -- @require            w:c:dev:Module:Arguments

local _args = {}

_args.getArgs = require('Dev:Arguments').getArgs

function _args.getNumberedAndNamed(args) local numbered = {} for k, v in pairs(args) do		if type( k ) == "number" then numbered[k] = v			args[k] = nil end end return { numbered = numbered, named = args } end

function _args.keysToLower(args) for k, v in pairs(args) do		if k and type( k ) ~= 'number' then args[k] = nil args[ mw.ustring.lower( k ) ] = v		end end return args end

function _args.setDefaults(args, defaults) for k, v in pairs(defaults) do		if not args[k] then	args[k] = v end end return args end

function _args.translateAliases(args, aliases) for k, v in pairs(aliases) do		for _, alias in pairs(v) do			if args[alias] then args[k] = args[alias] args[alias] = nil break end end end return args end

function _args.normalize(frame, argData, options) local args = nil options = options or {} if options.split == nil then options.split = false end if options.lowerKeys == nil then options.lowerKeys = true end if options.convertBooleans == nil then options.convertBooleans = true end args = _args.getArgs( frame, options ) if argData.aliases then args = _args.translateAliases(args, argData.aliases) end if argData.defaults then args = _args.setDefaults(args, argData.defaults) end if options.split == true then args = _args.getNumberedAndNamed(args) end if options.lowerKeys == true then args = _args.keysToLower(args) end for k, v in pairs(args) do		if mw.ustring.lower(v) == 'true' then args[k] = true elseif mw.ustring.lower(v) == 'false' then args[k] = false end end return args end

return _args