What is yoctocolors?
The yoctocolors npm package is a lightweight library for styling terminal output with colors. It allows developers to easily add color to their console logs, making it easier to distinguish different types of messages.
What are yoctocolors's main functionalities?
Basic Coloring
This feature allows you to colorize text in the terminal. You can use different colors like red, green, and blue to make your console output more readable.
const yoctocolors = require('yoctocolors');
console.log(yoctocolors.red('This is a red text'));
console.log(yoctocolors.green('This is a green text'));
console.log(yoctocolors.blue('This is a blue text'));
Background Coloring
This feature allows you to change the background color of the text in the terminal. It supports various background colors like red, green, and blue.
const yoctocolors = require('yoctocolors');
console.log(yoctocolors.bgRed('This text has a red background'));
console.log(yoctocolors.bgGreen('This text has a green background'));
console.log(yoctocolors.bgBlue('This text has a blue background'));
Text Styling
This feature allows you to style the text with different attributes like bold, italic, and underline to emphasize certain parts of your console output.
const yoctocolors = require('yoctocolors');
console.log(yoctocolors.bold('This is bold text'));
console.log(yoctocolors.italic('This is italic text'));
console.log(yoctocolors.underline('This is underlined text'));
Other packages similar to yoctocolors
chalk
Chalk is a popular library for styling terminal output with colors. It offers a wide range of colors and styles, and it is known for its simplicity and ease of use. Compared to yoctocolors, Chalk has a larger community and more extensive documentation.
colors
Colors is another library for adding color and style to terminal output. It provides a variety of color and style options and is known for its straightforward API. While it offers similar functionalities to yoctocolors, it is slightly larger in size.
ansi-colors
Ansi-colors is a library for styling terminal output with ANSI escape codes. It is lightweight and fast, making it a good alternative to yoctocolors. It offers similar features but focuses more on performance and minimalism.
yoctocolors 🌈
The smallest and fastest command-line coloring package on the internet. Trust me.
The only thing that matters is micro-benchmark performance! ⚡️
Check out Chalk if you want something more mature and comprehensive.
Features
- 4x faster and 5x smaller than nanocolors
- Cat friendly
- An additional color
- Tree-shakeable, not stirred
- Actively maintained (at least for another week)
- No dependencies
Install
npm install yoctocolors
Usage
import * as colors from 'yoctocolors';
console.log(colors.red('Yo!'));
This package does not do color support detection. Check out supports-color
if you need that.
Styles
Modifiers
reset
- Reset the current style.bold
- Make the text bold.dim
- Make the text have lower opacity.italic
- Make the text italic. (Not widely supported)underline
- Put a horizontal line above the text. (Not widely supported)overline
- Put a horizontal line below the text. (Not widely supported)inverse
- Invert background and foreground colors.hidden
- Print the text but make it invisible.strikethrough
- Put a horizontal line through the center of the text. (Not widely supported)
Colors
black
red
green
yellow
blue
magenta
cyan
white
gray
Background colors
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
bgGray
Prior art
Yes
Benchmark
❯ ./test/simple-benchmark.js
nanocolors 31508276 ops/sec
picocolors 32524769 ops/sec
yoctocolors 132894792 ops/sec
Benchmark from nanocolors
Why?
See this discussion.