Module:Util

From Workers & Resources: Soviet Republic Official Wiki
Revision as of 23:41, 15 June 2022 by workers-resources-fandom>Abominação (Created page with "local util = {} --This module was taken from Nukapedia. All credits go to said wiki. function util.corename(frame, title) if frame ~= nil and util.exists(frame.args[1]) then result = mw.ustring.gsub(frame.args[1], '%s%(.*', '') else if util.exists(title) then result = mw.ustring.gsub(title, '%s%(.*', '') else result = mw.ustring.gsub(mw.title.getCurrentTitle().subpageText, '%s%(.*', '') end end return result end function u...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Util/doc

local util = {}
--[[
	This module was taken from Nukapedia. All credits go to said wiki.
]]

function util.corename(frame, title)
	if frame ~= nil and util.exists(frame.args[1]) then
    	result = mw.ustring.gsub(frame.args[1], '%s%(.*', '')
    else
    	if util.exists(title) then
    		result =  mw.ustring.gsub(title, '%s%(.*', '')
    	else
    		result = mw.ustring.gsub(mw.title.getCurrentTitle().subpageText, '%s%(.*', '')
    	end
	end
	return result
end

function util.exists(object, child)
	if object ~= nil and object ~= '' then
		if child ~= nil then
			if object[child] ~= nil and object[child] ~= '' then
				return true
			else
				return false
			end
		else
			return true
		end
	else
		return false
	end
end

function util.trim(s)
   return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end

function util.default(data, default)
		if util.exists(data) then
		return data
	else
		return default
	end
end

return util