Modernization to the current CSS rgb/rgba color parser #172
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#values
https://developer.mozilla.org/en-US/docs/Web/CSS/alpha-value
Both rgb and rgba contain the optional parameter of alpha despite naming convention. R, G, B are required; A is optional for both.
Test cases: ["rgb(30% 20% 50%)","rgb(153,255,153,0.5)","rgb(253, 255, 153)","rgb(255 255 255 / 50.75%)","rgba(255, 255, 255 / 50%)","rgb( 255, 255, 255, none )","rgba(none, 255, 255 / none)"]
Remains unsupported: Relative value syntax (rgb(from R G B[ / A]))
It seems like Math.round is used where you use Math.floor in browser implementations of handling percent byte rgb values (see MDN's test case of the first test case).
Thanks for the work in maintaining this library. Hope a few touch-ups are appreciated. Reach out/add commits if you notice any impactful bugs. I focused on making the parser more flexible and reducing code (for individual cases). ✌️
Alternative: #171