Socket
Socket
Sign inDemoInstall

colorette

Package Overview
Dependencies
0
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    colorette

Easily set the text color and style in the terminal.


Version published
Maintainers
1
Install size
12.0 kB
Created

Package description

What is colorette?

The colorette npm package is a Node.js library for colorizing text in the terminal. It provides a simple API to add colors and styles to console output, which can be useful for creating more readable and organized logs, command-line tools, and scripts.

What are colorette's main functionalities?

Text coloring

Colorette allows you to color text output in the terminal. You can use predefined color functions to wrap your text and make it appear in the specified color when logged to the console.

const { red, green, blue } = require('colorette');
console.log(red('This is red text'));
console.log(green('This is green text'));
console.log(blue('This is blue text'));

Text styling

In addition to coloring, colorette provides functions to apply various text styles such as bold, underline, and italic.

const { bold, underline, italic } = require('colorette');
console.log(bold('This is bold text'));
console.log(underline('This is underlined text'));
console.log(italic('This is italic text'));

Combining styles

Colorette allows you to combine multiple styles and colors for a single piece of text. This can be useful for highlighting important information or creating visually distinct messages in the terminal.

const { red, bold, bgGreen } = require('colorette');
console.log(bold(red(bgGreen('Red text on green background'))));

Other packages similar to colorette

Readme

Source

Colorette

Easily set the text color and style 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)

See supported styles.

import { blue } from "colorette"

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

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

Keywords

FAQs

Last updated on 07 Sep 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc