Module:RaritySort

Revision as of 17:16, 15 May 2025 by Ryan (talk | contribs)

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

local p = {}

function p.getSortValue(rarity)
    if rarity == nil or type(rarity) ~= "string" then
        return 99
    end

    local raw = rarity
    rarity = mw.text.trim(rarity)
    local r = mw.ustring.lower(rarity)

    -- Debug: remove these after testing
    if mw.title.getCurrentTitle().text == "Sandbox" then
        return "RAW: " .. tostring(raw) .. " | TRIMMED: " .. rarity
    end

    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