UNPKG

@mirawision/colorize

Version:

A comprehensive color manipulation library for TypeScript, providing functionalities for color conversion, validation, gradient generation, and various color adjustments.

28 lines (27 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.randomColor = void 0; const convert_color_1 = require("./convert-color"); const types_1 = require("./types"); /** * Generates a random color in the specified format. * * @param {ColorFormat} format - The desired color format (hex, hexa, rgb, rgba, hsl, hsla, hsv, cmyk). * Default is 'hex'. * * @returns {string} - The random color in the specified format. * * Example usage: * randomColor(); // Returns a random color in HEX format. * randomColor(ColorFormat.RGB); // Returns a random color in RGB format. */ const randomColor = (format = types_1.ColorFormat.HEX) => { const getRandomInt = (max) => Math.floor(Math.random() * (max + 1)); const r = getRandomInt(255); const g = getRandomInt(255); const b = getRandomInt(255); const a = Math.random().toFixed(2); const baseColor = `rgba(${r}, ${g}, ${b}, ${a})`; return (0, convert_color_1.convertColor)(baseColor, format); }; exports.randomColor = randomColor;