UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

184 lines 8.21 kB
import type { Hex, Hex6, Hex8, HSL, HSLA, RGB, RGBA } from './types'; /** * * Converts HSL to RGB color format. * * @param h - The hue component of the HSL color, in degrees (0 to 360). * @param s - The saturation component of the HSL color, as a percentage (0 to 100). * @param l - The lightness component of the HSL color, as a percentage (0 to 100). * @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`). */ export declare const convertHslToRgb: (h: number, s: number, l: number) => RGB; /** * * Converts RGB to HSL color format. * * @param r - The red component of the RGB color, in the range 0 to 255. * @param g - The green component of the RGB color, in the range 0 to 255. * @param b - The blue component of the RGB color, in the range 0 to 255. * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`). */ export declare const convertRgbToHsl: (r: number, g: number, b: number) => HSL; /** * * Converts HSL to Hex color format. * * @param h - The hue component of the HSL color, in degrees (0 to 360). * @param s - The saturation component of the HSL color, as a percentage (0 to 100). * @param l - The lightness component of the HSL color, as a percentage (0 to 100). * @returns A string representing the color in Hex format (e.g., `#FF0000`). */ export declare const convertHslToHex: (h: number, s: number, l: number) => Hex6; /** * * Converts Hex to HSL color format. * * @param hex - A string representing the color in Hex format (e.g., `#FF0000`). * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`). */ export declare const convertHexToHsl: (hex: Hex6 | Hex) => HSL; /** * * Converts RGB to Hex color format. * * @param r - The red component of the RGB color, in the range 0 to 255. * @param g - The green component of the RGB color, in the range 0 to 255. * @param b - The blue component of the RGB color, in the range 0 to 255. * @returns A string representing the color in Hex format (e.g., `#FF0000`). */ export declare const convertRgbToHex: (r: number, g: number, b: number) => Hex6; /** * * Converts Hex to RGB color format. * * @param hex - A string representing the color in Hex format (e.g., `#FF0000`). * @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`). */ export declare const convertHexToRgb: (hex: Hex6 | Hex | string) => RGB; /** * * Converts RGB to RGBA format, adding alpha (opacity). * * @param r - The red component of the RGB color, in the range 0 to 255. * @param g - The green component of the RGB color, in the range 0 to 255. * @param b - The blue component of the RGB color, in the range 0 to 255. * @param a - The alpha (opacity) value, in the range 0 to 1. * @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`). */ export declare const convertRgbToRgba: (r: number, g: number, b: number, a?: number) => RGBA; /** * * Converts RGBA to Hex format, including alpha channel as part of Hex8. * * @param r - The red component of the RGB color, in the range 0 to 255. * @param g - The green component of the RGB color, in the range 0 to 255. * @param b - The blue component of the RGB color, in the range 0 to 255. * @param a - The alpha (opacity) value, in the range 0 to 1. * @returns A string representing the color in Hex8 format (e.g., `#FF000080`). */ export declare const convertRgbaToHex8: (r: number, g: number, b: number, a?: number) => Hex8; /** * * Converts HSLA to RGBA color format, including alpha channel. * * @param h - The hue component of the HSL color, in degrees (0 to 360). * @param s - The saturation component of the HSL color, as a percentage (0 to 100). * @param l - The lightness component of the HSL color, as a percentage (0 to 100). * @param a - The alpha (opacity) value, in the range 0 to 1. * @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`). */ export declare const convertHslaToRgba: (h: number, s: number, l: number, a?: number) => RGBA; /** * * Converts RGBA to HSLA color format, including alpha channel. * * @param r - The red component of the RGB color, in the range 0 to 255. * @param g - The green component of the RGB color, in the range 0 to 255. * @param b - The blue component of the RGB color, in the range 0 to 255. * @param a - The alpha (opacity) value, in the range 0 to 1. * @returns A string representing the color in HSLA format (e.g., `hsla(0, 100%, 50%, 0.5)`). */ export declare const convertRgbaToHsla: (r: number, g: number, b: number, a?: number) => HSLA; /** * * Converts Hex8 to RGBA color format, including alpha channel. * - `Special Note:` Cast the parameter to `Hex8` before converting to `RGBA`. * @example convertHex8ToRgba('#FFF122DE' as Hex8) * * @param hex8 - A string representing the color in Hex8 format (e.g., `#FF000080`). * @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`). */ export declare const convertHex8ToRgba: (hex8: Hex8) => RGBA; /** * * Converts HSLA to Hex8 color format, including alpha channel. * * @param h - The hue component of the HSL color, in degrees (0 to 360). * @param s - The saturation component of the HSL color, as a percentage (0 to 100). * @param l - The lightness component of the HSL color, as a percentage (0 to 100). * @param a - The alpha (opacity) value, in the range 0 to 1. * @returns A string representing the color in Hex8 format (e.g., `#658789DF`). */ export declare const convertHslaToHex8: (h: number, s: number, l: number, a?: number) => Hex8; /** * * Converts Hex8 to HSLA color format. * - `Special Note:` Cast the parameter to `Hex8` before converting to `HSLA`. * @example convertHex8ToHsla('#FFF122DE' as Hex8) * * @param hex - A string representing the color in Hex format (e.g., `#FF0000DE`). * @returns A string representing the color in HSLA format.. */ export declare const convertHex8ToHsla: (hex8: Hex8) => HSLA; /** * * Converts a `Hex` color code to `RGB` and `HSL` formats. * - `Special Note:` Cast the parameter to `Hex6` before converting to `RGB` and `HSL`. * @example convertColorCode('#FFF122' as Hex6) * * @param color The `Hex` color code (e.g., `#3c6945`). * @returns An object containing the `RGB` and `HSL` formats of the given `Hex` color. */ export declare function convertColorCode(color: Hex6): { rgb: RGB; hsl: HSL; }; /** * * Converts an `RGB` color to `Hex` and `HSL` formats. * * @param color The `RGB` color string (e.g., `rgb(60, 105, 69)`). * @returns An object containing the `Hex` and `HSL` formats of the given `RGB` color. */ export declare function convertColorCode(color: RGB): { hex: Hex6; hsl: HSL; }; /** * * Converts an `HSL` color to `Hex` and `RGB` formats. * * @param color The `HSL` color string (e.g., `hsl(132, 27.27%, 32.35%)`). * @returns An object containing the `Hex` and `RGB` formats of the given `HSL` color. */ export declare function convertColorCode(color: HSL): { hex: Hex6; rgb: RGB; }; /** * * Converts a `Hex8` color code to `RGB` and `HSL` formats. * - `Special Note:` Cast the parameter to `Hex8` before converting to `RGBA` and `HSLA`. * @example convertColorCode('#FFF122DE' as Hex8) * * @param color The `Hex8` color code (e.g., `#3c6945`). * @returns An object containing the `RGB` and `HSL` formats of the given `Hex8` color. */ export declare function convertColorCode(color: Hex8): { rgba: RGBA; hsla: HSLA; }; /** * * Converts an `RGBA` color to `Hex8` and `HSLA` formats. * * @param color The `RGBA` color string (e.g., `rgb(60, 105, 69)`). * @returns An object containing the `Hex8` and `HSLA` formats of the given `RGBA` color. */ export declare function convertColorCode(color: RGBA): { hex8: Hex8; hsla: HSLA; }; /** * * Converts an `HSLA` color to `Hex8` and `RGBA` formats. * * @param color The `HSLA` color string (e.g., `hsl(132, 27.27%, 32.35%)`). * @returns An object containing the `Hex8` and `RGBA` formats of the given `HSLA` color. */ export declare function convertColorCode(color: HSLA): { hex8: Hex8; rgba: RGBA; }; //# sourceMappingURL=convert.d.ts.map