Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

get-random-color-by-kidker

kidker959ISC1.1.0TypeScript support: included

Simple Helper functions to generate random colors in RGB, RGBA, HSL, HSLA, and hexadecimal formats

random, colors, color, rgb, rgba, hsl, hsla, cmyk, cmyka, hexadecimal

readme

Get Random Color

npm version

Description

get-random-color-by-kidker is a simple package that provides utility functions to generate random colors in different formats, including:

  • RGB
  • RGBA
  • HSL
  • HSLA
  • Hexadecimal
  • CYMK
  • CYMKA

Installation

You can install this package via npm:

npm install get-random-color-npm-by-kidker

Examples

import * as getRandomColors from 'get-random-color-by-kidker';

// Generating a Random RGB Color: 

const randomRGB = getRandomColors.getRandomRGB();
console.log(randomRGB); // Example output: rgb(23, 145, 76)


// Generating a Random RGBA Color: 

const randomRGBA = getRandomColors.getRandomRGBA();
console.log(randomRGBA); // Example output: rgba(23, 145, 76, 0.8)

// Generating a Random Hexadecimal Color:

const randomHex = getRandomColors.getRandomHexadecimal();
console.log(randomHex); // Example output: #17e576


// Generating a Random HSL Color:

const randomHSL = getRandomColors.getRandomHSL();
console.log(randomHSL); // Example output: hsl(200%,50%,50%)


// Generating a Random HSLA Color:

const randomHSLA = getRandomColors.getRandomHSLA();
console.log(randomHSLA); // Example output: hsla(200%,50%,50%,0.7)

// Generating a Random CMYK Color:

const randomCMYK = getRandomColors.getRandomCMYK();
console.log(randomCMYK); // Example output: cmyk(20%, 50%, 30%, 10%)


// Generating a Random CMYKA Color:

const randomCMYKA = getRandomColors.getRandomCMYKA();
console.log(randomCMYKA); // Example output: cmyk(20%, 50%, 30%, 10%, 0.7)

Function OverView:

  • getRandomRGB(): Generates a random RGB color string in the format rgb(r, g, b).
  • getRandomRGBA(): Generates a random RGBA color string in the format rgba(r, g, b, a).
  • getRandomHexadecimal(): Generates a random Hexadecimal color string in the format #rrggbb.
  • getRandomHSL(): Generates a random HSL color string in the format hsl(h, s%, l%).
  • getRandomHSLA(): Generates a random HSLA color string in the format hsla(h, s%, l%, a).
  • getRandomCMYK(): Generates a random CMYK color string in the format cmyk(c%, m%, y%, k%).
  • getRandomCMYKA(): Generates a random CMYKA color string in the format cmyk(c%, m%, y%, k%, a).

Contributing:

Feel free to submit pull requests for improvements or open issues for any bugs you may encounter.

License:

This project is licensed under the MIT License.

Author:

Kidker95