Difference between pages "Module:Util" and "Card Tips:Swarm of Centipedes"

From Yugipedia
(Difference between pages)
Jump to: navigation, search
(Add some more helper functions.)
 
(Created page with "{{Navigation}} * This card can be searched by "Insect Imitation", "Cocoon of Ultra Evolution", "Digital Bug Centibit", "Digital Bug LEDybug", "...")
 
Line 1: Line 1:
-- <pre>
+
{{Navigation}}
-- @name Util
 
-- @description Holds commonly used simple functions.
 
-- @author [[User:Becasita]]
 
-- @contact [[User talk:Becasita]]
 
  
-------------------
+
* This card can be [[Searcher|searched]] by "[[Insect Imitation]]", "[[Cocoon of Ultra Evolution]]", "[[Digital Bug Centibit]]", "[[Digital Bug LEDybug]]", "[[Mystic Potato]]", "[[Verdant Sanctuary]]", "[[Kittytail, Mystical Beast of the Forest]]", "[[Howling Insect]]", "[[Gokipon]]", "[[Danipon]]", "[[Ninjitsu Art of Transformation]]", "[[Dharc the Dark Charmer, Gloomy]]", "[[Mystic Tomato]]", "[[Chaos Zone]]", "[[Sphere of Chaos]]", "[[Serpentine Princess]]", "[[Battle Royal Mode - Joining]]", "[[Vampire Dragon]]", "[[Rescue Ferret]]", "[[Umbramirage the Elemental Lord]]", "[[Sangan]]", "[[Witch of the Black Forest]]", and other [[List of generic searchers#Monsters|generic searchers]].
-- Export variable:
 
-------------------
 
local U = {};
 
 
 
-------------
 
-- Functions:
 
-------------
 
-- mw functions:
 
local mwTextSplit = mw.text.split;
 
local mwTextTrim = mw.text.trim;
 
 
 
-- @name bold
 
-- @description Renders bold wikitext markup.
 
function U.bold( s )
 
return ("'''%s'''"):format( s )
 
end
 
 
 
-- @name italics
 
-- @description Renders italics wikitext markup.
 
function U.italics( s )
 
return ("''%s''"):format( s )
 
end
 
 
 
-- @name trim
 
-- @description Trims white space from front and tail of string. Returns nil if only whitespace.
 
-- @see [[mw:Extension:Scribunto/Lua reference manual#mw.text.trim]]
 
function U.trim( s )
 
if s and not s:match( '^%s*$' ) then
 
return mwTextTrim( s );
 
end
 
end
 
 
 
-- @name count
 
-- @description Counts the number of elements in a table.
 
function U.count( t )
 
local counter = 0;
 
for key, value in pairs( t ) do
 
counter = counter + 1;
 
end
 
return counter;
 
end
 
 
 
-- @name link
 
-- @description Creates a wikitext link.
 
function U.link( page, label )
 
return ('[[%s|%s]]'):format(
 
page:gsub( '#', '' ),
 
label or mwTextSplit( page, '%s*%(' )[1]
 
);
 
end
 
 
 
-- @name getDab
 
-- @description Gets the dab text of a title, if it has dab (fails for two dabs).
 
function U.getDab( title )
 
return title:match( '%((.*)%)%s*$' ) or '';
 
end
 
 
 
-- @name isSomething
 
-- @description Meta-function for type checkers.
 
local function isSomething( toCompare, compareTo )
 
return type( toCompare ) == type( compareTo );
 
end
 
 
 
-- @name isBoolean
 
function U.isBoolean( v )
 
return isSomething( v, true );
 
end
 
 
 
-- @name isFunction
 
function U.isFunction( v )
 
return isSomething( v, function() end );
 
end
 
 
 
-- @name isNil
 
function U.isNil( v )
 
return isSomething( v, nil );
 
end
 
 
 
-- @name isNumber
 
function U.isNumber( v )
 
return isSomething( v, 1 );
 
end
 
 
 
-- @name isString
 
function U.isString( v )
 
return isSomething( v, '' );
 
end
 
 
 
-- @name isEmpty
 
function U.isEmpty( s )
 
return mwTextTrim( s ) == '';
 
end
 
 
 
-- @name isTable
 
function U.isTable( v )
 
return isSomething( v, {} );
 
end
 
 
 
--[[function U.processArgs( frame, ... )
 
return
 
end]]
 
-- @name getArgs
 
-- @description Parses arguments.
 
-- @see [[Module:Arguments]]
 
--[[local getArgs;
 
function U.getArgs( ... )
 
getArgs = getArgs or require( 'Module:Arguments' ).getArgs;
 
return getArgs( ... );
 
end]]
 
 
 
-- @name getName
 
-- @description Gets the localized name of a card, set or character.
 
-- @see [[Module:Name]]
 
--[[local getName;
 
function U.getName( ... )
 
getName = getName or require( 'Module:Name' ).main;
 
return getName( ... );
 
end]]
 
 
 
-- @name newInfoObject
 
-- @description
 
-- @see [[Module:Info class]]
 
local InfoClass;
 
function U.newInfoObject( title )
 
InfoClass = InfoClass or require( 'Module:Info class' );
 
return InfoClass.new( title );
 
end
 
 
 
----------
 
-- Return:
 
----------
 
return U;
 
-- </pre>
 

Latest revision as of 23:03, 26 January 2024