This package implements the WCAG 2.0 grading and score system.
This project was initially a mix of another two NodeJS projects ports relative-luminance and wcag-contrast to Golang both created by Tom MacWright.
Use go get.
go get github.com/afonsolopez/colorblind
Then import the validator package into your own code.
import "github.com/afonsolopez/colorblind"
# Convert hexadecimal color codes to RGB values
colorblind.HextoRGB("#DE605F") # [0 0 0 255]
# Get the contrast score based on a RGB value
colorblind.ScoreRGB([4]int{0, 0, 0, 255}, [4]int{255, 255, 255, 255}) # 21
# Get the contrast score based on a hexadecimal color code
colorblind.ScoreHex("#663399", "#FFF") # 21
# Get the WCAG 2.0 grading based on a contrast score
colorblind.Grading(21) # AAA
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.