Modul:Funktioner: Skillnad mellan sidversioner
mIngen redigeringssammanfattning |
Ingen redigeringssammanfattning |
||
| Rad 16: | Rad 16: | ||
end | end | ||
function p. | function p.isEmpty(s) | ||
local result = false | local result = false | ||
if type(s) == "nil" then | if type(s) == "nil" then | ||
| Rad 30: | Rad 30: | ||
end | end | ||
return result | return result | ||
end | |||
function p.categoryLink( category, sortkey, label ) | |||
if not p.isEmpty( label ) then | |||
return p.linkToCategory( category, label ) .. p.category( category, sortkey ) | |||
else | |||
return p.category( category, sortkey ) | |||
end | |||
end | |||
function p.category( category, sortkey ) | |||
if sortkey == nil then | |||
sortkey = '' else sortkey = '|' .. sortkey | |||
end | |||
return string.format('[['..'Kategori:%s%s]]', category, sortkey) | |||
end | |||
function p.linkToCategory( category, label ) | |||
return string.format('[[:'..'Kategori:%s|%s]]', category, label or 'Kategori:' .. category ) | |||
end | end | ||
return p | return p | ||
Versionen från 30 oktober 2023 kl. 00.21
Dokumentationen för denna modul kan skapas på Modul:Funktioner/dok
Skriptfel: Luafel: Internt fel: Tolken har avslutats med signalen "11".
local p = {}
function p.explode( sep, text )
local sep, fields = sep or "::", {}
local pattern = string.format("([^%s]+)", sep)
text:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
function p.trim(s)
if type(s) == "string" then
return (s:gsub("^%s*(.-)%s*$", "%1"))
else
return false
end
end
function p.isEmpty(s)
local result = false
if type(s) == "nil" then
result = true
elseif type(s) == "string" then
if s == "" then
result = true
end
elseif type(s) == "table" then
if next(s) == nil then
result = true
end
end
return result
end
function p.categoryLink( category, sortkey, label )
if not p.isEmpty( label ) then
return p.linkToCategory( category, label ) .. p.category( category, sortkey )
else
return p.category( category, sortkey )
end
end
function p.category( category, sortkey )
if sortkey == nil then
sortkey = '' else sortkey = '|' .. sortkey
end
return string.format('[['..'Kategori:%s%s]]', category, sortkey)
end
function p.linkToCategory( category, label )
return string.format('[[:'..'Kategori:%s|%s]]', category, label or 'Kategori:' .. category )
end
return p