[go: nahoru, domu]

tree: aff99dba456afab1fb5f82449ad3de720ceb2684 [path history] [tgz]
  1. index.cjs
  2. index.d.ts
  3. index.js
  4. LICENSE.md
  5. package.json
  6. README.md
node_modules/colorette/README.md

Colorette

Easily set the color and style of text in the terminal.

  • 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`))

Feeling adventurous? Try the pipeline operator.

console.log("Da ba dee da ba daa" |> blue |> bold)

Installation

npm install colorette

API

<style>(string)

import { blue } from "colorette"

blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m

See supported styles.

options.enabled

Colorette automatically detects if your terminal can display color, but you can toggle color as needed.

import { options } from "colorette"

options.enabled = false

You can also force the use of color globally by setting FORCE_COLOR= or NO_COLOR= from the CLI.

$ FORCE_COLOR= node example.js >log
$ NO_COLOR= node example.js

Supported styles

ColorsBackground ColorsBright ColorsBright Background ColorsModifiers
blackbgBlackblackBrightbgBlackBrightdim
redbgRedredBrightbgRedBrightbold
greenbgGreengreenBrightbgGreenBrighthidden
yellowbgYellowyellowBrightbgYellowBrightitalic
bluebgBlueblueBrightbgBlueBrightunderline
magentabgMagentamagentaBrightbgMagentaBrightstrikethrough
cyanbgCyancyanBrightbgCyanBrightreset
whitebgWhitewhiteBrightbgWhiteBright
gray

Benchmarks

npm --prefix bench start

License

MIT