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 your terminal text color & styles.


Version published
Weekly downloads
31M
increased by0.32%
Maintainers
1
Install size
16.6 kB
Created
Weekly downloads
 

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 your terminal text color & styles.

  • No dependecies
  • Automatic color support detection
  • Up to 2x faster than alternatives
  • TypeScript support
  • NO_COLOR friendly
  • Node >= 10

Upgrading from Colorette 1.x?

Quickstart

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

You can also nest styles without breaking existing color sequences.

console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))

Need to override terminal color detection? You can do that too.

import { createColors } from "colorette"

const { blue } = createColors({ useColor: false })

console.log(blue("Blue? Nope, nah"))

Installation

npm install colorette

API

<color>()

See all supported colors.

import { blue } from "colorette"

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

createColors()

Override terminal color detection via createColors({ useColor }).

import { createColors } from "colorette"

const { blue } = createColors({ useColor: false })

isColorSupported

true if your terminal supports color, false otherwise. Used internally, but exposed for convenience.

Environment

You can override color detection from the CLI by setting the --no-color or --color flags.

$ ./example.js --no-color | ./consumer.js

Or if you can't use CLI flags, by setting the NO_COLOR= or FORCE_COLOR= environment variables.

$ NO_COLOR= ./example.js | ./consumer.js

Supported colors

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

Benchmarks

npm --prefix bench start
  chalk         1,786,703 ops/sec
  kleur         1,618,960 ops/sec
  colors          646,823 ops/sec
  ansi-colors     786,149 ops/sec
  picocolors    2,871,758 ops/sec
+ colorette     3,002,751 ops/sec

Acknowledgments

Colorette started out in 2015 by @jorgebucaran as a lightweight alternative to Chalk and was introduced originally as Clor. Our terminal color detection logic borrows heavily from @sindresorhus and @Qix- work on Chalk. The idea of slicing strings to clear bleeding sequences was adapted from a similar technique used by @alexeyraspopov in picocolors. Thank you to all our contributors! <3

License

MIT

Keywords

FAQs

Last updated on 14 Jun 2022

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