or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-features.mdbackground-colors.mdbright-colors.mdconfiguration.mdindex.mdsymbols.mdtext-colors.mdtext-modifiers.md
tile.json

tessl/npm-ansi-colors

A high-performance terminal string styling library providing chainable ANSI color codes and text formatting for Node.js CLI applications.

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

To install, run

npx @tessl/cli install tessl/npm-ansi-colors@4.1.0

index.mddocs/

ANSI Colors

ANSI Colors is a high-performance terminal string styling library for Node.js applications that provides chainable ANSI color codes and text formatting. It enables developers to add colors, background colors, text modifiers (bold, italic, underline), and visual effects to command-line interfaces and console output with blazing fast performance and zero dependencies.

Package Information

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

Core Imports

const colors = require('ansi-colors');

ES Modules:

import colors from 'ansi-colors';

Basic Usage

const colors = require('ansi-colors');

// Single styles
console.log(colors.red('Error message'));
console.log(colors.green('Success message'));
console.log(colors.bold('Important text'));

// Chained styles  
console.log(colors.bold.red('Bold red text'));
console.log(colors.blue.underline('Blue underlined text'));

// Nested colors
console.log(colors.yellow(`Warning: ${colors.red.bold('critical')} issue detected`));

Architecture

ANSI Colors is built around several key components:

  • Chainable API: All style functions return functions that can be chained together for complex formatting
  • High Performance: Optimized ANSI code generation with zero dependencies for maximum speed
  • Color Detection: Automatic color support detection with manual override capabilities
  • Safe Implementation: Doesn't modify String.prototype, avoiding conflicts with other libraries
  • Platform Support: Cross-platform Unicode symbols with automatic platform detection

Capabilities

Text Colors

Standard foreground color functions for terminal text styling.

// Standard colors
const black: StyleFunction;
const red: StyleFunction;  
const green: StyleFunction;
const yellow: StyleFunction;
const blue: StyleFunction;
const magenta: StyleFunction;
const cyan: StyleFunction;
const white: StyleFunction;
const gray: StyleFunction;
const grey: StyleFunction; // alias for gray

interface StyleFunction {
  (text: string): string;
  // All other style functions are also available as properties for chaining
}

Text Colors

Background Colors

Background color functions for terminal text styling.

// Background colors  
const bgBlack: StyleFunction;
const bgRed: StyleFunction;
const bgGreen: StyleFunction;
const bgYellow: StyleFunction;
const bgBlue: StyleFunction;
const bgMagenta: StyleFunction;
const bgCyan: StyleFunction;
const bgWhite: StyleFunction;

Background Colors

Text Modifiers

Text formatting modifiers like bold, italic, and underline.

// Text modifiers
const reset: StyleFunction;
const bold: StyleFunction;
const dim: StyleFunction;
const italic: StyleFunction;
const underline: StyleFunction;
const inverse: StyleFunction;
const hidden: StyleFunction;
const strikethrough: StyleFunction;

Text Modifiers

Bright Colors

Bright/intense color variants for both foreground and background.

// Bright foreground colors
const blackBright: StyleFunction;
const redBright: StyleFunction;
const greenBright: StyleFunction;
const yellowBright: StyleFunction;
const blueBright: StyleFunction;
const magentaBright: StyleFunction;
const cyanBright: StyleFunction;
const whiteBright: StyleFunction;

// Bright background colors  
const bgBlackBright: StyleFunction;
const bgRedBright: StyleFunction;
const bgGreenBright: StyleFunction;
const bgYellowBright: StyleFunction;
const bgBlueBright: StyleFunction;
const bgMagentaBright: StyleFunction;
const bgCyanBright: StyleFunction;
const bgWhiteBright: StyleFunction;

Bright Colors

Configuration and Control

Global settings and utilities for controlling color behavior.

// Configuration properties
let enabled: boolean;
let visible: boolean;

// Regular expression for matching ANSI codes
const ansiRegex: RegExp;

// Utility functions
function hasColor(str: string): boolean;
function hasAnsi(str: string): boolean; // alias for hasColor
function stripColor(str: string): string;
function unstyle(str: string): string; // alias for stripColor
function noop(str: string): string;

Configuration

Advanced Features

Custom styling, theming, and instance creation capabilities.

// Custom styling functions
function alias(name: string, style: string | StyleFunction): void;
function theme(themeObject: Record<string, string | StyleFunction>): typeof colors;
function create(): typeof colors;

// Additional utility aliases
const none: StyleFunction; // alias for noop
const clear: StyleFunction; // alias for noop

Advanced Features

Platform Symbols

Cross-platform Unicode symbols for CLI applications.

const symbols: {
  // Core symbols available on all platforms
  ballotDisabled: string;
  ballotOff: string;
  ballotOn: string;
  bullet: string;
  bulletWhite: string;
  fullBlock: string;
  heart: string;
  identicalTo: string;
  line: string;
  mark: string;
  middot: string;
  minus: string;
  multiplication: string;
  obelus: string;
  pencilDownRight: string;
  pencilRight: string;
  pencilUpRight: string;
  percent: string;
  pilcrow2: string;
  pilcrow: string;
  plusMinus: string;
  question: string;
  section: string;
  starsOff: string;
  starsOn: string;
  upDownArrow: string;
  
  // Platform-specific symbols (may be undefined on some platforms)
  ballotCross?: string;
  check: string;
  cross: string;
  ellipsisLarge: string;
  ellipsis: string;
  info: string;
  questionFull?: string;
  questionSmall: string;
  pointer: string;
  pointerSmall: string;
  radioOff: string;
  radioOn: string;
  warning: string;
};

Platform Symbols

Types

interface StyleFunction {
  (text: string): string;
  
  // All style functions are available as chainable properties
  reset: StyleFunction;
  bold: StyleFunction;
  dim: StyleFunction;
  italic: StyleFunction;
  underline: StyleFunction;
  inverse: StyleFunction;
  hidden: StyleFunction;
  strikethrough: StyleFunction;
  
  black: StyleFunction;
  red: StyleFunction;
  green: StyleFunction;
  yellow: StyleFunction;
  blue: StyleFunction;
  magenta: StyleFunction;
  cyan: StyleFunction;
  white: StyleFunction;
  gray: StyleFunction;
  grey: StyleFunction;
  
  blackBright: StyleFunction;
  redBright: StyleFunction;
  greenBright: StyleFunction;
  yellowBright: StyleFunction;
  blueBright: StyleFunction;
  magentaBright: StyleFunction;
  cyanBright: StyleFunction;
  whiteBright: StyleFunction;
  
  bgBlack: StyleFunction;
  bgRed: StyleFunction;
  bgGreen: StyleFunction;
  bgYellow: StyleFunction;
  bgBlue: StyleFunction;
  bgMagenta: StyleFunction;
  bgCyan: StyleFunction;
  bgWhite: StyleFunction;
  
  bgBlackBright: StyleFunction;
  bgRedBright: StyleFunction;
  bgGreenBright: StyleFunction;
  bgYellowBright: StyleFunction;
  bgBlueBright: StyleFunction;
  bgMagentaBright: StyleFunction;
  bgCyanBright: StyleFunction;
  bgWhiteBright: StyleFunction;
}

interface StyleDefinition {
  name: string;
  codes: [number, number];
  open: string;
  close: string;
  regex: RegExp;
  wrap: (input: string, newline?: boolean) => string;
}