Module:ProcessingFunctions: Difference between revisions

From Sekaipedia
Content added Content deleted
No edit summary
No edit summary
Line 16: Line 16:
function Functions.convertStringToArray(delimiter)
function Functions.convertStringToArray(delimiter)
return Functions.stringToArray(delimiter)
return Functions.stringToArray(delimiter)
end

function Functions.stringToBoolOrNil(str)
local Yesno = require('Module:Yesno')

return Yesno(val, nil)
end
end



Revision as of 23:20, 17 October 2022


This module contains several helper functions for Module:InfoboxBuilder and Module:DatatableBuilder templates.

Functions

stringToArray

ProcessingFunctions.stringToArray(delimiter)

Pass in the delimiter to be used when splitting the string into tokens. When called, this will return a function that uses the first parameter as the input string to split.

stringToBoolOrNil

ProcessingFunctions.stringToBoolOrNil

When called, this function will turn a string into a bool if the string is equivalent to a true value or false value (see Module:Yesno for such values). If the string is neither true nor false, then returns nil.

stringToNumber

ProcessingFunctions.stringToNumber

When called, this function will turn a string into a number or nil.


local Functions = {} 

function Functions.stringToArray(delimiter)
	return function(str)
		if str == nil then return nil end
		
		local array = mw.text.split(str, delimiter)
		for i=1, #array do
			array[i] = mw.text.trim(array[i])
		end
		
		return array
	end
end

function Functions.convertStringToArray(delimiter)
	return Functions.stringToArray(delimiter)
end

function Functions.stringToBoolOrNil(str)
	local Yesno = require('Module:Yesno')

	return Yesno(val, nil)
end

return Functions
Cookies help us deliver our services. By using our services, you agree to our use of cookies.