dyejs
v1.0.2
Published
A lightweight and flexible terminal string styling library for Node.js and TypeScript. Supports colors, gradients (foreground/background), custom themes, and colorized logging.
Maintainers
Readme
dyejs
A lightweight and flexible JavaScript/TypeScript library for terminal string styling, gradients, and themes. dyejs makes it easy to add color, style, and effects to your CLI output with a simple and intuitive API.
Features
Supported Colors
Basic Foreground Colors
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
Bright Foreground Colors
- blackBright
- redBright
- greenBright
- yellowBright
- blueBright
- magentaBright
- cyanBright
- whiteBright
Aliases
- gray
- grey
Background Colors
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
Bright Background Colors
- bgBlackBright
- bgRedBright
- bgGreenBright
- bgYellowBright
- bgBlueBright
- bgMagentaBright
- bgCyanBright
- bgWhiteBright
Background Aliases
- bgGray
- bgGrey
Gradients
You can use any of the above color names or hex codes (e.g., #ff0000, #00ff00, #0000ff) for gradients.
Use gradient, gradientFg, or gradientBg to apply gradients to text.
Installation
npm install dyejsUsage
Using Icons & Emojis
You can include Unicode emojis and icons directly in your strings:
console.log(dye("✅ Success!", "green"));
console.log(dye("⚠️ Warning!", "yellow"));
console.log(dye("❌ Error!", "red"));
console.log(rainbow("🌈 Rainbow!"));
console.log(blink("🚨 Blinking Alert!"));
await typewriter("⌛ Loading...");Animated Effects
Add animation and dynamic effects to your terminal output:
import { rainbowAnimate, blinkAnimate, typewriter } from "dyejs";
// Animated rainbow text
await rainbowAnimate("Animated Rainbow!");
// Simulated blinking text
await blinkAnimate("Simulated Blinking!");
// Typewriter effect
await typewriter("Loading...");Basic Dyeing
import { dye } from "dyejs";
console.log(dye("Hello, World!", "red"));Using Gradients
import { gradient } from "dyejs";
console.log(gradient("Gradient Text", ["red", "yellow", "green"]));Gradients with Hex Codes
You can use hex color codes for more precise gradients:
import { gradientFg, gradientBg } from "dyejs";
console.log(gradientFg("Hex Gradient", ["#ff0000", "#00ff00", "#0000ff"])); // Foreground gradient
console.log(
gradientBg("Background Hex Gradient", ["#ff0000", "#00ff00", "#0000ff"])
); // Background gradientBoth gradientFg and gradientBg accept arrays of named colors or hex codes.
Theming
import { dye, themes } from "dyejs";
themes.defineTheme("error", (msg) => dye.red(msg));
themes.defineTheme("info", (msg) => dye.blue(msg));
themes.defineTheme("success", (msg) => dye.green(msg));
console.log(dye("This is an error", "error"));Logger
import { logger } from "dyejs";
logger.info("Information message");
logger.error("Error message");
logger.success("Success message");API Reference
rainbowAnimate(text, options?)
text(string): The text to animate with a moving rainbow effect.options(object): Optional.{ delay?: number, repeat?: number }for speed and cycles.
blinkAnimate(text, options?)
text(string): The text to animate with a blinking effect.options(object): Optional.{ delay?: number, repeat?: number }for speed and cycles.
typewriter(text, delay?)
text(string): The text to animate as a typewriter.delay(number): Optional. Delay in ms between characters (default: 50).
dye(text, color)
text(string): The text to dye (colorize).color(string): The color or theme key to apply.
gradient(text, colors)
text(string): The text to apply the gradient to.colors(string[]): Array of color names for the gradient.
themes.defineTheme(name, fn)
name(string): Theme key.fn(function): Function that returns a styled string.
logger
logger.info(message)logger.error(message)logger.success(message)
Animated Effects
import { rainbowAnimate, blinkAnimate, typewriter } from "dyejs";
// Animated rainbow text
await rainbowAnimate("Animated Rainbow!");
// Simulated blinking text
await blinkAnimate("Simulated Blinking!");
// Typewriter effect
await typewriter("Loading...");License
MIT
- Terminal string styling with colors and styles
- Foreground and background gradients (named and hex colors)
- Custom color themes
- Colorized logger (info, error, success)
- Animated effects: rainbow, blinking, and typewriter (simulated in all terminals)
- TypeScript support
