From 64e562bbf0e827306057b82024bae7eb9096abe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20LES=C3=89N=C3=89CHAL?= Date: Mon, 29 Jan 2024 18:14:46 +0100 Subject: [PATCH] ColorUtil: check color array size by using a `Color` type to ensure RGB/HSV arrays have at least 3 values --- jquery/colorUtil.d.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/jquery/colorUtil.d.ts b/jquery/colorUtil.d.ts index e7b94a6..c71783a 100644 --- a/jquery/colorUtil.d.ts +++ b/jquery/colorUtil.d.ts @@ -4,6 +4,8 @@ declare global { } } +type Color = [number, number, number]; + interface ColorUtil { /** * Parse CSS color strings looking for color tuples @@ -11,10 +13,10 @@ interface ColorUtil { * Based on highlightFade by Blair Mitchelmore * * - * @param {Array|string} color - * @returns {Array} + * @param {Color|string} color + * @returns {Color} */ - getRGB(color: string | number[]): number[]; + getRGB(color: string | T): T; /** * Named color map @@ -22,7 +24,7 @@ interface ColorUtil { * Based on Interface by Stefan Petre * */ - colors: Record; + colors: Record; /** * Convert an RGB color value to HSL. @@ -38,9 +40,9 @@ interface ColorUtil { * @param {number} r The red color value * @param {number} g The green color value * @param {number} b The blue color value - * @returns {number[]} The HSL representation + * @returns {Color} The HSL representation */ - rgbToHsl(r: number, g: number, b: number): number[]; + rgbToHsl(r: number, g: number, b: number): Color; /** * Convert an HSL color value to RGB. @@ -56,9 +58,9 @@ interface ColorUtil { * @param {number} h The hue * @param {number} s The saturation * @param {number} l The lightness - * @returns {number[]} The RGB representation + * @returns {Color} The RGB representation */ - hslToRgb(h: number, s: number, l: number): number[]; + hslToRgb(h: number, s: number, l: number): Color; /** * Get a brighter or darker rgb() value string. @@ -72,11 +74,14 @@ interface ColorUtil { * // > "rgb(118,29,29)" * ``` * - * @param {Mixed} currentColor Current value in css + * @param {Color|string} currentColor Current value in css * @param {number} mod Wanted brightness modification between -1 and 1 * @returns {string} Like `'rgb(r,g,b)'` */ - getColorBrightness(currentColor: any, mod: number): `rgb(${number},${number},${number})`; + getColorBrightness( + currentColor: string | Color, + mod: number + ): `rgb(${number},${number},${number})`; } export {};