hexcolor

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 2 Imported by: 5

README

func Parse(s string) color.NRGBA

Hex color string will be silently parsed as color.NRGBA

// color.NRGBA{ 0xab, 0xc1, 0x23, 0xff }
hexcolor.Parse("#AbC123") 
hexcolor.Parse("AbC123") 

// color.NRGBA{ 0xaa, 0xbb, 0xcc, 0xff }
hexcolor.Parse("#aBc")
hexcolor.Parse("abC") 

// color.NRGBA{ 0xab, 0xc1, 0x23, 0xff }
hexcolor.Parse("#abc123FF")
hexcolor.Parse("Abc123FF") 

// invalid format will return hexcolor.Default, which is magenta
// color.NRGBA{ 0xff, 0x00, 0xff, 0xff }
hexcolor.Parse("invalid format")

Note: No errors will be returned, whether the input is valid or not. Invalid inputs will return the default color (Default color.NRGBA{0x00, 0x00, 0x00, 0x00}), but you should never expect this.

func SafeParse(s string) color.NRGBA

Parse() is fast, but for some invalid colors, Parse() may return unexpected result.

SafeParse() will check if input is valid first.

hexcolor.Parse("#12345X")     // -> not sure
hexcolor.SafeParse("#12345X") // -> Default color.NRGBA{}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Default = color.NRGBA{}
)

Functions

func IsValid added in v1.3.0

func IsValid(s string) bool

func Parse

func Parse(s string) color.NRGBA

func SafeParse added in v1.3.0

func SafeParse(s string) color.NRGBA

func ToString added in v1.3.0

func ToString(clr color.NRGBA) string

Types

type Color added in v1.2.0

type Color struct {
	color.NRGBA
}

func New added in v1.2.0

func New(s string) Color

func (Color) MarshalJSON added in v1.3.0

func (clr Color) MarshalJSON() (r []byte, err error)

func (Color) String added in v1.3.0

func (clr Color) String() string

func (*Color) UnmarshalJSON added in v1.3.0

func (clr *Color) UnmarshalJSON(data []byte) error

- "" - "#123" - "#1234" - "#123456" - "#123456FF" - invalid values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳