colors

package module
v0.0.0-...-eee66fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2016 License: MIT Imports: 2 Imported by: 0

README

Travis CI Software License GoDoc Coverage Status

CSS colors parser in Golang

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.

Head over to the Go documentation to see available methods and examples.

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

func IsReserved(str string) (reserved bool, hexadecimalValue string)

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

func StringToHexColor(str string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL