webcolors

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

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

Go to latest
Published: Aug 21, 2015 License: MIT Imports: 6 Imported by: 8

README

go-webcolors

A library for working with color names and color value formats defined by the HTML and CSS specifications for use in documents on the Web.

go-webcolors is available on the Godoc

This library is originally available in Python by James Bennett, PyPI and Bitbucket. go-webcolors have been ported from Python to Go with all the functions available. Contributions in the form of patches, issue reports, bug reports and pull requests are welcome.

Support is included for the following formats:

  • Specification-defined color names
  • Six-digit hexadecimal
  • Three-digit hexadecimal
  • Integer rgb triplet
  • Percentage rgb triplet

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CSS21HexToNames = ReverseMap(CSS21NamesToHex)
View Source
var CSS21NamesToHex = HTML4NamesToHex
View Source
var CSS2HexToNames = HTML4HexToNames
View Source
var CSS2NamesToHex = HTML4NamesToHex
View Source
var CSS3HexToNames = ReverseMap(CSS3NamesToHex)
View Source
var CSS3NamesToHex = map[string]string{}/* 147 elements not displayed */
View Source
var HTML4HexToNames = ReverseMap(HTML4NamesToHex)
View Source
var HTML4NamesToHex = map[string]string{
	"aqua":    "#00ffff",
	"black":   "#000000",
	"blue":    "#0000ff",
	"fuchsia": "#ff00ff",
	"green":   "#008000",
	"grey":    "#808080",
	"lime":    "#00ff00",
	"maroon":  "#800000",
	"navy":    "#000080",
	"olive":   "#808000",
	"purple":  "#800080",
	"red":     "#ff0000",
	"silver":  "#c0c0c0",
	"teal":    "#008080",
	"white":   "#ffffff",
	"yellow":  "#ffff00",
	"orange":  "#ffa500",
}
View Source
var HexColorRegex = regexp.MustCompile(`^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$`)
View Source
var SupportedSpecifications = []string{"html4", "css2", "css21", "css3"}

Functions

func ByteToInt

func ByteToInt(Input []byte) int

func Contains

func Contains(s []string, e string) bool

func HexToName

func HexToName(HexValue string, Spec string) string

Convert a hexadecimal color value to its corresponding normalized color name, if any such name exists

func HexToRGB

func HexToRGB(HexValue string) []int

Convert a hexadecimal color value to a 3-tuple of integers suitable for use in an rgb triplet specifying that color

func HexToRGBPercent

func HexToRGBPercent(HexValue string) []string

Convert a hexadecimal color value to a 3-tuple of percentages suitable for use in an rgb triplet representing that color

func NameToRGB

func NameToRGB(Name string, Spec string) []int

Convert a color name to a 3-tuple of integers suitable for use in an rgb triplet specifying that color

func NameToRGBPercent

func NameToRGBPercent(Name string, Spec string) []string

Convert a color name to a 3-tuple of percentages suitable for use in an rgb triplet specifying that color

func NamesToHex

func NamesToHex(Name string, Spec string) string

Convert a color name to a normalized hexadecimal color value

func NormalizeHex

func NormalizeHex(HexValue string) string

Normalize a hexadecimal color value

func NormalizeIntegerRGB

func NormalizeIntegerRGB(Value int) int

Normalize value for use in an integer rgb triplet

func NormalizeIntegerTriplet

func NormalizeIntegerTriplet(RGBTriplet []int) []int

Normalize an integer rgb triplet so that all values are within the range 0-255 inclusive.

func NormalizePercentRGB

func NormalizePercentRGB(Value string) string

Normalize value for use in a percentage rgb triplet

func NormalizePercentTriplet

func NormalizePercentTriplet(RGBTriplet []string) []string

Normalize a percentage rgb triplet to that all values are within the range 0%-100% inclusive.

func PercentToInteger

func PercentToInteger(Percent string) int

Internal helper for converting a percentage value to an integer between 0 and 255 inclusive

func RGBPercentToHex

func RGBPercentToHex(RGBPercentTriplet []string) string

Convert a 3-tuple of percentages, suitable for use in an rgb color triplet, to a normalized hexadecimal color value for that color

func RGBPercentToName

func RGBPercentToName(RGBPercentTriplet []string, Spec string) string

Convert a 3-tuple of percentages, suitable for use in an rgb color triplet, to its corresponding normalized color name, if any such name exists

func RGBPercentToRGB

func RGBPercentToRGB(RGBPercentTriplet []string) []int

Convert a 3-tuple of percentages, suitable for use in an rgb color triplet, to a 3-tuple of integers suitable for use in representing that color

func RGBToHex

func RGBToHex(RGBTriplet []int) string

Convert a 3-tuple of integers, suitable for use in an rgb color triplet, to a normalized hexadecimal value for that color

func RGBToName

func RGBToName(RGBTriplet []int, Spec string) string

Convert a 3-tuple of integers, suitable for use in an rgb color triplet, to its corresponding normalized color name, if any such name exists

func RGBToRGBPercent

func RGBToRGBPercent(RGBTriplet []int) []string

Convert a 3-tuple of integers, suitable for use in an rgb color triplet, to a 3-tuple of percentages suitable for use in representing that color

func ReverseMap

func ReverseMap(m map[string]string) map[string]string

Types

This section is empty.

Jump to

Keyboard shortcuts

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