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

Add type for Hex color #144

Closed
ximex opened this issue Apr 11, 2024 · 2 comments
Closed

Add type for Hex color #144

ximex opened this issue Apr 11, 2024 · 2 comments

Comments

@ximex
Copy link
Contributor

ximex commented Apr 11, 2024

add a type for hex-color strings that is a bit stricter than only string.
type HexColor = `#${string}`;

@jaywcjlove
Copy link
Member

@ximex I can add this type to the package. I tried using the HexColor type, but it may not be easy to use in the code because many places have done error handling, which causes type errors.

// To compare colors like `#FFF` and `ffffff` we convert them into RGB objects
return equalColorObjects(hexToRgba(first), hexToRgba(second));

export const validHex = (hex: string): boolean => /^#?([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);

@ximex
Copy link
Contributor Author

ximex commented Sep 24, 2024

@ximex ximex closed this as completed Sep 24, 2024
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

No branches or pull requests

2 participants