nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
44 lines (43 loc) • 2.24 kB
TypeScript
import type { $ColorType, HSL, RandomColor, RandomColorOptions, RandomHexRGB } from './types';
/**
* * Utility to generate a unique random HSL color.
*
* @param maxColors - The maximum number of recent colors to store in memory. Default is `16`.
* @returns Generated unique random color in `HSL` format.
*/
export declare const generateRandomHSLColor: (maxColors?: number) => HSL;
/**
* @deprecated For optimized performance and more flexibility, please consider using {@link generateRandomColor}.
*
* * Utility to generate a unique random color in `Hex6` and `RGB` format.
*
* @param maxColors - The maximum number of recent colors to store in memory. Default is `16`.
* @returns An object of generated unique random color in both `Hex` and `RGB` formats.
*/
export declare const generateRandomColorInHexRGB: (maxColors?: number) => RandomHexRGB;
/**
* * Generates a random unique color in one of three formats: `Hex6`, `RGB`, or `HSL`.
*
* @remarks
* - If no `options` or `colorType` option is provided, the function defaults to returning a color in `Hex6` format.
* - The `colorType` option determines the return type:
* - `'hex'` → returns a `Hex6` string e.g. `'#34E2EF'`
* - `'rgb'` → returns an `RGB` string e.g. `'hsl(223, 96%, 53%)'`
* - `'hsl'` → returns an `HSL` string e.g. `'rgb(235, 159, 45)'`
* - The `maxColors` option controls how many recently generated colors are kept in memory to prevent repetition.
* By default, this value is `16`. Increasing it allows more unique color variations before repeating.
*
* @param options - Configuration options for random color generation, including `colorType` and `maxColors`.
* @returns A random unique color in the specified format (`Hex6`, `RGB`, or `HSL`).
*
* @example
* const hex = generateRandomColor();
* // hex value with inferred type: Hex6
*
* const rgb = generateRandomColor({ colorType: 'rgb' });
* // rgb value with inferred type: RGB
*
* const hsl = generateRandomColor({ colorType: 'hsl', maxColors: 32 });
* // hsl value with inferred type: HSL, with a larger unique color memory pool
*/
export declare function generateRandomColor<C extends $ColorType = 'hex'>(options?: RandomColorOptions<C>): RandomColor<C>;