Module:RaritySort: Difference between revisions
Tag: Undo |
No edit summary |
||
Line 2: | Line 2: | ||
function p.getSortValue(rarity) | function p.getSortValue(rarity) | ||
-- | -- Handle nil or non-string input safely | ||
if rarity == nil or type(rarity) ~= "string" then | if rarity == nil or type(rarity) ~= "string" then | ||
return 99 | return 99 | ||
end | end | ||
-- Trim whitespace and lowercase it | |||
rarity = mw.text.trim(rarity) | |||
local r = mw.ustring.lower(rarity) | local r = mw.ustring.lower(rarity) | ||
-- Matching known rarities | |||
if r == "always" then | if r == "always" then | ||
return 1 | return 1 | ||
elseif r:match("^1/%d+") then | elseif r:match("^1/%d+$") then | ||
return 2 | return 2 | ||
elseif r == "rare" then | elseif r == "rare" then | ||
Line 18: | Line 21: | ||
return 4 | return 4 | ||
else | else | ||
return 99 | return 99 -- unknown or custom text | ||
end | end | ||
end | end | ||
return p | return p |