Module:StringUtils: Difference between revisions
From MENACE Official Wiki
mNo edit summary |
mNo edit summary |
||
| Line 34: | Line 34: | ||
-- Main entry point for the module | -- Main entry point for the module | ||
function StringUtils.main(frame) | --[[function StringUtils.main(frame) | ||
local input = frame.args[1] or "" | local input = frame.args[1] or "" | ||
local action = frame.args[2] or "lower" | local action = frame.args[2] or "lower" | ||
| Line 47: | Line 47: | ||
return "ERROR at StringUtils module: Invalid action" | return "ERROR at StringUtils module: Invalid action" | ||
end | end | ||
end | end--]] | ||
return StringUtils | return StringUtils | ||
Revision as of 19:57, 7 October 2025
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(input)
if type(input) == "string" then
return string.lower(input)
end
return nil
end
--- Converts a string to uppercase
function StringUtils.toUpperCase(input)
if type(input) == "string" then
return string.upper(input)
end
return nil
end
--- Converts a string to titlecase
function StringUtils.toTitleCase(input)
if type(input) == "string" then
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


