Module:StringUtils
From MENACE Official Wiki
Documentation for this module may be created at Module:StringUtils/doc
---
--- Provides common utilities for strings
---
---@module StringUtils
local StringUtils = {}
--- Converts a string to lowercase
function StringUtils.toLowerCase(frame)
if frame.args then
input = frame.args[1] or frame.args.name
return string.lower(input)
end
return nil
end
--- Converts a string to uppercase
function StringUtils.toUpperCase(frame)
if type(frame) == "string" and frame.args then
input = frame.args[1] or frame.args.name
return string.upper(input)
end
return nil
end
--- Converts a string to titlecase
function StringUtils.toTitleCase(frame)
if type(frame) == "string" and frame.args then
input = frame.args[1] or frame.args.name
local result, count = input:gsub("(%a)([%w']*)", function(first, rest)
return first:upper() .. rest:lower()
end)
return result
end
return nil
end
-- Main entry point for the module
--[[function StringUtils.main(frame)
local input = frame.args[1] or ""
local action = frame.args[2] or "lower"
if action == "lower" then
return StringUtils.toLowerCase(input)
elseif action == "upper" then
return StringUtils.toUpperCase(input)
elseif action == "title" then
return StringUtils.toTitleCase(input)
else
return "ERROR at StringUtils module: Invalid action"
end
end--]]
return StringUtils


