Module:SentenceCase

From Nookipedia, the Animal Crossing wiki

Documentation for this module may be created at Module:SentenceCase/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function search(category, substrings)
    for k,v in pairs(substrings) do
        if string.find(category, v) then
            return true
        end
    end
    return false
end

function p.main(frame)
    local args         = getArgs(frame)
	local name         = args['1'] or ''
    return p.firstToUpper(name)
end

-- https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
function p.firstToUpper(name)
	local keepLowercase = {"iQue", "iQue shirt", "iQueGBA", "amiibo shelf"}
	local aoDai = {"áo dài"}
	if search(name, keepLowercase) == true then
		return name
	elseif search(name, aoDai) == true then
		return "Áo dài"
	else
    	return (name:gsub("^%l", string.upper))
    end
end

return p