Text coloring functions that apply foreground colors to terminal output using ANSI escape codes.
Basic 16-color palette supported by most terminals.
/**
* Apply black text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function black(str: string): string;
/**
* Apply red text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function red(str: string): string;
/**
* Apply green text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function green(str: string): string;
/**
* Apply yellow text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function yellow(str: string): string;
/**
* Apply blue text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function blue(str: string): string;
/**
* Apply magenta text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function magenta(str: string): string;
/**
* Apply cyan text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function cyan(str: string): string;
/**
* Apply white text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function white(str: string): string;
/**
* Apply gray text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function gray(str: string): string;
/**
* Apply grey text color (alias for gray)
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function grey(str: string): string;Bright variants of standard colors for enhanced visibility.
/**
* Apply bright red text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightRed(str: string): string;
/**
* Apply bright green text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightGreen(str: string): string;
/**
* Apply bright yellow text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightYellow(str: string): string;
/**
* Apply bright blue text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightBlue(str: string): string;
/**
* Apply bright magenta text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightMagenta(str: string): string;
/**
* Apply bright cyan text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightCyan(str: string): string;
/**
* Apply bright white text color
* @param str - Text to color
* @returns Colored text with ANSI codes
*/
function brightWhite(str: string): string;Functional API:
const colors = require('colors/safe');
console.log(colors.red('Error message'));
console.log(colors.green('Success message'));
console.log(colors.yellow('Warning message'));
console.log(colors.brightBlue('Info message'));String Prototype API:
const colors = require('colors');
console.log('Error message'.red);
console.log('Success message'.green);
console.log('Warning message'.yellow);
console.log('Info message'.brightBlue);Chaining with other styles:
const colors = require('colors/safe');
// Combine color with styles
console.log(colors.red.bold('Bold red text'));
console.log(colors.blue.underline('Underlined blue text'));When using the default import, all text color functions are available as getters on String.prototype:
interface String {
black: string;
red: string;
green: string;
yellow: string;
blue: string;
magenta: string;
cyan: string;
white: string;
gray: string;
grey: string;
brightRed: string;
brightGreen: string;
brightYellow: string;
brightBlue: string;
brightMagenta: string;
brightCyan: string;
brightWhite: string;
}