Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
randomcolor
Advanced tools
The randomcolor npm package is a versatile tool for generating random colors. It allows users to create random colors with various options for hue, luminosity, and format.
Generate a random color
This feature generates a completely random color in hexadecimal format.
const randomColor = require('randomcolor');
const color = randomColor();
console.log(color);
Generate a random color with specific hue
This feature generates a random color with a specified hue, in this case, blue.
const randomColor = require('randomcolor');
const color = randomColor({ hue: 'blue' });
console.log(color);
Generate a random color with specific luminosity
This feature generates a random color with a specified luminosity, in this case, light.
const randomColor = require('randomcolor');
const color = randomColor({ luminosity: 'light' });
console.log(color);
Generate a random color with specific format
This feature generates a random color in a specified format, in this case, RGB.
const randomColor = require('randomcolor');
const color = randomColor({ format: 'rgb' });
console.log(color);
Generate multiple random colors
This feature generates an array of multiple random colors, in this case, five colors.
const randomColor = require('randomcolor');
const colors = randomColor({ count: 5 });
console.log(colors);
Chroma.js is a powerful library for color conversions and color scales. It provides more advanced color manipulation capabilities compared to randomcolor, including color blending, interpolation, and color scales.
The color package is a comprehensive library for color conversion and manipulation. It supports a wide range of color models and provides methods for color transformations, making it more feature-rich for color manipulation tasks compared to randomcolor.
TinyColor is a small, fast library for color manipulation and conversion. It offers a balance between simplicity and functionality, providing more color manipulation options than randomcolor while maintaining a small footprint.
A tiny script for generating attractive random colors. See the results on the demo.
randomColor is available minified on cdnjs. It is also distributed on npm and bower.
npm install randomcolor
randomColor has been ported to C#, Go, PHP, Python, Swift, Objective-C and Java.
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 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
, rgbArray
, hsl
, hslArray
and hex
(default).
// Returns a hex code for an attractive color
randomColor();
// Returns an array of ten green colors
randomColor({
count: 10,
hue: 'green'
});
// Returns a hex code for a light blue
randomColor({
luminosity: 'light',
hue: 'blue'
});
// Returns a hex code for a 'truly random' color
randomColor({
luminosity: 'random',
hue: 'random'
});
// Returns a bright color in RGB
randomColor({
luminosity: 'bright',
format: 'rgb' // e.g. 'rgb(225,200,20)'
});
// Returns a dark RGB color with random alpha
randomColor({
luminosity: 'dark',
format: 'rgba' // e.g. 'rgba(9, 1, 107, 0.6482447960879654)'
});
// Returns a light HSL color with random alpha
randomColor({
luminosity: 'light',
format: 'hsla' // e.g. 'hsla(27, 88.99%, 81.83%, 0.6450211517512798)'
});
This project is dedicated to the public domain.
More generally, it might be a good idea to consider using other color models.
FAQs
A tiny script for generating attractive random colors
The npm package randomcolor receives a total of 55,358 weekly downloads. As such, randomcolor popularity was classified as popular.
We found that randomcolor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.