jfsiii / chromath

JavaScript color conversion and manipulation functions
https://jfsiii.github.io/chromath/
190 stars 13 forks source link

Hex value 1 is parsed as 255 #2

Open jfsiii opened 11 years ago

jfsiii commented 11 years ago

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:

joyously commented 10 years ago

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.

katylava commented 10 years ago

What's going on here?

> new Chromath('#970136').toString()
'#97FF36'
> new Chromath('#970236').toString()
'#970236'