Home
Random
Log in
Settings
About HighSpell Wiki
Disclaimers
HighSpell Wiki
Search
Editing
Module:RaritySort
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!
local p = {} -- Clean and extract processing info local function clean(rarity) if not rarity or type(rarity) ~= "string" then return nil, false end rarity = mw.text.trim(rarity) local hasTilde = rarity:sub(1, 1) == "~" if hasTilde then rarity = rarity:sub(2) end -- Strip commas (e.g. "1/10,000" β "1/10000") rarity = rarity:gsub(",", "") return rarity, hasTilde end -- RaritySort for sorting function p.getSortValue(frame) local rarityRaw = frame.args[1] local rarity, _ = clean(rarityRaw) if not rarity then return 999999999 end local lowered = rarity:lower() if lowered == "1" or lowered == "always" then return 1 elseif lowered == "rare" then return 999999 elseif lowered == "never" then return 0 end -- Match 1/X and round down (floor) local numStr = lowered:match("^1/(%d+%.?%d*)$") if numStr then local num = tonumber(numStr) if num then return math.floor(num) end end return 999999999 end -- Normalize display text function p.normalizeDisplay(frame) local original = frame.args[1] if not original or type(original) ~= "string" then return "Unknown" end local trimmed = mw.text.trim(original) local hasTilde = trimmed:sub(1, 1) == "~" local raw = hasTilde and trimmed:sub(2) or trimmed if raw == "1" then return "Always" end return hasTilde and ("~" .. raw) or raw end return p
Summary:
Please note that all contributions to HighSpell Wiki 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
HighSpell Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:RaritySort/doc
(
edit
)