Module:RaritySort: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
Undo revision 2897 by Ryan (talk)
Tag: Undo
Line 2: Line 2:


function p.getSortValue(rarity)
function p.getSortValue(rarity)
    -- Return 99 if rarity is nil or not a string
     if rarity == nil or type(rarity) ~= "string" then
     if rarity == nil or type(rarity) ~= "string" then
         return "Input was nil or not string"
         return 99
     end
     end


     local r = mw.ustring.lower(rarity)
     local r = mw.ustring.lower(rarity)


     -- Show what was passed in and how it's interpreted
     if r == "always" then
     return "Input: " .. rarity .. " | Interpreted: " .. r
        return 1
     elseif r:match("^1/%d+") then
        return 2
    elseif r == "rare" then
        return 3
    elseif r == "never" then
        return 4
    else
        return 99
    end
end
end


return p
return p

Revision as of 17:14, 15 May 2025

Documentation for this module may be created at Module:RaritySort/doc

local p = {}

function p.getSortValue(rarity)
    -- Return 99 if rarity is nil or not a string
    if rarity == nil or type(rarity) ~= "string" then
        return 99
    end

    local r = mw.ustring.lower(rarity)

    if r == "always" then
        return 1
    elseif r:match("^1/%d+") then
        return 2
    elseif r == "rare" then
        return 3
    elseif r == "never" then
        return 4
    else
        return 99
    end
end

return p