Zum Inhalt springen
Das Halloween-Event (Süßes oder Saures) ist beendet. Du kannst verbleibende Kürbisse noch im Hexenhütte eintauschen.

Modul:Firestone/Util: Unterschied zwischen den Versionen

Aus Firestone Idle Rpg Wiki
Die Seite wurde neu angelegt: „-- Modul:Firestone/Util local U = {} U.DAY = 86400 -- "2025-11-05" → os.time(...) function U.parseIsoDate(s) local y,m,d = tostring(s or ""):match("^(%d%d%d%d)%-(%d%d)%-(%d%d)$") if not y then return nil end return os.time{ year = tonumber(y), month = tonumber(m), day = tonumber(d), hour = 12 } end -- Timestamp → MediaWiki-Timestamp local function tsToMw(ts) return os.date("!%Y%m%d%H%M%S", ts) end function U.formatDateDe(v) loc…“
(kein Unterschied)

Version vom 5. November 2025, 11:09 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Firestone/Util/Doku erstellt werden

-- Modul:Firestone/Util
local U = {}

U.DAY = 86400

-- "2025-11-05" → os.time(...)
function U.parseIsoDate(s)
    local y,m,d = tostring(s or ""):match("^(%d%d%d%d)%-(%d%d)%-(%d%d)$")
    if not y then return nil end
    return os.time{ year = tonumber(y), month = tonumber(m), day = tonumber(d), hour = 12 }
end

-- Timestamp → MediaWiki-Timestamp
local function tsToMw(ts)
    return os.date("!%Y%m%d%H%M%S", ts)
end

function U.formatDateDe(v)
    local ts = (type(v) == "number") and v or U.parseIsoDate(v)
    if not ts then return "" end
    local lang = mw.getContentLanguage()
    return lang:formatDate("d.m.Y", tsToMw(ts))
end

function U.isEmpty(v)
    return v == nil or v == ""
end

function U.norm(s)
    if s == nil then return "" end
    s = mw.text.trim(tostring(s))
    return mw.ustring.lower(s):gsub("%s+"," ")
end

-- Parent-Args bevorzugen
function U.getArgs(frame)
    local p = frame:getParent()
    local src = (p and p.args) or frame.args or {}
    local a = {}
    for k,v in pairs(src) do
        if v ~= nil and v ~= "" then
            a[k] = mw.text.trim(tostring(v))
        end
    end
    return a
end

function U.hasItems(t)
    if type(t) ~= "table" then return false end
    for _ in pairs(t) do return true end
    return false
end

-- versucht "halloween", "Halloween", "HALLOWEEN" usw.
function U.pickKey(tbl, key)
    if type(tbl) ~= "table" then return nil end
    if tbl[key] ~= nil then return key end
    local k2 = tostring(key)
    if tbl[k2] ~= nil then return k2 end
    local kn = U.norm(k2)
    for k,_ in pairs(tbl) do
        if U.norm(k) == kn then
            return k
        end
    end
    return nil
end

-- tief in Tabellen gehen
function U.deepGet(tbl, path)
    local cur = tbl
    for _,k in ipairs(path) do
        if type(cur) ~= "table" then return nil end
        local real = U.pickKey(cur, k)
        if not real then return nil end
        cur = cur[real]
    end
    return cur
end

-- [[Datei:...]]
function U.fileTag(file, opts)
    if U.isEmpty(file) then return "" end
    local parts = { "Datei:" .. file }
    if opts and opts.size  then table.insert(parts, opts.size)  end
    if opts and opts.param then table.insert(parts, opts.param) end
    return string.format("[[%s]]", table.concat(parts, "|"))
end

-- "1-3" → "1–3", "5-" → "5+"
function U.prettyRange(s)
    if not s or s == "" then return "" end
    s = tostring(s)
    if s:sub(-1) == "-" then
        return s:sub(1, -2) .. "+"
    end
    return s:gsub("%-","–")
end

return U