Skip to content

chalk

介绍

chalk 是一个用于在终端中输出彩色文本的 JavaScript 库。它提供了一种简单的方式来为控制台输出添加颜色和样式,使得日志信息更加醒目和易于阅读。

安装

bash
npm i chalk

使用

js
import chalk from 'chalk'

console.log(chalk.blue('Hello world!')) // 输出蓝色文本
console.log(chalk.red.bold('This is an error message!')) // 输出红色加粗文本
console.log(chalk.green.underline('This is a success message!')) // 输出绿色下划线文本
console.log(chalk.yellow('Warning: This is a warning message!')) // 输出黄色文本
console.log(chalk.bgCyan('This text has a cyan background!')) // 输出带有青色背景的文本
console.log(chalk.hex('#FF5733')('This is a custom color!')) // 输出自定义颜色文本

基于 MIT 许可发布