write-format
v1.0.124
Published
A library to write in color or style
Readme
write-format
A lightweight and flexible library to write text in color or with different styles to the console.
Installation
You can install this library using npm or yarn:
npm install write-formatUsage
Basic Example
const { write } = require("write-format");
write("Hello, World!", { fg: "blue", effects: ["bold"] });Available Styles and Colors
Text Styles:
boldfaintitalicunderlinedinversestrikethrough
Foreground Colors:
black,red,green,yellow,blue,magenta,cyan,whitebrightBlack,brightRed,brightGreen,brightYellow,brightBlue,brightMagenta,brightCyan,brightWhitepalette(number)for 256-color supportrgb(r, g, b)for true color support
Background Colors:
bgBlack,bgRed,bgGreen,bgYellow,bgBlue,bgMagenta,bgCyan,bgWhitebgBrightBlack,bgBrightRed,bgBrightGreen,bgBrightYellow,bgBrightBlue,bgBrightMagenta,bgBrightCyan,bgBrightWhitepalette(number)for 256-color supportrgb(r, g, b)for true color support
Advanced Usage
Customizing Colors
You can specify RGB or 256-color palette values:
write("Custom Palette", { fg: { palette: 82 } });
write("Custom RGB", { fg: { rgb: [255, 165, 0] } });Formatting and Writing Text
const { Cformat, write } = require("write-format");
console.log(
Cformat("Stylized text", {
fg: "magenta",
bg: "yellow",
effects: ["bold", "underlined"],
})
);
write("Formatted output to stdout", { fg: "cyan" });Stripping ANSI Codes
const { stripAnsi } = require("write-format");
const cleanText = stripAnsi("\x1b[31mRed Text\x1b[0m");
console.log(cleanText); // Outputs: Red TextConfiguration
You can customize settings:
const { configure } = require("write-format");
configure({
timestamp: true, // Show timestamps in logs
level: "debug", // Set the minimum log level
});Compatibility
This library is compatible with Node.js (v12+ recommended). It works in any terminal that supports ANSI escape codes.
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.
