colorboy
Easily add color to your console.log
s in Node.js.
Installation
npm install colorboy
Usage
;console;console;console;
Colors
Below you can see how to specify colors. To specify a background color, simply use .bgColor()
instead of .color()
.
- Colors added by
addDefaults()
:Can be'Sonic'cyanred
,black
,green
,yellow
,blue
,pink
,cyan
,white
orgray
- A CSS keyword:
'Sonic'.color('crimson')
- A hex code:'Sonic'color'#FF00FF'
- An rgb code:'Sonic'color220 20 60
- An rgb code:'Sonic'color220 20 60 'rgb'
- An hsl code:'Sonic'color32 100 100 'hsl'
- An hsv code:'Sonic'color32 100 50 'hsv'
- An hwb code:'Sonic'color32 0 50 'hwb'
Passing arrays works too:
// the following are equivalent:'Sonic'color220 20 60'Sonic'color220 20 60 // the following are equivalent:'Sonic'color32 100 100 'hsl''Sonic'color32 100 100 'hsl'
Styles
Use styles added by addDefaults()
:
'Sonic'bold
Can be bold
, dim
, italic
, underline
, inverse
and strikethrough
When specifying custom styles, you can pass a string or an array of strings. These are the possible strings:
"bold"
"dim"
"italic"
"underline"
"inverse"
"strikethrough"
"reset"
"hidden"
"visible"
Custom colors & styles
let currentBgColor = 'red'; console;console;console;currentBgColor = 'cyan'console;
colorboy.addDefaults(functions = true, colors = true, styles = true)
Adds the default colorboy colors & styles. Takes three optional arguments, all true by default.
functions
: Whether to add the default functions prototypes (color
,bgColor
andstyle
)colors
: Whether to add the default colors prototypes (red
,green
, etc)styles
: Whether to add the default styles prototypes (bold
,underline
, etc)
colorboy.addColor(name, options)
Adds a color prototype.
name
: The prototype nameoptions
: Acolor object
(see below)
colorboy.addColorFunction(name, optionsCallback)
name
: The prototype name.options
: A function that returns acolor object
(see below).
color object
An object that defines colors and styles, in this format:
{
color: COLOR,
bgColor: COLOR,
style: STYLE
}
Dev instructions
Get started
- Install Node.js
- Run
npm install
To test, run:
npm run test
Publish new version
- Update CHANGELOG.md
- Bump the version number, commit and tag:
npm version <version>
- Publish to npm:
npm publish
- Create GitHub release with release notes