Terminal text coloring and styling library for Node.js applications that adds colors, background colors, and text formatting effects to console output
npx @tessl/cli install tessl/npm-colors@1.4.0Colors is a comprehensive terminal text coloring and styling library for Node.js applications that enables developers to add colors, background colors, and text formatting effects to console output. It offers two usage patterns: a chainable API that extends String.prototype for convenient method chaining, and a safer functional API that doesn't modify native objects.
npm install colorsStandard usage (extends String.prototype):
const colors = require('colors');
// or
import colors from 'colors';Safe usage (functional API only):
const colors = require('colors/safe');
// or
import colors from 'colors/safe';String prototype extension (default):
const colors = require('colors');
console.log('Hello World'.red);
console.log('Bold and underlined'.bold.underline);
console.log('Rainbow text'.rainbow);Safe functional API:
const colors = require('colors/safe');
console.log(colors.red('Hello World'));
console.log(colors.bold.underline('Bold and underlined'));
console.log(colors.rainbow('Rainbow text'));Colors.js is built around several key components:
Standard and bright text coloring functions for terminal output.
// Standard colors
function black(str: string): string;
function red(str: string): string;
function green(str: string): string;
function yellow(str: string): string;
function blue(str: string): string;
function magenta(str: string): string;
function cyan(str: string): string;
function white(str: string): string;
function gray(str: string): string;
function grey(str: string): string; // alias for gray
// Bright colors
function brightRed(str: string): string;
function brightGreen(str: string): string;
function brightYellow(str: string): string;
function brightBlue(str: string): string;
function brightMagenta(str: string): string;
function brightCyan(str: string): string;
function brightWhite(str: string): string;Background coloring functions for highlighting text with colored backgrounds.
// Standard background colors
function bgBlack(str: string): string;
function bgRed(str: string): string;
function bgGreen(str: string): string;
function bgYellow(str: string): string;
function bgBlue(str: string): string;
function bgMagenta(str: string): string;
function bgCyan(str: string): string;
function bgWhite(str: string): string;
function bgGray(str: string): string;
function bgGrey(str: string): string; // alias for bgGray
// Bright background colors
function bgBrightRed(str: string): string;
function bgBrightGreen(str: string): string;
function bgBrightYellow(str: string): string;
function bgBrightBlue(str: string): string;
function bgBrightMagenta(str: string): string;
function bgBrightCyan(str: string): string;
function bgBrightWhite(str: string): string;Text formatting and styling functions for enhanced terminal output.
function reset(str: string): string;
function bold(str: string): string;
function dim(str: string): string;
function italic(str: string): string;
function underline(str: string): string;
function inverse(str: string): string;
function hidden(str: string): string;
function strikethrough(str: string): string;Advanced text transformation effects including rainbow colors, zalgo text, and themed patterns.
function rainbow(str: string): string;
function zebra(str: string): string;
function america(str: string): string;
function trap(str?: string): string;
function random(str: string): string;
function zalgo(str?: string, options?: ZalgoOptions): string;Core utility functions for color management, terminal detection, and text processing.
function stripColors(str: string): string;
function strip(str: string): string; // alias for stripColors
function enable(): void;
function disable(): void;
function setTheme(theme: object): void;interface Color {
(text: string): string;
// Chaining support for all color and style functions
strip: Color;
stripColors: Color;
black: Color;
red: Color;
green: Color;
yellow: Color;
blue: Color;
magenta: Color;
cyan: Color;
white: Color;
gray: Color;
grey: Color;
bgBlack: Color;
bgRed: Color;
bgGreen: Color;
bgYellow: Color;
bgBlue: Color;
bgMagenta: Color;
bgCyan: Color;
bgWhite: Color;
reset: Color;
bold: Color;
dim: Color;
italic: Color;
underline: Color;
inverse: Color;
hidden: Color;
strikethrough: Color;
rainbow: Color;
zebra: Color;
america: Color;
trap: Color;
random: Color;
zalgo: Color;
}
interface ZalgoOptions {
up?: boolean;
mid?: boolean;
down?: boolean;
size?: 'mini' | 'maxi' | string;
}
// When using String prototype extension, all methods are available on strings
interface String {
// All color, background, style, and effect methods available
red: string;
bold: string;
rainbow: string;
// ... (complete list in individual capability docs)
}