Module:Functions

local p = {} local function range(a, b, step) if not b then b = a   a = 1 end step = step or 1 local f = step > 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue <= b then return nextvalue end end or   step < 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue >= b then return nextvalue end end or     function(_, lastvalue) return lastvalue end return f, nil, a - step end local function split(inputstr, sep) if sep == nil then sep = "%s" end local t={} for str in string.gmatch(inputstr, "([^"..sep.."]+)") do               table.insert(t, str) end return t end local function round(val, decimal) if (decimal) then return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) else return math.floor(val+0.5) end end local function numbers(number) local lang = mw.language.getContentLanguage:getCode local fN = require('Dev:Formatnum').formatNum return fN(tonumber(number), lang) end function compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end

function upperFirstLetter(str) return (str:gsub("^%l", string.upper)) end

function noPage(frame, pagename, content) return frame:expandTemplate{title = "createpageifnotex", args={ NS_MAIN = pagename, NS_TEMPLATE = content }} end

function time(seconds) local seconds = tonumber(seconds) if seconds <= 0 then return "0S"; else toReturn = "" days = string.format("%02.f", math.floor(seconds/86400)); hours = string.format("%02.f", math.floor(seconds/3600 - (days*24))); mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); if(days>0) then toReturn = toReturn..days.."D "; end if(hours>0) then toReturn = toReturn..hours.."H "; end if(mins>0) then toReturn = toReturn..mins.."M "; end if (secs>0) then toReturn = toReturn..secs.."S"; end return toReturn; end end p.range=range p.split=split p.round=round p.numbers=numbers p.compareLess=compareLess p.compareMore=compareMore p.tableSort=tableSort p.upfirst = upperFirstLetter p.noPage = noPage p.time = time return p