Module:RaritySort

From HighSpell Wiki
Revision as of 17:15, 15 May 2025 by Ryan (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

function p.getSortValue(rarity)
    -- Handle nil or non-string input safely
    if rarity == nil or type(rarity) ~= "string" then
        return 99
    end

    -- Trim whitespace and lowercase it
    rarity = mw.text.trim(rarity)
    local r = mw.ustring.lower(rarity)

    -- Matching known rarities
    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 -- unknown or custom text
    end
end

return p