# console-enhance **Repository Path**: yang_yong_qian/console-enhance ## Basic Information - **Project Name**: console-enhance - **Description**: console.log 增强库 - **Primary Language**: JavaScript - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-05 - **Last Updated**: 2025-12-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # yangyonqian-console-enhance 一个强大的 console 增强库,支持颜色输出和链式调用 API,提供完整的 TypeScript 类型支持。 ## 特性 - 🎨 支持 8 种文字颜色和 8 种背景颜色 - 🔗 支持链式调用,如 `console.blue.bgRed('text')` - 📘 完整的 TypeScript 类型提示 - 🌐 支持 Node.js 和浏览器环境 - 🚀 零配置,导入即用 ## 安装 ```bash npm install yangyonqian-console-enhance ``` ## 使用方法 ### 基本使用 ```typescript import "yangyonqian-console-enhance"; // 基本颜色 console.blue("这是蓝色文字"); console.red("这是红色文字"); console.green("这是绿色文字"); // 背景颜色(自动使用白色文字) console.bgRed("这是红色背景,文字自动为白色"); console.bgBlue("这是蓝色背景,文字自动为白色"); // 链式调用(文字颜色 + 背景颜色) console.blue.bgRed("这是红底蓝字"); console.red.bgYellow("这是黄底红字"); console.green.bgBlue("这是蓝底绿字"); ``` ### 支持的颜色 #### 文字颜色 - `black` - 黑色 - `red` - 红色 - `green` - 绿色 - `yellow` - 黄色 - `blue` - 蓝色 - `magenta` - 洋红色 - `cyan` - 青色 - `white` - 白色 #### 背景颜色 - `bgBlack` - 黑色背景 - `bgRed` - 红色背景 - `bgGreen` - 绿色背景 - `bgYellow` - 黄色背景 - `bgBlue` - 蓝色背景 - `bgMagenta` - 洋红色背景 - `bgCyan` - 青色背景 - `bgWhite` - 白色背景 ### 使用其他 console 方法 ```typescript console.blue.info("这是 info 方法 - 蓝色"); console.red.warn("这是 warn 方法 - 红色"); console.green.error("这是 error 方法 - 绿色"); console.yellow.debug("这是 debug 方法 - 黄色"); ``` ### 链式调用示例 ```typescript // 单色文字 console.blue("蓝色文字"); // 单色背景 console.bgRed("红色背景"); // 文字颜色 + 背景颜色 console.blue.bgRed("红底蓝字"); console.red.bgYellow("黄底红字"); // 可以继续链式调用(后面的会覆盖前面的) console.blue.bgRed.green("注意:最后设置的颜色会生效"); ``` ## API ### 导入方式 ```typescript // 方式 1: 直接导入(自动增强全局 console) import "yangyonqian-console-enhance"; // 方式 2: 导入并获取增强的 console import enhanceConsole from "yangyonqian-console-enhance"; const myConsole = enhanceConsole(console); ``` ### 类型定义 所有颜色方法都支持完整的 TypeScript 类型提示,包括: - 文字颜色方法 - 背景颜色方法 - console 标准方法(log, info, warn, error, debug) ## 示例 ```typescript import "yangyonqian-console-enhance"; // 基本使用 console.blue("Hello World"); console.red("Error message"); console.green("Success message"); // 链式调用 console.blue.bgRed("Important message"); console.yellow.bgBlue("Warning message"); // 使用其他方法 console.cyan.info("Info with cyan color"); console.magenta.error("Error with magenta color"); ``` ## 环境支持 - ✅ Node.js (所有版本) - ✅ 浏览器 (现代浏览器) - ✅ TypeScript ## 特性说明 - **自动白色文字**:当只设置背景颜色时,文字颜色会自动设置为白色,确保在深色背景上的可读性 - **自定义文字颜色**:如果同时设置了文字颜色和背景颜色,将使用指定的文字颜色 ## 注意事项 1. 颜色效果在支持 ANSI 转义序列的终端中才能正常显示 2. 在 Windows 的旧版 CMD 中可能无法正常显示颜色 3. 建议在支持颜色的终端中使用(如 VS Code 终端、iTerm2、Windows Terminal 等) 4. 当只使用背景颜色时,文字会自动变为白色以确保可读性 ## 开发 ```bash # 安装依赖 npm install # 编译 npm run build # 测试 npm test ``` ## 发布 ```bash # 构建项目 npm run build # 发布到 npm npm publish ``` ## License MIT