Module:Utils: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [checked revision] |
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
function p.checkImage(name) | function p.checkImage(name) | ||
local icon = name .. '_Icon.png' | local icon = name:gsub('%s+', '') .. '_Icon.png' | ||
if mw.title.makeTitle('File', name).file.exists then | if mw.title.makeTitle('File', name).file.exists then | ||
return name | return name |
Revision as of 11:21, 24 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
function p.checkImage(name)
local icon = name:gsub('%s+', '') .. '_Icon.png'
if mw.title.makeTitle('File', name).file.exists then
return name
else
return 'NoImage.png'
end
end
return p