bgrins / TinyColor

Fast, small color manipulation and conversion for JavaScript
https://bgrins.github.io/TinyColor/
MIT License
5.05k stars 438 forks source link

toString is returning rgba value but toHexString is returning a different value #207

Open ivikash opened 5 years ago

ivikash commented 5 years ago

Hi,

.toHexString() is not returning the expected value. Attaching a runkit.

https://runkit.com/embed/dhv39902sm0k

var tinycolor2 = require("tinycolor2")
const sheetsDefault = "#00857A"
const color =
console.log(tinycolor2(sheetsDefault).setAlpha(0.5).toString())
console.log(tinycolor2(sheetsDefault).setAlpha(0.5).toHexString())
davegomez commented 3 years ago

It seems the library doesn't have support for the Alpha channel in HEX values @ivikash. But in theory, is returning the correct value.

davegomez commented 3 years ago

@ivikash just noticed that you are not using the toHex8String method.

var tinycolor2 = require("tinycolor2")
const sheetsDefault = "#00857A"
console.log(tinycolor2(sheetsDefault).setAlpha(0.5).toString()).       // "rgba(0, 133, 122, 0.5)" 
console.log(tinycolor2(sheetsDefault).setAlpha(0.5).toHex8String()).   // "#00857a80"