-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_test.go
More file actions
40 lines (32 loc) · 668 Bytes
/
Copy pathexample_test.go
File metadata and controls
40 lines (32 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package csscolorparser_test
import (
"fmt"
"github.com/mazznoer/csscolorparser"
)
func Example() {
c, err := csscolorparser.Parse("rgb(100% 0% 0% / 50%)")
if err != nil {
panic(err)
}
fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A)
fmt.Println(c.RGBA255())
fmt.Println(c.HexString())
fmt.Println(c.RGBString())
// Output:
// R:1.000, G:0.000, B:0.000, A:0.500
// 255 0 0 128
// #ff000080
// rgb(255 0 0 / 50%)
}
func ExampleColor_Name() {
c, err := csscolorparser.Parse("#ffd700")
if err != nil {
panic(err)
}
fmt.Println(c.RGBString())
name, _ := c.Name()
fmt.Println(name)
// Output:
// rgb(255 215 0)
// gold
}