Generate random colors.
This package is included in 'randplus'.
// Classicconstrandom=require('@randplus/color');console.log(random('hex'));// '000000' ~ 'ffffff'console.log(random('hex',{prefix: '#'}));// '#000000' ~ '#ffffff'console.log(random('rgb'));// [0, 0, 0] ~ [255, 255, 255]console.log(random('word'));// 'limegreen'console.log(random('word',{language: 'ja'}));// '鉄色'// Advancedconst{ hex, rgb, word }=require('@randplus/color');console.log(hex());// '000000' ~ 'ffffff'console.log(hex('#'));// '#000000' ~ '#ffffff'console.log(rgb());// [0, 0, 0] ~ [255, 255, 255]console.log(word());// 'limegreen'console.log(word('cn'));// '紫磨金'Install color-name-lib.
npm i color-name-libconst{ hex }=require('@randplus/color');constcolorName=require('color-name-lib');constcolorHex=hex();constname=colorName(colorHex);console.log(`${colorHex}: ${name}`);or use lib/color-name-lib.js.
const{ hex }=require('@randplus/color');constcolorName=require('@randplus/color/lib/color-name-lib');constcolorHex=hex();constname=colorName(colorHex);console.log(`${colorHex}: ${name}`);