Module:Color

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

local p = {}

function p.normalize(frame)
    local color = frame.args[1] or ""
    color = mw.text.trim(color)

    if color:match("^#%x%x%x$") or
       color:match("^#%x%x%x%x$") or
       color:match("^#%x%x%x%x%x%x$") or
       color:match("^#%x%x%x%x%x%x%x%x$") then
        return color
    end

    if color:match("^%x%x%x$") or
       color:match("^%x%x%x%x$") or
       color:match("^%x%x%x%x%x%x$") or
       color:match("^%x%x%x%x%x%x%x%x$") then
        return "#" .. color
    end

    return color
end

return p