Replies: 9 comments 3 replies
-
I don't think they should be treated differently (I'm not sure if others would disagree though). A bad input value, I think, should throw an error. I don't know how well the parameters of a color function are validated. |
Beta Was this translation helpful? Give feedback.
-
I have updated the codepen to illustrate the same behavior with colors instances created using this syntax: color = new Color("spaceId", [0, 0, 0]); For real-world reference: I stumbled on this different treatment because this comment in an issue in the elements repo here triggered the idea to test it. So it might be relevant in that situation. My code is definitely affected, though it's only a few extra lines. I just added an additional check for this situation where I already have a |
Beta Was this translation helpful? Give feedback.
-
To clarify:
So there is a difference between the "ugly" and the "bad", though both result in undisplayable colors. |
Beta Was this translation helpful? Give feedback.
-
fyi - this is my additional check for if (color.display().includes("NaN")) Otherwise I'm not sure which of these might be correct: if (color.coords.some(v => isNaN(v)); or if (color.coords.some(v => Number.isNaN(Number(v))); or maybe |
Beta Was this translation helpful? Give feedback.
-
@facelessuser - I didn't see your last comment until I had posted mine 2 minutes later. I think we're on the same page. What you say is the reason why I'm using
In my case I'm validating the text in an |
Beta Was this translation helpful? Give feedback.
-
...and isn't supplying an invalid color space id to the color space id interface a user error too? Why would that be different than an invalid number? I understand the mechanics of "getting stopped in its tracks". |
Beta Was this translation helpful? Give feedback.
-
fyi - Color.js accepts a lot of strings with non-numeric characters for coordinates and successfully converts them to numbers. For example, In my small set of test cases it is more restrictive than But the parentheses are weird. Not complaining, just observing. |
Beta Was this translation helpful? Give feedback.
-
Unitless numbers are valid in CSS now too, for all color spaces. The latter Id consider a bug though. |
Beta Was this translation helpful? Give feedback.
-
@LeaVerou - I've submitted issue #614. What about the original question here? Is there any sense in submitting an enhancement request to throw an error instead of instantiating an undisplayable |
Beta Was this translation helpful? Give feedback.
-
https://codepen.io/sidewayss/pen/ogvjYrd
I'm looking for clarification on the different results here. In that codepen you'll see 3 Color instances created based on versions of the same serialized color string. The first one is "good", so no issue there.
The "ugly" color has a bogus coordinate:
"foo"
. The Color instance gets created without throwing an error. It is obviously not a displayable color, sodisplay()
is filled withNaN
.The "bad" color has a bogus color space
--bar
. An error is thrown and the Color instance does not get created.Why are "ugly" and "bad" treated differently? "ugly" could be considered equally illegitimate.
Beta Was this translation helpful? Give feedback.
All reactions