Top Related Projects
🖍 Terminal string styling done right
The fastest Node.js library for formatting terminal text with ANSI colors~!
get colors in your node.js console
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染
Quick Overview
Colorette is a minimalist library for adding ANSI color and style to the terminal output in Node.js. It provides a simple and lightweight way to add color and formatting to console logs and other terminal-based applications.
Pros
- Lightweight: Colorette is a small and efficient library, weighing in at just a few kilobytes.
- Cross-platform: The library works across different operating systems and terminal emulators, ensuring consistent color and style output.
- Easy to use: The API is straightforward and intuitive, making it easy to integrate into existing projects.
- Actively maintained: The project is actively maintained, with regular updates and bug fixes.
Cons
- Limited functionality: Colorette is a focused library, providing only basic color and style functionality. It may not have all the features of more comprehensive terminal styling libraries.
- Dependency on ANSI escape codes: The library relies on ANSI escape codes, which may not be supported by all terminal emulators or environments.
- No support for advanced formatting: Colorette does not provide support for more advanced terminal formatting, such as cursor positioning or cursor movement.
- No support for custom color palettes: The library uses a predefined set of colors and styles, and does not allow for the definition of custom color palettes.
Code Examples
Here are a few examples of how to use Colorette in your Node.js projects:
const { green, red, blue, bold } = require('colorette');
console.log(green('This text is green'));
console.log(red('This text is red'));
console.log(blue(bold('This text is blue and bold')));
This code demonstrates the basic usage of Colorette, allowing you to easily add color and style to your console output.
const { cyan, underline } = require('colorette');
console.log(`${cyan('Cyan')} ${underline('underlined')} text`);
This example shows how to combine multiple styles using Colorette's functions.
const { dim, italic } = require('colorette');
console.log(`${dim('Dimmed')} ${italic('italic')} text`);
This code snippet demonstrates the use of the dim
and italic
styles provided by Colorette.
Getting Started
To get started with Colorette, simply install the package using npm or yarn:
npm install colorette
or
yarn add colorette
Once installed, you can import the library and use its functions to add color and style to your console output:
const { green, red, blue, bold } = require('colorette');
console.log(green('This text is green'));
console.log(red('This text is red'));
console.log(blue(bold('This text is blue and bold')));
You can also selectively import the functions you need, as shown in the previous code examples.
That's the basic setup for using Colorette in your Node.js projects. Refer to the project's documentation for more advanced usage and configuration options.
Competitor Comparisons
🖍 Terminal string styling done right
Pros of Chalk
- More extensive color and style options, including background colors and text decorations
- Supports nested and complex styling with a chainable API
- Wider community adoption and more frequent updates
Cons of Chalk
- Larger package size and more dependencies
- Slightly more complex API for basic use cases
- May be overkill for simple color needs
Code Comparison
Colorette:
import { red, bold } from 'colorette'
console.log(red(bold('Hello, world!')))
Chalk:
import chalk from 'chalk'
console.log(chalk.red.bold('Hello, world!'))
Both libraries provide similar basic functionality for adding color to console output. Colorette uses individual imports for colors and styles, while Chalk uses a chainable API. Chalk offers more advanced features like nested styles and background colors, which may be beneficial for complex styling needs.
Colorette is lighter and more focused on simplicity, making it a good choice for projects with basic color requirements. Chalk, on the other hand, provides a more comprehensive set of features and is widely adopted in the community, making it suitable for projects that need extensive styling options or want to leverage its ecosystem.
The fastest Node.js library for formatting terminal text with ANSI colors~!
Pros of kleur
- Smaller bundle size (1.1kB vs 3.4kB for colorette)
- Supports nested color combinations
- Slightly faster performance in some benchmarks
Cons of kleur
- Less extensive color support (16 colors vs 256 for colorette)
- No support for background colors
- Requires manual import of specific color functions
Code Comparison
kleur:
import { red, bold } from 'kleur';
console.log(red().bold('Hello, world!'));
colorette:
import { red, bold } from 'colorette';
console.log(bold(red('Hello, world!')));
Both libraries provide similar functionality for adding color to console output, but with slight differences in syntax and implementation. kleur uses method chaining for combining styles, while colorette uses nested function calls.
kleur focuses on minimalism and performance, making it a good choice for projects where bundle size is critical. colorette offers more extensive color support and background color options, making it suitable for projects requiring more advanced styling capabilities.
Ultimately, the choice between these libraries depends on the specific needs of your project, considering factors such as bundle size, color range requirements, and syntax preferences.
get colors in your node.js console
Pros of colors.js
- More extensive color and styling options, including background colors and text decorations
- Supports custom color themes and color detection
- Has a longer history and larger user base, potentially offering more community support
Cons of colors.js
- Larger package size and more dependencies
- More complex API with additional features that may not be necessary for all use cases
- Has faced controversy due to past intentional breaking changes
Code Comparison
colors.js:
const colors = require('colors');
console.log('Hello'.green); // outputs green text
console.log('World'.blue.bgRed); // blue text with red background
console.log(colors.rainbow('Multicolor!')); // rainbow text
colorette:
const { green, blue, bgRed } = require('colorette');
console.log(green('Hello')); // outputs green text
console.log(blue(bgRed('World'))); // blue text with red background
// No built-in rainbow function
Both libraries provide similar basic functionality for coloring console output, but colors.js offers more advanced features out of the box. colorette focuses on simplicity and performance, with a smaller footprint and fewer features. The choice between them depends on the specific needs of your project, balancing between feature richness and simplicity.
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台 颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染
Pros of Color
- More comprehensive feature set, including background colors and styles
- Supports Windows console and can auto-detect color support
- Provides methods for custom color definitions and RGB/HSL
Cons of Color
- Larger package size due to more features
- Slightly more complex API compared to Colorette's simplicity
- May have higher performance overhead for basic use cases
Code Comparison
Colorette:
import { red, bold } from 'colorette'
console.log(red(bold('Hello, World!')))
Color:
import "github.com/gookit/color"
color.Red.Bold.Println("Hello, World!")
Summary
Colorette is a lightweight, focused library for adding color to terminal output in JavaScript. It offers a simple API and small package size, making it ideal for projects where minimal dependencies are preferred.
Color, on the other hand, is a more feature-rich Go library that provides extensive color and styling options, including background colors and custom color definitions. It also offers better Windows support and auto-detection of color capabilities.
While Color offers more functionality, it comes at the cost of a larger package size and potentially higher complexity. Colorette's simplicity may be preferable for projects with basic color needs, while Color is better suited for applications requiring advanced terminal styling options.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð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
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
Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers |
---|---|---|---|---|
black | bgBlack | blackBright | bgBlackBright | dim |
red | bgRed | redBright | bgRedBright | bold |
green | bgGreen | greenBright | bgGreenBright | hidden |
yellow | bgYellow | yellowBright | bgYellowBright | italic |
blue | bgBlue | blueBright | bgBlueBright | underline |
magenta | bgMagenta | magentaBright | bgMagentaBright | |
cyan | bgCyan | cyanBright | bgCyanBright | reset |
white | bgWhite | whiteBright | bgWhiteBright | |
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
Top Related Projects
🖍 Terminal string styling done right
The fastest Node.js library for formatting terminal text with ANSI colors~!
get colors in your node.js console
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot