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 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


return StringUtils