一个骗子黑客

Lie付 Hacker.jp

npm chalkはこう使う

npm chalk

コンソール出力に色づけできる、chalk。

こんな感じにチェーンで呼べるので、呼ぶ場所で都度呼んでもいいんだけど、

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

coffeescript

こんな感じで

chalk = require 'chalk'


print = (msg, type = 'log')
    _c = chalk
    switch type
        when 'warn' then _c = chalk.yellow
        when 'error' then _c = chalk.red
        when 'log' then _c = chalk.gray

    console.log _c(msg)

print('Hello, World!')

とかやると楽。

呼び出すタイプでスタイルを決めておいて、利用する形です。 複雑なチェーンであればあるほど、楽になる。