我在 NPM 发布了新包: con-colors

链接地址:npmjs.com

con-colors

安装依赖

bash 复制代码
yarn add con-colors

使用

导入:

js 复制代码
import { print } from "con-colors";

使用:

js 复制代码
print.succ("成功的消息");
print.err("失败的消息")

例子:

js 复制代码
import { print } from "con-colors";

for (let i = 0; i < 10; i++) {
    if (i === 6) {
        print.err(`Failure: ${i}. An error has occurred!`)
    }
    print.succ(`Test: ${i}`);
}

其他情况(自定义)

自定义其他颜色,导入颜色函数(colors)

js 复制代码
import { colors, CONSTANT_COLORS } from "con-colors";

使用:

js 复制代码
console.log(colors());

例子:

js 复制代码
import { colors, CONSTANT_COLORS } from "con-colors";

for (let i = 0; i < 10; i++) {
    if (i % 2 === 0) {
        console.log(colors('yellow', `index: ${i}`));
    } else {
        console.log(colors(['cyanBg', CONSTANT_COLORS.red], `index: ${i}`));
    }
}

颜色说明

参数 颜色
'bright' 亮色
'grey' 灰色
'italic' 斜体
'underline' 下划线
'reverse' 反向
'hidden' 隐藏
'black' 黑色
'red' 红色
'green' 绿色
'yellow' 黄色
'blue' 蓝色
'magenta' 品红
'cyan' 青色
'white' 白色
'blackBg' 背景色为黑色
'redBg' 背景色为红色
'greenBg' 背景色为绿色
'yellowBg' 背景色为黄色
'blueBg' 背景色为蓝色
'magentaBg' 背景色为品红
'cyanBg' 背景色为青色
'whiteBg' 背景色为白色
相关推荐
Hyyy1 小时前
理解LLM的基本工作原理:预训练、微调、推理的区别
前端
Gatlin2 小时前
前端逆向与反逆向:一场猫鼠游戏的底层逻辑与实战
前端
Pedantic2 小时前
本地通知(Local Notifications)学习笔记
前端
森蓝情丶2 小时前
我给 AI 搭了个法庭:一个前端仔的 LangGraph 实战全记录
前端·后端
爱勇宝2 小时前
干了近 8 年,一夜之间被裁:AI 时代,程序员最该害怕的不是 AI
前端·后端·程序员
Pedantic3 小时前
Combine 框架学习笔记
前端
runnerdancer3 小时前
Agent如何加载执行Skill的脚本
前端·agent
yingyima3 小时前
VS Code 正则替换技巧:从凌晨3点的服务器报警开始
前端
默_笙3 小时前
🛬 我让 AI 帮我写了一个打飞机游戏,结果 Canvas 把我整不会了
前端·javascript
梯度不陡3 小时前
AI 到底能不能从零写软件?ProgramBench 和 RepoZero 给出了两种答案
前端·javascript·面试