chalk-terminal
v1.0.1
Published
A chalk-like terminal string styling utility for Node.js, allowing colored and styled console output.
Maintainers
Readme
chalk-terminal
🇻🇳 Phiên bản Tiếng Việt
Giới thiệu
chalk-terminal là một thư viện Node.js nhỏ gọn giúp tô màu và định dạng văn bản trong terminal bằng mã ANSI. Thư viện hỗ trợ:
Màu cơ bản (red, green, blue, …) và màu sáng (brightRed, brightGreen, …)
Màu 24-bit (RGB) và hex
Tên màu tuỳ chỉnh (orange, pink, teal, …)
Hiệu ứng tô đậm (bold), nghiêng (italic), gạch chân (underline), ẩn (hidden), hoán vị (inverse), v.v.
Chuỗi chain-style như chalk.red.bold.underline("text")
Hỗ trợ template literal và ép kiểu tự động
Cài đặt
npm install chalk-terminal
hoặc
yarn add chalk-terminal
Sử dụng cơ bản
const chalk = require('chalk-terminal');
console.log(chalk.red('Hello world!')); console.log(chalk.green.bold('Success!')); console.log(chalk.blue.underline('Link: http://example.com'));
Sử dụng RGB, HEX và tên màu
// RGB console.log(chalk.rgb(255, 165, 0)('Orange by RGB'));
// HEX console.log(chalk.hex('#ff00ff')('Magenta by HEX'));
// Tên màu console.log(chalk.name('teal')('Teal named color'));
Hiệu ứng nền (Background)
console.log(chalk.bgBlue.white('White on Blue background')); console.log(chalk.bgName('gold').black('Black text on Gold'));
API chính
Phương thức Miêu tả
chalk.colorName(text) Tô màu theo ANSI cơ bản chalk.rgb(r,g,b)(text) Tô màu 24-bit theo giá trị RGB chalk.hex(hexCode)(text) Tô màu theo mã HEX chalk.name(colorName) Tô màu theo tên định sẵn trong thư viện chalk.bgColor Tô màu nền tương ứng (vd: bgRed, bgRgb…) chalk.bold(text) In đậm chalk.italic(text) In nghiêng chalk.underline(text) Gạch chân chalk.inverse(text) Hoán vị (đổi màu nền và chữ) chalk.reset Reset tất cả hiệu ứng
Tích hợp Template Literals
const name = 'Alice';
console.log(chalk.redXin chào ${name}, chúc bạn một ngày tốt lành!);
Tùy biến nâng cao
Bạn có thể kết hợp nhiều hiệu ứng:
console.log(chalk.bold.underline.rgb(128,0,128)('Custom Purple Bold Underline'));
Giấy phép
Thư viện chalk-terminal được cấp phép theo MIT License.
🇬🇧 English Version
chalk-terminal
Introduction
chalk-terminal is a lightweight Node.js library for coloring and styling terminal text with ANSI codes. Features:
Basic colors (red, green, blue, …) and bright variants (brightRed, brightGreen, …)
24-bit color support (RGB) and HEX
Custom named colors (orange, pink, teal, …)
Text styles: bold, italic, underline, hidden, inverse, etc.
Chainable syntax: chalk.red.bold.underline("text")
Template literal support and automatic string coercion
Installation
npm install chalk-terminal
or
yarn add chalk-terminal
Basic Usage
const chalk = require('chalk-terminal');
console.log(chalk.red('Hello world!')); console.log(chalk.green.bold('Success!')); console.log(chalk.blue.underline('Link: http://example.com'));
Using RGB, HEX and Named Colors
// RGB console.log(chalk.rgb(255, 165, 0)('Orange by RGB'));
// HEX console.log(chalk.hex('#ff00ff')('Magenta by HEX'));
// Named Color console.log(chalk.name('teal')('Teal named color'));
Background Styles
console.log(chalk.bgBlue.white('White on Blue background')); console.log(chalk.bgName('gold').black('Black text on Gold background'));
Core API
Method Description
chalk.colorName(text) Apply basic ANSI color chalk.rgb(r,g,b)(text) Apply 24-bit RGB color chalk.hex(hexCode)(text) Apply HEX color chalk.name(colorName) Apply custom named color from the library chalk.bgColor Background color (e.g., bgRed, bgRgb, etc.) chalk.bold(text) Bold text chalk.italic(text) Italic text chalk.underline(text) Underlined text chalk.inverse(text) Inverse (swap foreground and background) chalk.reset Reset all styles
Template Literal Integration
const name = 'Alice';
console.log(chalk.redHello ${name}, have a great day!);
Advanced Customization
Combine multiple styles:
console.log(chalk.bold.underline.rgb(128,0,128)('Custom Purple Bold Underline'));
License
The chalk-terminal library is licensed under the MIT License.
