/colors

Primary LanguageGoMIT LicenseMIT

colors

colors is a Go package to parse color strings. Provides a type to use easily with cobra / pflag or other command line packages.

Using | Example | About

Unit Tests Go Reference Discord Discussion

Using

Install in the usual Go fashion:

$ go get -u github.com/kenshaw/colors@latest

Example

package colors_test

import (
	"fmt"
	"log"

	"github.com/kenshaw/colors"
)

func Example() {
	for _, s := range []string{
		"red",
		"rgba(192, 192, 192, 255)",
		"navajo white",
		"#ffeeaa",
		"rgb(106,90,205)",
		"rgb(0,255,0)",
		"hex(f,e,a)",
		"#fff",
		"rgba(26,33,80,22)",
		"#cdcdcd80",
		"#cdcdcdff",
		"hex(0,0,0,0)",
	} {
		c, err := colors.Parse(s)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(c)
	}
	// Output:
	// red
	// silver
	// navajowhite
	// #fea
	// slateblue
	// lime
	// #0f0e0a
	// white
	// #1a215016
	// #cdcdcd80
	// #cdcdcd
	// transparent
}

About

Built to support the fv, iv, and usql applications.