Skip to content

Commit

Permalink
fix: change color validation functionality in isValidHsl.ts
Browse files Browse the repository at this point in the history
The 'isValidHsl' function has been updated. It's no longer validating 'undefined' as 'deg' unit and no longer returning 'NaN' for default cases. Additionally, the check for 'h' not being 'NaN' has been removed. Values are now correctly validated within their respective ranges.
  • Loading branch information
mallikcheripally committed May 28, 2024
1 parent e7d25e3 commit b517126
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/validations/isValidHsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function isValidHsl(color: string): boolean {
let hueValue = parseFloat(hue);
switch (unit) {
case 'deg':
case undefined:
return hueValue;
case 'rad':
return hueValue * (180 / Math.PI);
Expand All @@ -22,7 +21,7 @@ export function isValidHsl(color: string): boolean {
case 'turn':
return hueValue * 360;
default:
return NaN;
return hueValue;
}
};

Expand All @@ -31,7 +30,7 @@ export function isValidHsl(color: string): boolean {
const l = parseFloat(match[4]);

return (
!isNaN(h) && h >= 0 && h <= 360 &&
h >= 0 && h <= 360 &&
s >= 0 && s <= 100 &&
l >= 0 && l <= 100
);
Expand Down

0 comments on commit b517126

Please sign in to comment.