Modul:Ordinal

Dari Wiki Javasatu
Revisi sejak 20 September 2023 21.15 oleh Adminjavasatu (bicara | kontrib) (←Membuat halaman berisi '--[[ This template will add the appropriate ordinal prefix to a given integer. Please do not modify this code without applying the changes first at Module:Ordinal/sandbox and testing at Module:Ordinal/sandbox/testcases and Module talk:Ordinal/sandbox/testcases. ]] local p = {} --[[ This function converts an integer value into a numeral followed by ordinal indicator. The output string might contain HTML tags. Usage: {{#invoke:Ordinal|ordinal|1=}} {{#in...')
(beda) ← Revisi sebelumnya | Revisi terkini (beda) | Revisi selanjutnya → (beda)
Loncat ke navigasi Loncat ke pencarian

Dokumentasi untuk modul ini dapat dibuat di Modul:Ordinal/doc

--[[  
 
This template will add the appropriate ordinal prefix to a given integer.
 
Please do not modify this code without applying the changes first at
Module:Ordinal/sandbox and testing at Module:Ordinal/sandbox/testcases and
Module talk:Ordinal/sandbox/testcases.
 
]]

local p = {}

--[[
This function converts an integer value into a numeral followed by ordinal indicator.
The output string might contain HTML tags.
 
Usage:
{{#invoke:Ordinal|ordinal|1=}}
{{#invoke:Ordinal|ordinal}} - uses the caller's parameters
 
Parameters
    1: Any number or string.
]]
function p.ordinal(frame)
	local args = frame.args
    if args[1] == nil then
        args = frame:getParent().args
    end
    if args[1] == nil then
    	args[1] = "{{{1}}}"
    end
    return p._ordinal(args[1])
end

function p._ordinal(n)
	local x = tonumber(mw.ustring.match(n, "(%d*)%W*$"))
	local prefix = "ke-"
	return prefix .. n
end

return p