Need help with chalk?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

chalk
15.5K Stars 595 Forks MIT License 303 Commits 9 Opened issues

Description

🖍 Terminal string styling done right

Services available

!
?

Need anything else?

Contributors list

No Data



Chalk


Terminal string styling done right

Build Status Coverage Status npm dependents Downloads XO code style TypeScript-ready run on repl.it





Highlights

Install

$ npm install chalk

Usage

const chalk = require('chalk');

console.log(chalk.blue('Hello world!'));

Chalk comes with an easy to use composable API where you just chain and nest the styles you want.

const chalk = require('chalk');
const log = console.log;

// Combine styled and normal strings log(chalk.blue('Hello') + ' World' + chalk.red('!'));

// Compose multiple styles using the chainable API log(chalk.blue.bgRed.bold('Hello world!'));

// Pass in multiple arguments log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));

// Nest styles log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));

// Nest styles of the same type even (color, underline, background) log(chalk.green( 'I am a green line ' + chalk.blue.underline.bold('with a blue substring') + ' that becomes green again!' ));

// ES2015 template literal log(CPU: ${chalk.red('90%')} RAM: ${chalk.green('40%')} DISK: ${chalk.yellow('70%')});

// ES2015 tagged template literal log(chalkCPU: {red ${cpu.totalPercent}%} RAM: {green ${ram.used / ram.total * 100}%} DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%});

// Use RGB colors in terminal emulators that support it. log(chalk.keyword('orange')('Yay for orange colored text!')); log(chalk.rgb(123, 45, 67).underline('Underlined reddish color')); log(chalk.hex('#DEADED').bold('Bold gray!'));

Easily define your own themes:

const chalk = require('chalk');

const error = chalk.bold.red; const warning = chalk.keyword('orange');

console.log(error('Error!')); console.log(warning('Warning!'));

Take advantage of console.log string substitution:

const name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
//=> 'Hello Sindre'

API

chalk.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.