randomcolor
Advanced tools
Comparing version 0.5.1 to 0.5.2
{ | ||
"name": "randomcolor", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "For generating attractive random colors", | ||
"main": "randomColor.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
@@ -16,17 +10,8 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"attractive", | ||
"random", | ||
"color", | ||
"generator" | ||
], | ||
"keywords": ["attractive", "random", "color", "generator"], | ||
"author": "David Merfield", | ||
"license": "CC0", | ||
"bugs": { | ||
"url": "https://github.com/davidmerfield/randomColor/issues" | ||
}, | ||
"bugs": {"url": "https://github.com/davidmerfield/randomColor/issues"}, | ||
"homepage": "http://llllll.li/randomColor/", | ||
"spm": { | ||
"main": "randomColor.js" | ||
}, | ||
"spm": {"main": "randomColor.js"}, | ||
"devDependencies": { | ||
@@ -33,0 +18,0 @@ "cheerio": "^0.19.0", |
@@ -248,2 +248,5 @@ // randomColor by David Merfield under the CC0 license | ||
if (color.hueRange) {return color.hueRange;} | ||
} else if (colorInput.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) { | ||
const hue = HexToHSB(colorInput)[0]; | ||
return [ hue, hue ]; | ||
} | ||
@@ -409,2 +412,21 @@ } | ||
function HexToHSB (hex) { | ||
hex = hex.replace(/^#/, ''); | ||
hex = hex.length === 3 ? hex.replace(/(.)/g, '$1$1') : hex; | ||
const red = parseInt(hex.substr(0, 2), 16) / 255, | ||
green = parseInt(hex.substr(2, 2), 16) / 255, | ||
blue = parseInt(hex.substr(4, 2), 16) / 255; | ||
const cMax = Math.max(red, green, blue), | ||
delta = cMax - Math.min(red, green, blue), | ||
saturation = cMax ? (delta / cMax) : 0; | ||
switch (cMax) { | ||
case red: return [ 60 * (((green - blue) / delta) % 6) || 0, saturation, cMax ]; | ||
case green: return [ 60 * (((blue - red) / delta) + 2) || 0, saturation, cMax ]; | ||
case blue: return [ 60 * (((red - green) / delta) + 4) || 0, saturation, cMax ]; | ||
} | ||
} | ||
function HSVtoHSL (hsv) { | ||
@@ -411,0 +433,0 @@ var h = hsv[0], |
# [Random Color](http://llllll.li/randomColor) | ||
A tiny script for generating attractive random colors. See the results on [the demo](http://llllll.li/randomColor/). | ||
A tiny script for generating attractive random colors. See the demo for [an explanation](http://llllll.li/randomColor/) and [some samples](http://llllll.li/randomColor/). | ||
[![Demo](http://i.imgur.com/lOLCqvu.gif)](http://llllll.li/randomColor) | ||
randomColor is available [minified on cdnjs](http://cdnjs.com/libraries/randomcolor). It is also distributed on [npm](https://www.npmjs.org/package/randomcolor) and bower. | ||
randomColor is available [minified on cdnjs](http://cdnjs.com/libraries/randomcolor). It is also distributed on [npm](https://www.npmjs.org/package/randomcolor). | ||
@@ -19,3 +19,3 @@ ```javascript | ||
**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. | ||
**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. If you pass a hexidecimal color string such as ```#00FFFF```, randomColor will extract its hue value and use that to generate colors. | ||
@@ -30,3 +30,3 @@ **Luminosity** – Controls the luminosity of the generated color. You can specify a string containing ```bright```, ```light``` or ```dark```. | ||
**Alpha** – A decimal between 0 and 1 which specifies the alpha amount of ```rgba``` and ```hsla``` formats. Defaults to a random value. | ||
**Alpha** – A decimal between 0 and 1. Only relevant when using a format with an alpha channel (```rgba``` and ```hsla```). Defaults to a random value. | ||
@@ -33,0 +33,0 @@ ### Examples |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
65002
1
11
544