chromath
chromath copied to clipboard
Hex value 1 is parsed as 255
The constructor allows float values for percentages (e.g, 0.8 == 204 == CC) and integers (204 == CC).
As a result, the value 1 is being interpreted as 100% or 255. This is almost certainly not what the developer wanted.
Ideas:
- require 1.0, not 1, for 100%
- ignore 1 as a percentage value altogether
It's not just the hex values. The bug is that the scaled and scaled01 functions check for the values to be greater than 1 before scaling. But a 1 is valid both before and after scaling.
My fix is to eliminate the scale functions and move the scaling into the parsing functions, which is the only place you know whether it needs scaling or not. (but this may only work for my usage, which is for CSS values) On a related note, the rgb parser allows a mix of percentage and integer values, which is not valid in CSS. And of course, hsv is not valid in CSS.
What's going on here?
> new Chromath('#970136').toString()
'#97FF36'
> new Chromath('#970236').toString()
'#970236'