Module:List

From RosieSoCrossing
Revision as of 11:47, 14 January 2026 by Rosie (talk | contribs) (Created page with "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 ==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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