我在 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' 背景色为白色
相关推荐
sugar__salt几秒前
三列布局与 TypeScript 工具类型 Pick / Omit / Partial 详解
前端·javascript·typescript
IMPYLH23 分钟前
HTML 的 <html> 元素
前端·javascript·html
IT_陈寒26 分钟前
SpringBoot自动配置的坑,把我整不会了
前端·人工智能·后端
赵大仁32 分钟前
Human-in-the-loop:前端确认流与后端幂等
前端·后端·ai·agent·人机协作
恋猫de小郭35 分钟前
超好用 R8 Configuration Analyzer, 优化你的 App 大小和内存
android·前端·flutter
赖龙10 小时前
pnpm vs npm
前端·npm·node.js
学如逆水,不进则退11 小时前
在线免费音频剪辑:NBTools 可视化波形裁剪 MP3/WAV,本地处理免上传
前端·音视频
Mh11 小时前
虚拟滚动真的比普通滚动性能更好吗?
前端·javascript·性能优化
pe7er11 小时前
React + Ant Design 中的 IME (输入法合成)安全输入组件
前端
Super 含12 小时前
Android 启动优化(二):TTID、TTFD 与 Macrobenchmark 启动性能测量
前端