omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.67k stars 49 forks source link

Clamp NaN values #30

Closed subzey closed 3 years ago

subzey commented 3 years ago

As I can see, Colord is generally very tolerable to the garbage input. But the NaN values (and ones that are coerced to NaN) are not handled:

colord({r: 'foo', g: 'bar', b: 'baz'}).toRgb()
{ r: NaN, g: NaN, b: NaN, a: 1 }
colord({r: 'foo', g: 'bar', b: 'baz'}).toHex()
'#NaNNaNNaN'

This is a proposed fix: To treat NaN values as a finite lower bound in clamp()

omgovich commented 3 years ago

Smart! I owe you a beer 🍻