Skip to main content

Function: isRgbColor()

isRgbColor(value): value is RGB

Defined in: functions/isRgbColor.ts:28

Checks if a value is a valid RGB color object.

This function checks if the provided value is an object with properties r, g, and b that are integers within the specified ranges:

  • r (red) should be an integer between 0 and 255
  • g (green) should be an integer between 0 and 255
  • b (blue) should be an integer between 0 and 255
  • 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 RGB

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

Examples

isRgbColor({ r: 255, g: 0, b: 0 }); // true
isRgbColor({ r: 255, g: 0, b: 0, a: 1 }); // true
isRgbColor({ r: 256, g: 0, b: 0 }); // false
isRgbColor("#ff0000"); // false