Module:RaritySort: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:


function p.getSortValue(rarity)
function p.getSortValue(rarity)
     return tostring(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
end


return p
return p

Revision as of 17:19, 15 May 2025

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