You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, I have searched the closed issues and read what's there.
Problem: Color.prototype.hex() breaks the principle of least surprise.
The behavior is never documented (not even in a test).
It's inconsistent with the existing behavior of .rgb().toString(), .hsl.toString() et. al.
All those methods intelligently switch between rgb and rgba, hsl and hsla etc. when appropriate.
(Note: Currently the only way to force a "rgb()" string is to first run .alpha(1))
I see a few ways to mend this, and I'm willing to make a PR if you're willing to accept any of them:
Documentation:
Add clearly worded note in the README warning of this behavior.
Add a test that tests for this behavior.
Add a lossless .toHex() method that switches between .hex() and .hexa()
Add tests for the new method.
Make .hex() more similar to .rgb().string():
Change .hex() to automatically emit the alpha channel when valpha < 1.
Update the tests for .hex()
Either deprecate .hexa() or add a new lossy .hex6() method.
Methods 1 and 2 easily go together.
Method 3 could qualify as a non-breaking change, as the current behaviour has never been tested or documented.
The text was updated successfully, but these errors were encountered:
Yes, I have searched the closed issues and read what's there.
Problem:
Color.prototype.hex()
breaks the principle of least surprise.The behavior is never documented (not even in a test).
It's inconsistent with the existing behavior of
.rgb().toString()
,.hsl.toString()
et. al.All those methods intelligently switch between
rgb
andrgba
,hsl
andhsla
etc. when appropriate.(Note: Currently the only way to force a "rgb()" string is to first run
.alpha(1)
)I see a few ways to mend this, and I'm willing to make a PR if you're willing to accept any of them:
.toHex()
method that switches between.hex()
and.hexa()
.hex()
more similar to.rgb().string()
:.hex()
to automatically emit the alpha channel whenvalpha < 1
..hexa()
or add a new lossy.hex6()
method.Methods 1 and 2 easily go together.
Method 3 could qualify as a non-breaking change, as the current behaviour has never been tested or documented.
The text was updated successfully, but these errors were encountered: