我在 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' 背景色为白色
相关推荐
q***64974 分钟前
SpringSecurity踢出指定用户
android·前端·后端
undsky5 分钟前
【RuoYi-Eggjs】:把 MyBatis 带到 Node.js
node.js
q***76667 分钟前
SpringSecurity 实现token 认证
android·前端·后端
llxxyy卢8 分钟前
xss-maps(1-12)尝试思路过关加源码分析
前端·xss
小璞12 分钟前
一、React Fiber 架构与任务调度详解
前端·react.js·前端框架
小璞12 分钟前
四、虚拟 DOM 与 Diff 算法:架构设计的智慧
前端·react.js·前端框架
南蓝13 分钟前
【AI 日记】调用大模型的时候如何按照 sse 格式输出
前端·人工智能
一树论15 分钟前
浏览器插件开发经验分享二:如何处理日期控件
前端·javascript
小璞15 分钟前
六、React 并发模式:让应用"感觉"更快的架构智慧
前端·react.js·架构
Yanni4Night17 分钟前
LogTape:零依赖的现代JavaScript日志解决方案
前端·javascript