Editing Module:ParamtestGive feedback
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
-- | -- | ||
-- Tests basic properties of parameters | -- Tests basic properties of parameters | ||
| Line 26: | Line 9: | ||
-- | -- | ||
function p.is_empty(arg) | function p.is_empty( arg ) | ||
if not arg or not arg:find('%S') then | |||
return true | |||
end | |||
return false | |||
end | end | ||
| Line 34: | Line 21: | ||
-- | -- | ||
function p.default_to( | function p.default_to(param, default) | ||
if | if param and param:find('%S') then | ||
return | return param | ||
else | else | ||
return default | return default | ||
| Line 43: | Line 30: | ||
-- | -- | ||
-- | -- Tests if the parameter has content | ||
-- The same as !is_empty, but this is more readily clear | |||
-- | -- | ||
function p. | |||
function p.has_content( arg ) | |||
if not arg or not arg:find('%S') then | |||
return false | |||
end | end | ||
return | |||
return true | |||
end | end | ||
-- | -- | ||
-- Tests if the parameter has content | -- Tests if the parameter has been defined (regardless of content) | ||
-- | -- | ||
function p.is_defined( arg ) | |||
if not arg then | |||
return false | |||
else | |||
return true | |||
end | |||
end | |||
-- | |||
-- Removes leading and trailing whitespace from the parameter | |||
-- Which is unfortunately not removed when passed through invoke | |||
-- | -- | ||
function p. | function p.trim( arg ) | ||
return string. | return string.gsub( arg, '^%s*(%S+)%s*$', '%1') | ||
end | end | ||
| Line 71: | Line 67: | ||
-- | -- | ||
function p.ucfirst(arg) | function p.ucfirst( arg ) | ||
if not arg or arg:len() == 0 then | if not arg or arg:len() == 0 then | ||
return nil | return nil | ||
| Line 85: | Line 81: | ||
-- | -- | ||
function p.ucflc(arg) | function p.ucflc( arg ) | ||
if not arg or arg:len() == 0 then | if not arg or arg:len() == 0 then | ||
return nil | return nil | ||