TinyColor
TinyColor copied to clipboard
Added .toRgbaString() method to tinycolor.js
needed a method to convert to rgba(....) string regardless whether alpha is 1 or not.
I'm not sure about exposing a new method for this, since we would then need to also expose toHslaString, toHsvaString, etc for consistency. I think maybe we could add an option to pass "rgba" to the standard toString() method and have that force alpha. It may be best to have a private function called toRgbString that takes in r, g, b, a, and an extra param called forceAlpha that does what the exposed method currently does. Then have the exposed toRgbString just pass the properties along, while this new mode (toString("rgba")) would pass in (r, g, b, a, true). Does this make sense? Something like this, maybe:
function toRgbString(r, b, b, a, forceAlpha) {
return (a === 1 && !forceAlpha) ?
"rgb(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ")" :
"rgba(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ", " + roundA + ")";
}