chalk is a clean and focused alternative to colors , which is currently the most popular
string styling module, but it has serious deficiencies like extending
String.prototype which causes all kinds of problems. Although there are other ones, they either do too much or not enough.
1
|
npm install chalk |
Why
- Doesn’t extend String.prototype
- Expressive API
- Clean and focused
- Auto-detects color support
- Actively maintained
- Used by 150+ modules
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
var chalk = require( 'chalk' ); // style a string console.log( chalk.blue( 'Hello world!' ) ); // combine styled and normal strings console.log( chalk.blue( 'Hello' ), 'World' + chalk.red( '!' ) ); // compose multiple styles using the chainable API console.log( chalk.blue.bgRed.bold( 'Hello world!' ) ); // nest styles console.log( chalk.red( 'Hello' , chalk.underline.bgBlue( 'world' ) + '!' ) ); // pass in multiple arguments console.log( chalk.blue( 'Hello' , 'World!' , 'Foo' , 'bar' , 'biz' , 'baz' ) ); |
sindresorhus/chalk was written by Sindre Sorhus @sindresorhus who’s got a ton of other opensource work. Thank you!