League of Legends Wiki

Module:Feature

English

Module:Feature

2,781pages on
this wiki
Add New Page
Talk0
local lib = {}
 
function lib.mergeFrames(frame, parent)
    local args = {}
    if frame then
        for k,v in pairs(frame.args) do
            args[k] = v
        end
    end
    if parent then
        for k,v in pairs(parent.args) do
            args[k] = v
        end
    end
    return args
end
function lib.arguments(origArgs)
    local args = {}
    for k, v in pairs(origArgs) do
        if type(v) == 'string' then v = mw.text.trim(v) end
        if v ~= '' then args[k] = v end
    end
    return args
end
function lib.getSortedKeys(tab)
    local keys = {}
    for k,_ in pairs(tab) do keys[#keys+1] = k end
    table.sort(keys)
    return keys
end
function lib.groupedArguments(args, numeric)
    if numeric == nil then numeric = true end
    numeric = not not numeric
 
    local base = {}
    local groups = {}
 
    for k, v in pairs(args) do
        v = mw.text.trim(v) or ''
        if v ~= '' then
            if type(k) == 'string' then
                k = mw.text.trim(k) or ''
                if k ~= '' then
                    local split = mw.text.split(k, ':')
                    if #split == 1 then base[k] = v
                    else
                        local group = mw.text.trim(split[1]) or ''
                        local key = mw.text.trim(table.concat(split, ':', 2)) or ''
                        if key ~= '' and group ~= '' then
                            if numeric then
                                group = tonumber(group)
                                if group ~= nil then
                                    if groups[group] == nil then groups[group] = {} end
                                    groups[group][key] = v
                                else
                                    base[k] = v
                                end
                            else
                                if groups[group] == nil then groups[group] = {} end
                                groups[group][key] = v
                            end
                        else
                            base[k] = v
                        end
                    end
                end
            elseif v ~= '' then
                base[k] = v
            end
        end
    end
    return base, groups
end
function lib.ternary(cond, T, F) if cond then return T else return F end end
return lib