Module:Sandbox

local p = {}

function split(str, pattern) local out = {} local i = 1 local split_start, split_end = string.find(str, pattern, i)   while split_start do        out[#out+1] = string.sub(str, i, split_start - 1) i = split_end + 1 split_start, split_end = string.find(str, pattern, i)   end out[#out+1] = string.sub(str, i)   return out end

function p.outputAvailabilityCollapsed (frame) local data = frame.args[1] local availabilityTable = split( data, "," ) local availability = "" local availabilityList = "" local mainAvailability = "" for k, avail in ipairs(availabilityTable) do       if avail:match("%((.-)%)") then frame:wikitext('') availability = frame:expandTemplate{ title = "Availability", args = { avail:match("(.+)%("), note = avail:match("%((.-)%)") } }       else        	frame:wikitext('')            availability = frame:expandTemplate{ title = "Availability", args = { avail } }        end        if k == 1 then            mainAvailability = availability        else            availabilityList = availabilityList .. availability        end    end    local availabilityOutput = frame:expandTemplate{ title = "User:SuperHamster/Sandbox/Teal", args = { mainAvailability, availabilityList } }

return availabilityOutput end

return p