Skip to content

feat(rgba validation): allow floating point values for 0 and 1 on alpha channel #45

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Budaa
Copy link

@Budaa Budaa commented Oct 17, 2024

Overview:
This pull request enhances the alpha value validation in the validateHTMLColorRgb function by allowing floating-point representations of 0.0 and 1.0. While the previous implementation already supported percentage values and general floating-point numbers, these updates ensure that the specific floating-point formats for 0 and 1 are explicitly accommodated.

Changes Made:

  • Updated the regex pattern for the alpha channel to include:
    • Explicit support for 0.0 and 1.0, along with their variations (0.00, 1.00, etc.)

Detailed Changes:
The regex segment for alpha value validation has been refined to:

const A = '(\\/?${spaceNoneOrMore}(0?\\.?${digitOneOrMore}(%)?|1(\\.0+)?|0)${spaceNoneOrMore})?';

This update allows for:

  • Floating-point representations like 0.0, 0.00, and 1.0, 1.00
  • Retained support for percentage values (e.g., 50%, 100%)
  • General floating-point values (e.g., 0.5, 0.75)

Testing:
The updated validation has been tested against various input cases to ensure its accuracy:

  • Valid cases: 0, 0.0, 0.5, 1, 1.0, 50%, 100%
  • Invalid cases: 1.1, -0.5, 200%, 1.01%

Impact:
This enhancement improves the robustness of the color validation logic by explicitly allowing floating-point representations of 0 and 1, ensuring better compliance with user expectations and CSS standards.

Conclusion:
I believe this update will significantly enhance the usability of the RGB color parsing utility. I look forward to any feedback and further improvements!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant