Chalk

There are many wonderful node modules that adhere to Unix philosophy:

"Write programs that do one thing and do it well."

Out of many such one such elegant module is chalk thanks to Sindre Sorhus for that.

Whenever one wants to color the terminal, as in styling the strings on the console the first module that would come to mind is colors.js but one of the major drawbacks with that being it extending String.portotye or be these problems.

Installing chalk is like any other module: npm install --save chalk

Apart from allow the normal styling syntax, it also provides multiple styles, nested styles and multiple arguments.

For example:

1
2
3
4
5
var chalk = require('chalk');

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

console.log(  chalk.red('Hello', chalk.underline('world') + '!')  );

Here is a simple snippet for printing all of the styles it provides:

1
2
3
4
5
6
7
var chalk = require('chalk');

Object.keys(chalk.styles).forEach(function(style) {
    if( style !== "reset") {
      process.stdout.write(chalk[style](style) + ' ');
    }
});

gif FTW!?

chalk

Until next week, happy coloring!

chalk-colors

Suggest a module

Comments