Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Danski454/UBLSortable
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Danski454/UBLSortable/doc
(
edit
)