Module:RaritySort

Revision as of 17:19, 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 "was nil or not string"
    end

    local trimmed = mw.text.trim(rarity)
    local lowered = string.lower(trimmed)

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

return p