Module:Colors

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

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

Code

-- for color handling in lua modules
--
-- note: for many calls / invokes to this it is more efficient to copy+paste all
--       of this (except return line) into your module, instead of using
--         require( 'Module:Colors' )
cl = {
	d = function( s ) return mw.loadData( 'Module:Colors/data' )[s] end,
	r = function( s ) return cl.d(s)[1] end,
	g = function( s ) return cl.d(s)[2] end,
	b = function( s ) return cl.d(s)[3] end,
	isColorName = function( s ) return cl.d(s) ~= nil end,
	getHex      = function( s ) if not (s:sub( 1, 1 ) == '#')
		then if cl.isColorName(s)
			then s = string.format( '#%x%x%x',cl.d(s)[1],cl.d(s)[2],cl.d(s)[3] )
			else s = nil
			end
		end
		return s
	end
}

return cl