Text formatting and styling functions that apply various visual effects to terminal output using ANSI escape codes.
Fundamental text styling functions for enhanced terminal presentation.
/**
* Reset all styling and colors to default
* @param str - Text to reset
* @returns Text with reset ANSI codes
*/
function reset(str: string): string;
/**
* Apply bold/bright text styling
* @param str - Text to make bold
* @returns Bold text with ANSI codes
*/
function bold(str: string): string;
/**
* Apply dim/faint text styling
* @param str - Text to dim
* @returns Dimmed text with ANSI codes
*/
function dim(str: string): string;
/**
* Apply italic text styling (may not be supported on all terminals)
* @param str - Text to italicize
* @returns Italic text with ANSI codes
*/
function italic(str: string): string;
/**
* Apply underline text styling
* @param str - Text to underline
* @returns Underlined text with ANSI codes
*/
function underline(str: string): string;
/**
* Apply inverse/reverse video styling (swap foreground and background)
* @param str - Text to invert
* @returns Inverted text with ANSI codes
*/
function inverse(str: string): string;
/**
* Apply hidden/invisible text styling
* @param str - Text to hide
* @returns Hidden text with ANSI codes
*/
function hidden(str: string): string;
/**
* Apply strikethrough text styling (may not work with Mac OS Terminal App)
* @param str - Text to strike through
* @returns Strikethrough text with ANSI codes
*/
function strikethrough(str: string): string;Functional API:
const colors = require('colors/safe');
console.log(colors.bold('Important message'));
console.log(colors.underline('Emphasized text'));
console.log(colors.dim('Subtle information'));
console.log(colors.italic('Stylized text'));
console.log(colors.inverse('Highlighted section'));String Prototype API:
const colors = require('colors');
console.log('Important message'.bold);
console.log('Emphasized text'.underline);
console.log('Subtle information'.dim);
console.log('Stylized text'.italic);
console.log('Highlighted section'.inverse);Combining styles with colors:
const colors = require('colors/safe');
// Multiple style combinations
console.log(colors.red.bold('Bold red error'));
console.log(colors.blue.underline.italic('Stylized blue link'));
console.log(colors.yellow.dim('Faded yellow warning'));
console.log(colors.green.bold.underline('Emphasized success'));Advanced combinations:
const colors = require('colors');
// Complex style chains
console.log('Critical Alert'.red.bold.underline.inverse);
console.log('Debug Info'.cyan.dim.italic);
console.log('Deprecated Feature'.yellow.strikethrough);When using the default import, all text style functions are available as getters on String.prototype:
interface String {
reset: string;
bold: string;
dim: string;
italic: string;
underline: string;
inverse: string;
hidden: string;
strikethrough: string;
}