or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

background-colors.mdindex.mdspecial-effects.mdtext-colors.mdtext-styles.mdutility-functions.md
tile.json

tessl/npm-colors

Terminal text coloring and styling library for Node.js applications that adds colors, background colors, and text formatting effects to console output

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/colors@1.4.x

To install, run

npx @tessl/cli install tessl/npm-colors@1.4.0

index.mddocs/

Colors

Colors 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.

Package Information

  • Package Name: colors
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install colors

Core Imports

Standard 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';

Basic Usage

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'));

Architecture

Colors.js is built around several key components:

  • Style System: ANSI escape code mappings for colors and text effects
  • Chainable Interface: Fluent API supporting method chaining for combining effects
  • Dual API: String prototype extension for convenience, functional API for safety
  • Theme Support: Custom color schemes for application-specific styling
  • Terminal Detection: Automatic color capability detection with override options
  • Special Effects: Advanced text transformations like rainbow colors and zalgo text

Capabilities

Text Colors

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;

Text Colors

Background Colors

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;

Background Colors

Text Styles

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;

Text Styles

Special Effects

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;

Special Effects

Utility Functions

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;

Utility Functions

Global Types

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)
}