-
Notifications
You must be signed in to change notification settings - Fork 9
Add support for #rgba and #rrggbbaa #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@simonbrunel could you have a look please ? |
+ hexDouble(rgba[1]) | ||
+ hexDouble(rgba[2]) | ||
+ ( | ||
(a >= 0 && a < 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a === 1
will cause a problem here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine because if a === 1
(opaque), the alpha component is removed from the hex color (#RRGGBB
instead of #RRGGBBAA
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a === 1
, then there is no transparency, so I think we don't need to set the alpha
component. I imagine returning only a color formatted as #rrggbb
would be a bit faster for the following operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etimberg What do you think ?
@etimberg @kurkle @benmccann would you be able to give a look at that PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of regex's could be changed, but it doesn't change behavior. I would also prefer single quotes in strings, but it has nothing to do with this PR.
} | ||
var abbr = /^#([a-fA-F0-9]{3})$/i, | ||
hex = /^#([a-fA-F0-9]{6})$/i, | ||
var abbr = /^#([a-fA-F0-9]{3,4})$/i, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/^#([a-fA-F0-9]{3,4})$/
or /^#([a-f0-9]{3,4})$/i
works here, no need to specify the case insensitivity twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I think it comes from the original code. Since it doesn't change the result, I would leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upstream code has var abbr = /^#([a-f0-9]{3,4})$/i;
: https://github.com/Qix-/color-string/blob/master/index.js#L50
var abbr = /^#([a-fA-F0-9]{3})$/i, | ||
hex = /^#([a-fA-F0-9]{6})$/i, | ||
var abbr = /^#([a-fA-F0-9]{3,4})$/i, | ||
hex = /^#([a-fA-F0-9]{6}([a-fA-F0-9]{2})?)$/i, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. I would remove the A-F
part to make this shorter and thus more readable:
/^#([a-f0-9]{6})([a-f0-9]{2})?$/i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upstream is var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
: https://github.com/Qix-/color-string/blob/master/index.js#L51
@kurkle I don't think @loicbourgois is still available to update that PR. I think these changes are working correctly so if there is nothing blocking, I would merge as-is. |
@simonbrunel what I thought as well and that's why I approved with comments instead of requesting changes. |
Sorry, didn't notice the approval :) |
That's because it does not count 😭 😃 |
Ah, I didn't check the open PRs before sending mine, so didn't realize there was already one pending. Still I prefer my approach #4 of replacing the function contents with the code from upstream as it's easier to keep in sync with master and would address both open PRs. The other open PR @simonbrunel had suggested #2 (review) copying the code from master as well because it has perhaps a better implementation of what's trying to be accomplished in the other PR |
assert.equal(string.getAlpha("hwb(244, 100%, 100%)"), 1); | ||
|
||
// alpha | ||
assert.deepEqual(string.getRgba("#feff"), [255, 238, 255, 1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it probably would have been preferable to copy the tests from upstream to keep things in sync as much as possible instead of writing our own
As discussed in chartjs/Chart.js#5152.
Based on Qix-@88a8282