Skip to content
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

Extended HSL/HSLA/HSB Handling with Float Support #93

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

Conversation

danielebarbaro
Copy link
Contributor

This PR introduces extended support for handling HSL, HSLA, and HSB color formats with floating-point values.

The changes address and resolve Issue #89.

Changes:

  1. Centralized Regex Patterns:

    • Introduced HsPatterns class to centralize and manage regex patterns for validation and extraction.
    • This ensures consistency and maintainability of regex patterns across the library.
  2. Enhanced Parsing Logic:

    • Updated Hsb, Hsl, and Hsla classes to use the new HsPatterns class for parsing.
    • Modified the fromString methods to correctly parse and handle floating-point values in color strings.
  3. Validation Improvements:

    • "Refactored" Validate methods (hsbColorString, hslColorString, and hslaColorString) to utilize the new centralized regex patterns in HsPatterns.
  4. Tests and Dataset Enhancements:

    • Added test cases in Colors to cover scenarios involving floating-point values in HSL/HSLA/HSB strings.
    • Examples include edge cases such as hsla(357, 12.12%, 44.5%, 0.1) and hsl(221, 11.52%, 32.35%) (taken from the issue).
    • All updated test cases pass successfully, and new datasets were added to ensure comprehensive coverage for float handling.

Resolves:
Issue #89


class HsPatterns
{
private const HUE = '\d{1,3}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make these protected

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These also can be regular class properties, not constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to change from private to protected.

My initial idea was to create a ColorPattern class instead of HsPattern, but that would have required a complete refactor of the package—and doing that the day before Christmas would have been a bit naughty.

Using constants feels cleaner to me, as it allows me to avoid touching VALIDATION_PATTERNS and EXTRACTION_PATTERNS.

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.

Fails with HSL with floats
2 participants