Color type or object

I see a lot of repetitive code and faulty assumptions regarding colors, which are handled often within ES/JS, because of its close association with CSS. For many coders, a color apparently is always a 24-bit sRGB value expressed as a 6-digit hexadecimal number (or 3-tuple) preceded by a hash sign, e.g. #ABCDEF or #f00ba7.

I believe this could be improved a lot if there was a Color "datatype" built into ES-262, similar to Number or Date, or at least a global object Color that provided common functions like Math does.

1 Like

This sounds like something the CSSOM could solve, but it's outside TC39's authority. You might try the CSS Working Group?

In its current state at least, CSS OM does not seem to address anything near what I had in mind. It's just about parsing and serialization, not about manipulation, conversion etc.

See the https://www.w3.org/TR/css-typed-om-1/, which is primarily about things like CSS.px(1) and other value types. I mistakenly thought this was part of CSSOM, but it's a separate proposal on top of it.