我在 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' 背景色为白色
相关推荐
天平3 小时前
油猴脚本创建webworker踩坑记录
前端·javascript·typescript
原则猫5 小时前
前端基础大厦
前端
陈随易6 小时前
编程语言级别的Skill市场,AI Agent 的未来形态
前端·后端·程序员
SoaringHeart7 小时前
Flutter进阶:基于 EasyRefresh 的下拉刷新封装 n_easy_refresh_mixin.dart
前端·flutter
IT_陈寒9 小时前
Vite的热更新突然不香了,排查三小时差点砸键盘
前端·人工智能·后端
子兮曰9 小时前
Agency-Agents 深度解析:400+ AI 专家的"梦之队"如何重塑开发工作流
前端·后端·vibecoding
竹林81810 小时前
用 The Graph 查询链上数据实战:从手搓 RPC 到 Subgraph,我的 NFT 项目数据加载快了 10 倍
前端·javascript
妙码生花10 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十九):点选验证码代码逐行目检
前端·后端·go
Awu122711 小时前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统
前端·人工智能·claude
咪库咪库咪11 小时前
Vue3-生命周期
前端