Module:Align number list
Appearance
local getArgs = require('Module:Arguments').getArgs
local p = {}
local fsp = ' '
local function charXN(c, num)
local str = ""
for i=1,num do
str = str .. c
end
return str
end
local function intPartLen(str)
local counter = 0
for i = 1, #str do
local c = str:sub(i,i)
if c:match("%d") then
counter = counter + 1
else
break
end
end
return counter
end
local function findLongestInt(myTable)
local longestInt = 0
for key,value in pairs(myTable) do
local tmpCounter = intPartLen(value)
if longestInt < tmpCounter then
longestInt = tmpCounter
end
end
return longestInt
end
local function processList(argStr)
local myTable = mw.text.split(argStr, '\n')
local longestInt = findLongestInt(myTable)
local outputStr = ""
for key,value in pairs(myTable) do
local tmpCounter = intPartLen(value)
outputStr = outputStr
.. charXN(fsp, longestInt - tmpCounter)
.. value .. "<br>"
end
return outputStr
end
function p.main(frame)
local args = getArgs(frame)
if args and args[1] ~= nil then
return processList(args[1])
end
end
return p