Skip to main content

Function: isHslColor()

isHslColor(value): value is HSL

Defined in: functions/isHslColor.ts:28

Checks if a value is a valid HSL color object.

This function checks if the provided value is an object with properties h, s, and l that are integers within the specified ranges:

  • h (hue) should be an integer between 0 and 360
  • s (saturation) should be an integer between 0 and 100
  • l (lightness) should be an integer between 0 and 100
  • It also optionally checks for an a property, which should be a number between 0 and 1 if it exists.

Parameters

value

any

The value to check.

Returns

value is HSL

True if the value is a valid HSL color object, false otherwise.

Examples

isHslColor({ h: 360, s: 100, l: 50 }); // true
isHslColor({ h: 180, s: 50, l: 25, a: 0.5 }); // true
isHslColor({ h: 361, s: 50, l: 50 }); // false
isHslColor("#ff0000"); // false