Modul:Utilities
Vində tispir
Documentation for this module may be created at Modul:Utilities/doc
local Utilities = { }
function Utilities.trim( text )
if type( text ) == 'string' and text ~= '' then
text = text:gsub( '^%s*(%S?.-)%s*$', '%1' )
if text ~= '' then
return text
end
end
return nil
end
function Utilities.validTextArg( args, name, ... )
local text = Utilities.trim( args[name] )
if text then
return text
end
if select( '#', ... ) > 0 then
return Utilities.validTextArg( args, ... )
end
return nil
end
function Utilities.notEmpty( var, ... )
local text = Utilities.trim( var )
if text then
return text
end
local tvar = type( var )
if tvar == 'table' then
local nextFunc = pairs( var )
if nextFunc( var ) ~= nil then
return var
end
elseif var == true or ( tvar == 'number' and var ~= 0 ) or tvar == 'function' then
return var
end
if select( '#', ... ) > 0 then
return Utilities.notEmpty( ... )
end
end
function Utilities.extractArgs ( frame )
if type( frame.getParent ) == 'function' then
local args = frame:getParent().args
for k,v in pairs( frame.args ) do
args[k] = v;
end
return args
else
return frame
end
end
return Utilities