Module:Ucfirst

From NPOWiki
Jump to navigation Jump to search

Documentation [edit]

This is a shortcut to change the first letter of the given text to uppercase. It is only usable by other modules, not through invocation, because wikitext can simply use the ucfirst magic word. It will have no effect on numbers, the empty string, and nil. Other types will cause an error.

Example

local ucfirst = require('Module:ucfirst')
local foo = ucfirst('foo')-- returns "Foo"

The above documentation is transcluded from Module:Ucfirst/doc.

return function (arg)
	if type(arg) ~= 'string' and type(arg) ~= 'number' then
		return ''
	end
	return mw.ustring.upper(mw.ustring.sub(arg, 1, 1)) .. mw.ustring.sub(arg, 2)
end