Documentation ¶
Overview ¶
This package lets you transform a string to its hexadecimal representation according to the HTML5 specification: http://www.w3.org/TR/2011/WD-html5-20110525/common-microsyntaxes.html#colors
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsReserved ¶
Check if a color string is reserved.
A string is "reserved" if it looks like an hexadecimal color ("#ff0099", "ff0099", " #ff0099 "...) OR is a reserved color keyword according to http://www.w3.org/TR/css3-color/#svg-color ("red", " RED ", "transparent"...)
If the string is reserved, return also its hexadecimal format value. An example of the hexadecimal format for the output is the following: #f3f3f3
Example (HexadecimalColor) ¶
reserved, value := IsReserved(" ffFFff ") fmt.Fprintf(os.Stdout, "reserved: %t, value: %s", reserved, value)
Output: reserved: true, value: #ffffff
Example (NamedColor) ¶
reserved, value := IsReserved("red") fmt.Fprintf(os.Stdout, "reserved: %t, value: %s", reserved, value)
Output: reserved: true, value: #ff0000
Example (UnknowWord) ¶
reserved, value := IsReserved("foo") fmt.Fprintf(os.Stdout, "reserved: %t, value: %s", reserved, value)
Output: reserved: false, value:
func StringToHexColor ¶
Transform a string to its hexadecimal representation according to the HTML5 specification: http://www.w3.org/TR/2011/WD-html5-20110525/common-microsyntaxes.html#colors
An example of the hexadecimal format for the output is the following: #f3f3f3
Example (HexadecimalString) ¶
fmt.Println(StringToHexColor("FFFFFF"))
Output: #ffffff
Example (NamedColor) ¶
fmt.Println(StringToHexColor("white"))
Output: #ffffff
Example (OtherHexadecimalString) ¶
fmt.Println(StringToHexColor("#FFFFFF"))
Output: #ffffff
Example (OtherNamedColor) ¶
fmt.Println(StringToHexColor("limegreen"))
Output: #32cd32
Example (RandomString) ¶
fmt.Println(StringToHexColor("chucknorris"))
Output: #c00000
Types ¶
This section is empty.