Module:Layout/Production/Library/Text

Uit Wikibooks
 Deze module is nog in ontwikkeling (versie 0.0) en wordt getest.

De Module:Layout is bedoeld om snel, consistent en uitgebreid een pagina op te maken.
Er is een op de module afgestemde handleiding over deze onderwijswiki beschikbaar.

De module wordt geïnitialiseerd met de configuratie in Module:Layout/Production/Configuration.

Controleer op scriptfouten of opmaak notificaties.




local text = {};

function text.capitalize_first( str )
	if not text.valid( str ) then return ""; end
    str = str:lower();
    return (str:gsub("^%l", string.upper))
end
	
function text.split( str, trim )
	if not text.valid( str ) then return {}; end
    local result = {};
    for substring in string.gmatch( str, "[^,]+" ) do
    	if trim then substring = text.trim( substring ); end
        table.insert( result, substring );
    end
    if str:sub(1,1) == "," then
        table.insert( result, 1, "" );
    end
    if str:sub(-1) == "," then
        table.insert( result, "" );
    end
    return result;
end

function text.trim( str )
	if not text.valid( str ) then return ""; end
    return mw.text.trim( str, "\t\r\n\f ");
end

function text.valid( str )
    return ( str ~= nil and type( str ) == 'string' and str ~= "" and not str:match('^%s*$') );
end

return text;
Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.