color-algo
v1.1.3
Published
A small, professional random color generator. Works in Node (CJS/ESM), bundlers, and the browser.
Maintainers
Readme
random-color-generator
A tiny, professional random color generator JavaScript library.
Install (local dev)
# clone the folder or copy files into a folder
npm install
# run the test
npm testUsage
const getColor = require("random-color-generator");
// random values (not guaranteed to be the same across calls)
console.log(getColor.rgb()); // -> [r,g,b]
console.log(getColor.hex()); // -> '#rrggbb'
console.log(getColor.cmyk()); // -> {c,m,y,k}
// consistent color for single generation
const c = getColor.randomColor();
console.log(c.rgb, c.hex, c.cmyk);
// convert from a known hex or rgb
console.log(getColor.fromHex("#00ff88"));
console.log(getColor.fromRgb([255, 128, 0]));Conversions
- RGB -> HEX: basic 0-255 to hex conversion.
- RGB -> CMYK: standard formula using K = 1 - max(r',g',b') where r'=r/255.
Publishing
- Create an npm account:
npm loginclw2. Ensurenamein package.json is unique on npmjs.org. npm publish(if scoped package like@yourname/pkgusenpm publish --access public)
