Module:Utility

--[=[

LUA Module for Utility Functions

wordinal: Word-Ordinal form of number Parameters: 1 = Number (0-99) Return: Ordinal in Word form of number "??" for 0 or non-numeric input Input number for number >= 100 --]=]

local p = {}

local tOnesOrd = { [0] = '??',	[1] = 'first', [2] = 'second', [3] = 'third', [4] = 'fourth', [5] = 'fifth', [6] = 'sixth', [7] = 'seventh', [8] = 'eighth', [9] = 'ninth', [10] = 'tenth', [11] = 'eleventh', [12] = 'twelfth', [13] = 'thirteenth', [14] = 'fourteenth', [15] = 'fifteenth', [16] = 'sixteenth', [17] = 'seventeenth', [18] = 'eighteenth', [19] = 'nineteenth' }

local tTensOrd = { [2] = 'twentieth', [3] = 'thirtieth', [4] = 'fortieth', [5] = 'fiftieth', [6] = 'sixtieth', [7] = 'seventieth', [8] = 'eightieth', [9] = 'ninetieth' }

local tTens = { [2] = 'twenty', [3] = 'thirty', [4] = 'forty', [5] = 'fifty', [6] = 'sixty', [7] = 'seventy', [8] = 'eighty', [9] = 'ninety' }

function p.wordinal(num) local n = tonumber(num) or 0 if n >= 100 then return num end

if n < 20 then return tOnesOrd[n] elseif n % 10 == 0 then return tTensOrd[n / 10] else return tTens[math.floor(n / 10)] .. '-' .. tOnesOrd[n % 10] end end

return p