Modul:Link utilities: Unterschied zwischen den Versionen
(+No globals) |
(Umbenennung) |
||
Zeile 1: | Zeile 1: | ||
-- documentation | -- documentation | ||
local | local LinkUtilities = { | ||
suite = ' | suite = 'Link utilities', | ||
serial = '2020-10- | serial = '2020-10-24', | ||
item = 65228027 | item = 65228027 | ||
} | } | ||
-- module variable | -- module variable | ||
local | local lu = {} | ||
-- module import | -- module import | ||
Zeile 14: | Zeile 14: | ||
-- split separate items like numbers | -- split separate items like numbers | ||
function | function lu.splitItems( s, delimiters, defaultDelimiter ) | ||
defaultDelimiter = defaultDelimiter or ',' | defaultDelimiter = defaultDelimiter or ',' | ||
Zeile 42: | Zeile 42: | ||
-- extract comment written in parentheses | -- extract comment written in parentheses | ||
-- remove spaces between value like phone numbers and comment | -- remove spaces between value like phone numbers and comment | ||
function | function lu.extractComment( s ) | ||
local comment = '' | local comment = '' | ||
if s:find( '(', 1, true ) then | if s:find( '(', 1, true ) then | ||
Zeile 56: | Zeile 56: | ||
-- add error category and hint | -- add error category and hint | ||
-- catPrefix contains opening squared brackets | -- catPrefix contains opening squared brackets | ||
function | function lu.errorInfo( catPrefix, aCat, aClass, styles ) | ||
aClass = aClass or 'error' | aClass = aClass or 'error' | ||
styles = styles or '' | styles = styles or '' | ||
Zeile 66: | Zeile 66: | ||
-- module administration | -- module administration | ||
function | function lu.getModuleInterface() | ||
return | return LinkUtilities | ||
end | end | ||
function | function lu.failsafe( version ) | ||
return fs._failsafe( version, | return fs._failsafe( version, LinkUtilities ) or '' | ||
end | end | ||
return | return lu |
Version vom 24. Oktober 2020, 14:03 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Link utilities/doc erstellt werden
-- documentation local LinkUtilities = { suite = 'Link utilities', serial = '2020-10-24', item = 65228027 } -- module variable local lu = {} -- module import require( 'Module:No globals' ) local fs = require( 'Module:Failsafe' ) -- split separate items like numbers function lu.splitItems( s, delimiters, defaultDelimiter ) defaultDelimiter = defaultDelimiter or ',' -- wrap delimiters with zero marks s = mw.ustring.gsub( s, defaultDelimiter, '\0' .. defaultDelimiter .. '\0' ); -- substitude delimiters for _, delimiter in ipairs( delimiters ) do s = mw.ustring.gsub( s, delimiter, '\0' .. delimiter .. '\0' ); -- remove zero marks from inside parentheses () s = s:gsub( '%b()', function( t ) return t:gsub( '%z', '' ) end ) -- replace delimeters by the default delimiter s = mw.ustring.gsub( s, '\0' .. delimiter .. '\0', '\0' .. defaultDelimiter .. '\0' ); end -- results to an array s = mw.text.split( s, '\0' .. defaultDelimiter .. '\0' ) for i = #s, 1, -1 do s[ i ] = mw.text.trim( s[ i ] ) if s[ i ] == '' then table.remove( s, i ) end end return s end -- extract comment written in parentheses -- remove spaces between value like phone numbers and comment function lu.extractComment( s ) local comment = '' if s:find( '(', 1, true ) then local t = s:gsub( '^.*(%b())$', '%1' ) if t ~= s then comment = t s = s:gsub( '[%s%c]*%b()$', '' ) end end return s, comment end -- add error category and hint -- catPrefix contains opening squared brackets function lu.errorInfo( catPrefix, aCat, aClass, styles ) aClass = aClass or 'error' styles = styles or '' return catPrefix .. aCat .. ']]' .. '<span class="' .. aClass .. '" title="' .. aCat .. '"' .. ( styles ~= '' and ( ' style="' .. styles .. '"' ) or '' ) .. '>' .. aCat .. '</span>' end -- module administration function lu.getModuleInterface() return LinkUtilities end function lu.failsafe( version ) return fs._failsafe( version, LinkUtilities ) or '' end return lu