-- Imported from https://oldschool.runescape.wiki/w/Module:Paramtest
--
-- Meta module to standardize common modifications to incoming parameters
-- Tests basic properties of parameters
--
localp={}
--
-- Tests if the parameter is empty, all white space, or undefined
--
functionp.is_empty(arg)
returnnotstring.find(argor'','%S')
end
--
-- Returns the parameter if it has any content, the default (2nd param)
--
functionp.default_to(arg,default)
ifstring.find(argor'','%S')then
returnarg
else
returndefault
end
end
--
-- Returns a list of paramaters if it has any content, or the default
--
functionp.defaults(...)
localret={}
fori,vinipairs(...)do
ifstring.find(v[1]or'','%S')then
table.insert(ret,v[1])
else
-- or false, because nil is removed
table.insert(ret,v[2]orfalse)
end
end
returnunpack(ret)
end
--
-- Tests if the parameter has content
-- The same as !is_empty, but this is more readily clear
--
functionp.has_content(arg)
returnstring.find(argor'','%S')
end
--
-- uppercases first letter
--
functionp.ucfirst(arg)
ifnotargorarg:len()==0then
returnnil
elseifarg:len()==1then
returnarg:upper()
else
returnarg:sub(1,1):upper()..arg:sub(2)
end
end
--
-- uppercases first letter, lowercases everything else
--
functionp.ucflc(arg)
ifnotargorarg:len()==0then
returnnil
elseifarg:len()==1then
returnarg:upper()
else
returnarg:sub(1,1):upper()..arg:sub(2):lower()
end
end
returnp