本文主要是介绍插件中的chalk的用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
chalk是什么
chalk是一个颜色的插件。可以通过chalk.blue(‘hello world’)来改变颜色,但是我并没有式样成功,有待验证。
可以参考 npm chalk官网
- 简单用法
$ npm install chalk
const chalk = require('chalk');console.log(chalk.blue('Hello world!'));
const chalk = require('chalk');
const log = console.log;// Combine styled and normal strings
log(chalk.blue('Hello') + 'World' + chalk.red('!'));// Compose multiple styles using the chainable API
log(chalk.blue.bgRed.bold('Hello world!'));// Pass in multiple arguments
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));// Nest styles
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));// Nest styles of the same type even (color, underline, background)
log(chalk.green('I am a green line ' +chalk.blue.underline.bold('with a blue substring') +' that becomes green again!'
));// ES2015 template literal
log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);// ES2015 tagged template literal
log(chalk`
CPU: {red ${cpu.totalPercent}%}
RAM: {green ${ram.used / ram.total * 100}%}
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
`);// Use RGB colors in terminal emulators that support it.
log(chalk.keyword('orange')('Yay for orange colored text!'));
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));
这篇关于插件中的chalk的用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!