Modul:Link utilities: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
(lu.errorInfo removed)
(moduleInterface)
Zeile 2: Zeile 2:
local LinkUtilities = {
local LinkUtilities = {
suite  = 'Link utilities',
suite  = 'Link utilities',
serial = '2021-04-07',
serial = '2021-04-08',
item  = 65228027
item  = 65228027
}
}
-- module variable
local lu = {}


-- module import
-- module import
require( 'Module:No globals' )
require( 'Module:No globals' )
local fs = require( 'Module:Failsafe' )
 
-- module variable and administration
local lu = {
moduleInterface = LinkUtilities
}


-- split separate items like numbers
-- split separate items like numbers
Zeile 52: Zeile 53:
end
end
return s, comment
return s, comment
end
-- module administration
function lu.getModuleInterface()
return LinkUtilities
end
function lu.failsafe( version )
return fs._failsafe( version, LinkUtilities ) or ''
end
end


return lu
return lu

Version vom 8. April 2021, 07:53 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Link utilities/doc erstellt werden

-- documentation
local LinkUtilities = {
	suite  = 'Link utilities',
	serial = '2021-04-08',
	item   = 65228027
}

-- module import
require( 'Module:No globals' )

-- module variable and administration
local lu = {
	moduleInterface = LinkUtilities
}

-- 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%1\0' );

	-- substitude delimiters
	for _, delimiter in ipairs( delimiters ) do
		s = mw.ustring.gsub( s, delimiter, '\0%1\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

return lu