github:https://github.com/chalk/chalk
1、安装
npm install chalk
2、Api
生成样式的效果,与样式的顺序不存在关系,如果存在冲突,则取最后一个样式
chalk.<style>[.<style>...](string, [string...])
Example: chalk.red.bold.underline('Hello', 'world');
const chalk = require('chalk')
const log = console.log;
log(chalk.red.bold.bgWhite('hello','world','chalk'))
3、输出结果看,chalk有些样式未得到广泛支持,如underline\bold
4、chalk最新的5.0版本不再支持require方式引入,如果想在node中使用,目前只能使用4.0版本
5、chalk的level
Level | Description |
---|---|
0 | All colors disabled |
1 | Basic color support (16 colors) |
2 | 256 color support |
3 | Truecolor support (16 million colors) |
示例
const chalk = require('chalk')
chalk.level = 0
console.log(chalk.red('hello'))
//颜色会被level覆盖掉
ES中可以直接new
import {Chalk} from 'chalk';
const customChalk = new Chalk({level: 0});