npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@apollo-tech/random-color

v0.0.4

Published

A simple random color generator

Downloads

46

Readme

Random Color Generator

This is a simple random color generator that generates a random color, or colors, in the requested format. It is heavily based on the randomcolor tiny script. This package simply expands on the original script by adding more features and options, particularly by instantiating a class that can be used to retain the history of generated colors.

Installation

npm install @apollo-tech/random-color

Usage

Basic Usage

import RandomColorGenerator from '@apollo-tech/random-color';
// create a new instance of the random color generator
const generator = new RandomColorGenerator();
// generate a random color
const color = generator.randomColor()
console.log(color);
// Output: '#a3e2c1'

Options

You can pass an options object to influence the type of color it produces. The options object accepts the following properties:

hue – Controls the hue of the generated color. You can pass a string representing a color name: red, orange, yellow, green, blue, purple, pink and monochrome are currently supported.

luminosity – Controls the luminosity of the generated color. You can specify a string containing bright, light or dark.

count – An integer which specifies the number of colors to generate.

seed - An integer or string which when passed will cause randomColor to return the same color each time.

format – A string which specifies the format of the generated color. Possible values are rgb, rgba, rgbArray, hsl, hsla, hslArray, and hex. If you do not provide a value, hex will be used.

alpha – A decimal between 0 and 1. This is only relevant when using a format with an alpha channel (rgba and hsla). Defaults to a random value.

// generate a random color in a specific format
const color = generator.randomColor({ format: 'rgb' });
console.log(color);
// Output: 'rgb(225,200,20)'

History

The generator class retains a history of generated colors. You can access the history by calling the history property.

// view the history of generated colors
console.log(generator.history);
// Output: ['#a3e2c1', 'rgb(225,200,20)']

Methods

Verbose Logging

You can enable a logging method by setting the verbose mode to true. This will log the generated color to the console. All console messages are logged using the console.debug method and are prefixed with the string [RandomColor].

// enable verbose mode for testing
generator.setVerbose(true);
console.log(generator.verbose)
// Output: true

Set Seed

You can set the seed for the random color generator. This will allow you to generate the same random color each time you run the generator with the same seed. The seed can be set in the options object when calling the randomColor method, or by calling the setSeed method.

// change the seed
generator.setSeed(1234);
console.log(generator.seed);
// Output: 1234