Module:Sandbox/Danski454/UBLSortable

require('strict') local p = {} local getArgs = require('Module:Arguments').getArgs local TableTools = require('Module:TableTools') local ListModule = require('Module:List') -- based on Module:Sort list

function p.asc(frame) local args = getArgs(frame) return p._asc(args) end

function p._asc(args) local listItems = {} -- loop over args (copied from Module:Old XfD multi) for k, v in pairs(args) do		if type(k) == 'string' then local prefix, num = k:match('^(.-)([1-9][0-9]*)$') if prefix and num then num = tonumber(num) if not listItems[num] then listItems[num] = {} end listItems[num][prefix] = v			end end end listItems = TableTools.compressSparseArray(listItems) table.sort(listItems, function (a, b)   	local ak = a.key or a.item    	local bk = b.key or b.item    	if tonumber(ak) and tonumber(bk) then    		return tonumber(ak) < tonumber(bk)     	else    		return ak < bk    	end 	end) return p.renderList(listItems) end

function p.desc(frame) local args = getArgs(frame) return p._desc(args) end

function p._desc(args) end

function p.renderList(listItems) local args = {} for i=1, #listItems do		if listItems[i].item and mw.ustring.find(listItems[i].item, '%S') then args[#args+1] = listItems[i].item end end return ListModule.makeList('unbulleted', args) end

return p