Module:StringUtils: Difference between revisions
From MENACE Official Wiki
mNo edit summary |
mNo edit summary |
||
| Line 17: | Line 17: | ||
--- Converts a string to uppercase | --- Converts a string to uppercase | ||
function StringUtils.toUpperCase(frame) | function StringUtils.toUpperCase(frame) | ||
if | if frame.args then | ||
input = frame.args[1] or frame.args.name | input = frame.args[1] or frame.args.name | ||
return string.upper(input) | return string.upper(input) | ||
| Line 26: | Line 26: | ||
--- Converts a string to titlecase | --- Converts a string to titlecase | ||
function StringUtils.toTitleCase(frame) | function StringUtils.toTitleCase(frame) | ||
if | if frame.args then | ||
input = frame.args[1] or frame.args.name | input = frame.args[1] or frame.args.name | ||
local result, count = input:gsub("(%a)([%w']*)", function(first, rest) | local result, count = input:gsub("(%a)([%w']*)", function(first, rest) | ||
Revision as of 20:16, 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(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 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 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


