2.6.1 • Published 6 years ago

turbocolor v2.6.1

Weekly downloads
2,584
License
MIT
Repository
github
Last release
6 years ago

Turbocolor

CI Coverage npm.io

Turbocolor is a Node.js library for colorizing text using ANSI escape sequences.

Features

Installation

Usage

const tc = require("turbocolor")

Using styles.

console.log(tc.red("Hello!"))

Chaining styles.

console.log(tc.red.bold("Turbo") + tc.bgRed.white("Color"))

Using template literals.

console.log(`
  ${tc.bold("Score")}: ${100}
  Lives: ${tc.red.inverse(1)}
  Level: ${tc.bgCyan.black.inverse(2)}
`)

Nesting styles.

console.log(`Normal ${tc.bold(`Bold ${tc.red("Bold/Red")} Bold`)} Normal`)

Using console.log string substitution.

console.log(tc.green("Total: $%f"), 1.99)

API

tc.style.style...(string)

Every style function can be chained or nested with one another and when invoked, will return the given string argument wrapped in the corresponding ANSI escape codes. Style precedence is determined by chaining order in a first-come, first-served basis. This means that tc.red.green.blue is reduced to tc.red.

tc.Styles

Turbocolor exports ANSI escape codes for each available style. Use them if you want to stylize console output manually.

const { Styles } = require("turbocolor")

console.log(`${Styles.red.open}Red${Styles.red.close}`)

tc.enabled

Color support is automatically enabled if your terminal supports it, but you can toggle it on/off as needed.

const tc = require("turbocolor")

tc.enabled = false

Styles

Turbocolor only supports the regular color set at the moment. If you want to use the high intensity variations or need 256 color/Truecolor support, please use chalk instead.

ColorsBackground ColorsModifiers
blackbgBlackdim
redbgRedbold
greenbgGreenhidden
yellowbgYellowitalic
bluebgBlueunderline
magentabgMagentainverse
cyanbgCyanstrikethrough
whitebgWhitereset
gray

Benchmark Results

All tests run on a 2.4GHz Intel Core i7 CPU with 16 GB memory.

npm i -C bench && node bench

License

Turbocolor is MIT licensed. See LICENSE.