Modul:SK/Helper
< Modul:SK
Script error: The function "nonexistent" does not exist.
local h = {}
-- Pomoćna funkcija za čišćenje unosa
local function clean(val)
if type(val) == 'table' then val = val[1] end -- OVO rješava "got table" grešku
if type(val) == 'string' then val = val:gsub('%s+', '') end
return tonumber(val)
end
-- Nova funkcija za obradu naziva/teksta
function h.text(t)
if type(t) == 'table' then t = t[1] or t.v or "" end -- Izvlači string iz tablice
return tostring(t)
end
-- Format broja s tisućicama (razmak)
function h.num(n)
local num = clean(n)
if not num then return "" end
local s = tostring(math.floor(num))
local i, j, minus, int, fraction = s:find('^([-+]?)(%d+)([.]?%d*)$')
int = int:reverse():gsub('(%d%d%d)', '%1 '):reverse():gsub('^ ', '')
return minus .. int .. fraction
end
-- Format površine
function h.area(a)
local num = clean(a)
if not num then return "" end
return string.format("%.2f", num):gsub("%.", ",") .. " km²"
end
-- Format gustoće
function h.density(d)
local num = clean(d)
if not num then return "" end
return string.format("%.1f", num):gsub("%.", ",") .. " st./km²"
end
-- Format stanovništva
function h.pop(p)
return h.num(p)
end
return h