Jump to content

Welcome to King Warz Charts Wiki! Please note that the site is still under construction as I work on creating past chart week pages, as well as templates and pages for artists, songs, and albums. Because of this, you may see a lot of red links throughout the site.

Module:AlbumType

From King Warz Charts

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

local p = {}

local superscript_to_normal = {
    ['¹'] = '1',
    ['²'] = '2',
    ['³'] = '3',
    ['⁴'] = '4',
    ['⁵'] = '5',
    ['⁶'] = '6',
    ['⁷'] = '7',
    ['⁸'] = '8',
    ['⁹'] = '9',
    ['⁰'] = '0',
}

function parse_peak(peak)
    if not peak then return nil, nil end
    peak = mw.ustring.gsub(peak, '%s', '')  -- remove spaces
    local base_str, super_str = mw.ustring.match(peak, '^(%d+)(.*)$')
    if not base_str then return nil, nil end
    local base = tonumber(base_str)
    local weeks_str = ''
    for char in mw.ustring.gmatch(super_str, '.') do
        weeks_str = weeks_str .. (superscript_to_normal[char] or '')
    end
    local weeks = tonumber(weeks_str) or 1  -- default to 1 if no superscript
    return base, weeks
end

function p.main(frame)
    local args = frame:getParent().args
    local peak = args.peak or frame.args[1]
    local base, weeks = parse_peak(peak)
    if not base then return '' end  -- or 'Charted Album'
    
    if base == 1 then
        if weeks >= 5 then
            return 'Major Hit Album'
        else
            return 'Number One Hit Album'
        end
    elseif base >= 2 and base <= 5 then
        return 'Hit Album'
    else
        return 'Charted Album'
    end
end

return p