Difference between revisions of "Module:Common"
Jump to navigation
Jump to search
m (3 revisions imported: Importing from localhost) |
|||
| Line 12: | Line 12: | ||
function com.trim(object) | function com.trim(object) | ||
--Use of while instead of if incase multiple whitespaces are present. | --Use of while instead of if incase multiple whitespaces are present. | ||
while string.sub(object, 1, 1) == ' ' do | if com.exists(object) then | ||
while string.sub(object, 1, 1) == ' ' do | |||
object = string.sub(object, 2) | |||
end | |||
while string.sub(object, string.len(object)) == ' ' do | |||
object = string.sub(object, 1, string.len(object) - 1) | |||
end | |||
end | end | ||
Revision as of 16:15, 23 December 2021
Additional functions that are common to other modules. Although they could be called into templates the overhead call into lua would generally greater than using a built in mediawiki parser function where one exists.
When calling in to another module, use local com = require( "Module:Common"). This will ensure consistency between modules.
--[[
Additional functions that are common to other modules. Although they could
be called into templates the overhead call into lua would generally greater
than using a built in mediawiki parser function where one exists.
When calling in to another module, use 'local com = require( "Module:Common")'
This will ensure consistency between modules.
]]
local com = {}
function com.trim(object)
--Use of while instead of if incase multiple whitespaces are present.
if com.exists(object) then
while string.sub(object, 1, 1) == ' ' do
object = string.sub(object, 2)
end
while string.sub(object, string.len(object)) == ' ' do
object = string.sub(object, 1, string.len(object) - 1)
end
end
return object
end
function com.exists(object)
if object == nil or object == '' then
return false
else
return true
end
end
return com