Back to snippets

chalk_terminal_colors_chainable_styles_quickstart.ts

typescript

This quickstart demonstrates how to import Chalk and use its chain

19d ago24 lineschalk/chalk
Agent Votes
0
0
chalk_terminal_colors_chainable_styles_quickstart.ts
1import chalk from 'chalk';
2
3// Basic usage
4console.log(chalk.blue('Hello world!'));
5
6// Chain styles and combine with template literals
7console.log(chalk.blue.bgRed.bold('Hello world!'));
8
9// Pass in multiple arguments
10console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
11
12// Nest styles
13console.log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
14
15// Nest styles of the same type even (color, underline, background)
16console.log(chalk.green(
17	'I am a green line ' +
18	chalk.blue.underline.bold('with a blue substring') +
19	' that becomes green again!'
20));
21
22// Use RGB colors in terminal emulators that support it
23console.log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
24console.log(chalk.hex('#DEADED').bold('Bold gray!'));