Module:List

From Nookipedia, the Animal Crossing wiki

Documentation for this module may be created at Module:List/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function split(str, pattern)
    local out = {}
    for m in string.gmatch(str, "[^" .. pattern .. "]+") do
      table.insert(out, m)
    end
    return out
end

function p.main(frame)
    local args       = getArgs(frame)
    local listOfList = split( args[1], "," ) or ''
    return p.listFormat(listOfList)
end

function p.listFormat(listOfList)
	local listOf = ''
	for l = 1, #listOfList do
    	if l == #listOfList and l-1 ~= 0 then
        	listOf = listOf .. 'and '
        end
        listOf = listOf .. listOfList[l]
        if l == #listOfList then
        	listOf = listOf .. ''
        elseif l-1 == 0 and l+1 == #listOfList then
        	listOf = listOf .. ' '
        else
        	listOf = listOf .. ', '
        end
	end
	return listOf
end

return p