Easily set your terminal text color & styles.
- No wonky prototype method-chain API.
- Automatic color support detection.
- Up to 2x faster than alternatives.
NO_COLOR
friendly. ✅
Here's the first example to get you started.
import { blue, bold, underline } from "colorette"
console.log(
blue("I'm blue"),
bold(blue("da ba dee")),
underline(bold(blue("da ba daa")))
)
Here's an example using template literals.
console.log(`
There's a ${underline(blue("house"))},
With a ${bold(blue("window"))},
And a ${blue("corvette")}
And everything is blue
`)
Of course, you can nest styles without breaking existing color sequences.
console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))
Need to override automatic color detection? You can do that too.
import { createColors } from "colorette"
const { blue } = createColors({ useColor: false })
console.log(blue("Blue? Nope, nah"))
npm install colorette
See all supported colors.
blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m
true
if your terminal supports color, false
otherwise. Used internally and handled for you, but exposed for convenience.
Create a reusable instance of Colorette. Color support is automatically detected, but you can override it by setting the useColor
boolean property.
import { createColors } from "colorette"
const { blue } = createColors({ useColor: false })
You can override automatic color detection from the CLI too via NO_COLOR=
or FORCE_COLOR=
.
$ FORCE_COLOR= node example.js | ./consumer.js
Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers |
---|---|---|---|---|
black | bgBlack | blackBright | bgBlackBright | dim |
red | bgRed | redBright | bgRedBright | bold |
green | bgGreen | greenBright | bgGreenBright | hidden |
yellow | bgYellow | yellowBright | bgYellowBright | italic |
blue | bgBlue | blueBright | bgBlueBright | underline |
magenta | bgMagenta | magentaBright | bgMagentaBright | |
cyan | bgCyan | cyanBright | bgCyanBright | reset |
white | bgWhite | whiteBright | bgWhiteBright | |
gray |
npm --prefix bench start