Jump to content

Module:GetParameters

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}--[[Helper function that populates the argument list given that user may need to use a mix ofnamed and unnamed parameters. This is relevant because named parameters are notidentical to unnamed parameters due to string trimming, and when dealing with stringswe sometimes want to either preserve or remove that whitespace depending on the application.]]functionp.getParameters(frame_args,arg_list)localnew_args={};localindex=1;localvalue;fori,arginipairs(arg_list)dovalue=frame_args[arg]ifvalue==nilthenvalue=frame_args[index];index=index+1;endnew_args[arg]=value;endreturnnew_args;end--[[Helper Function to interpret boolean strings]]functionp.getBoolean(boolean_str)localboolean_value;iftype(boolean_str)=='string'thenboolean_str=boolean_str:lower();ifboolean_str=='false'orboolean_str=='no'orboolean_str=='0'orboolean_str==''thenboolean_value=false;elseboolean_value=true;endelseiftype(boolean_str)=='boolean'thenboolean_value=boolean_str;elseerror('No boolean value found');endreturnboolean_valueendfunctionp.defined(frame)localarg=mw.text.trim(frame.args[1])--if arg == tostring(tonumber(arg)) then -- undesired result for '-0'-- arg = tonumber(arg)--end--if mw.ustring.find(arg, '^%s*-?[1-9][0-9]*%s*$') ~= nil or arg == '0' then-- arg = tonumber(arg)--endifmw.ustring.find(arg,'^-?[1-9][0-9]*$')~=nilthenarg=tonumber(arg)elseifarg=='0'thenarg=0endreturnframe:getParent().args[arg]~=nilendreturnp
close