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 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 return p