ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:Utils: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Formatting)
m (Fromatting)
Line 2: Line 2:


-- Trims and parses the args into a table, then returns the table
-- Trims and parses the args into a table, then returns the table
function p.normaliseArgs(frame)
function p.normaliseArgs( frame )
local origArgs = frame:getParent().args
local origArgs = frame:getParent().args
local args = {}
local args = {}
for k, v in pairs(origArgs) do
for k, v in pairs( origArgs ) do
v = mw.text.trim(tostring(v))
v = mw.text.trim( tostring( v ) )
if v ~= '' then
if v ~= '' then
args[k] = v
args[k] = v

Revision as of 17:44, 20 February 2021

This module provides utility functions used from other modules.

Usage

Add the following line of code at the top of your file.

local Utils = require("Module:Utils")

-- You may then call functions from this module in your script. For example:
local tableLength = Utils.tableLen(myTable)

local p = {}

-- Trims and parses the args into a table, then returns the table
function p.normaliseArgs( frame )
	local origArgs = frame:getParent().args
	local args = {}
	
	for k, v in pairs( origArgs ) do
		v = mw.text.trim( tostring( v ) )
		if v ~= '' then
			args[k] = v
		end
	end
	
	return args
end

return p