Generate sleek, modern, nice colors with pure JS.
Everything needed for NiceColor.js to work is included in the class, no dependencies.
NiceColor.js comes in two versions; NiceColor.js
as a stand-alone class, and module/NiceColor.mjs
for use with ECMAScript Modules.
- Copy the contents of
NiceColor.js
into your JS-file. - Initialize and generate a color
const niceColor = new NiceColor();
niceColor.get(); // Returns HEX-color
- Copy the file
module/NiceColor.mjs
into your JS module(s) folder - Import
'NiceColor'
from yourtype='module'
or Node.js script
import { NiceColor } from "./<your-module-dir>/NiceColor.mjs";
- Initialize and generate a color
const niceColor = new NiceColor();
niceColor.get(); // Returns HEX-color
The RGB HEX channels are initialized as an array this.hex
of the class NiceColor
. You need to generate a color before the values get populated
this.hex = [
null, // Red
null, // Green
null // Blue
];
Example after generate()
has been run:
this.hex = [
"FF", // Red
"16", // Green
"A2" // Blue
];
Get the array with this.hex
after you've generated a color with get()
(or generate()
if you don't care about the final HEX-code at all)
Example:
const niceColor = new NiceColor();
niceColor.generate();
console.log(niceColor.hex); // Logs: Array["FF,"16,"A2"]