Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
color-hash
Advanced tools
Readme
Generate color based on the given string.
https://zenozeng.github.io/color-hash/demo/
bower install color-hash
A UMD version of ColorHash was located in dist/.
Note that Array.prototype.map was used in color-hash, a pollfill must be provided if you want to use it in IE8.
var colorHash = new ColorHash();
// in HSL, Hue ∈ [0, 360), Saturation ∈ [0, 1], Lightness ∈ [0, 1]
colorHash.hsl('Hello World'); // [ 235, 0.65, 0.35 ]
// in RGB, R, G, B ∈ [0, 255]
colorHash.rgb('Hello World'); // [ 31, 41, 147 ]
// in HEX
colorHash.hex('Hello World'); // '#1f2993'
var customHash = function(str) {
var hash = 0;
for(var i = 0; i < str.length; i++) {
hash += str.charCodeAt(i);
}
return hash;
};
var colorHash = new ColorHash({hash: customHash});
colorHash.hsl('Hello World!');
colorHash.rgb('Hello World!');
colorHash.hex('Hello World!');
var colorHash = new ColorHash({lightness: 0.5});
var colorHash = new ColorHash({lightness: [0.35, 0.5, 0.65]});
var colorHash = new ColorHash({saturation: 0.5});
var colorHash = new ColorHash({saturation: [0.35, 0.5, 0.65]});
npm install color-hash --save
var ColorHash = require('color-hash');
MIT.
Use the hash function (default is BKDRHash) to calculate the hash of the given string,
Hue = hash % 359. (Note that 359 is a prime)
Saturation = SaturationArray[hash / 360 % SaturationArray.length]
Lightness = LightnessArray[hash / 360 / Saturation.length % LightnessArray.length]
By default,
SaturationArray = LightnessArray = [0.35, 0.5, 0.65]
Though LAB is more perceptually uniform, HSL is easier to control. Simply sets lightness and saturation and change hue uniformly can generate uniform colors.
sudo npm install -g mocha
sudo npm install -g istanbul
npm test
https://zenozeng.github.io/color-hash/coverage/lcov-report/lib/index.html
sudo npm install -g browserify
npm run build
FAQs
Generate color based on the given string (using HSL color space and SHA256).
The npm package color-hash receives a total of 67,864 weekly downloads. As such, color-hash popularity was classified as popular.
We found that color-hash 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
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.