Background coloring functions that apply background colors to terminal output using ANSI escape codes for highlighting and emphasis.
Basic background colors using the standard 16-color palette.
/**
* Apply black background color
* @param str - Text to highlight
* @returns Text with black background and ANSI codes
*/
function bgBlack(str: string): string;
/**
* Apply red background color
* @param str - Text to highlight
* @returns Text with red background and ANSI codes
*/
function bgRed(str: string): string;
/**
* Apply green background color
* @param str - Text to highlight
* @returns Text with green background and ANSI codes
*/
function bgGreen(str: string): string;
/**
* Apply yellow background color
* @param str - Text to highlight
* @returns Text with yellow background and ANSI codes
*/
function bgYellow(str: string): string;
/**
* Apply blue background color
* @param str - Text to highlight
* @returns Text with blue background and ANSI codes
*/
function bgBlue(str: string): string;
/**
* Apply magenta background color
* @param str - Text to highlight
* @returns Text with magenta background and ANSI codes
*/
function bgMagenta(str: string): string;
/**
* Apply cyan background color
* @param str - Text to highlight
* @returns Text with cyan background and ANSI codes
*/
function bgCyan(str: string): string;
/**
* Apply white background color
* @param str - Text to highlight
* @returns Text with white background and ANSI codes
*/
function bgWhite(str: string): string;
/**
* Apply gray background color
* @param str - Text to highlight
* @returns Text with gray background and ANSI codes
*/
function bgGray(str: string): string;
/**
* Apply grey background color (alias for bgGray)
* @param str - Text to highlight
* @returns Text with grey background and ANSI codes
*/
function bgGrey(str: string): string;Bright variants of background colors for enhanced contrast and visibility.
/**
* Apply bright red background color
* @param str - Text to highlight
* @returns Text with bright red background and ANSI codes
*/
function bgBrightRed(str: string): string;
/**
* Apply bright green background color
* @param str - Text to highlight
* @returns Text with bright green background and ANSI codes
*/
function bgBrightGreen(str: string): string;
/**
* Apply bright yellow background color
* @param str - Text to highlight
* @returns Text with bright yellow background and ANSI codes
*/
function bgBrightYellow(str: string): string;
/**
* Apply bright blue background color
* @param str - Text to highlight
* @returns Text with bright blue background and ANSI codes
*/
function bgBrightBlue(str: string): string;
/**
* Apply bright magenta background color
* @param str - Text to highlight
* @returns Text with bright magenta background and ANSI codes
*/
function bgBrightMagenta(str: string): string;
/**
* Apply bright cyan background color
* @param str - Text to highlight
* @returns Text with bright cyan background and ANSI codes
*/
function bgBrightCyan(str: string): string;
/**
* Apply bright white background color
* @param str - Text to highlight
* @returns Text with bright white background and ANSI codes
*/
function bgBrightWhite(str: string): string;Legacy aliases for backward compatibility (deprecated but still functional).
/**
* Legacy alias for bgBlack
* @param str - Text to highlight
* @returns Text with black background and ANSI codes
*/
function blackBG(str: string): string;
/**
* Legacy alias for bgRed
* @param str - Text to highlight
* @returns Text with red background and ANSI codes
*/
function redBG(str: string): string;
/**
* Legacy alias for bgGreen
* @param str - Text to highlight
* @returns Text with green background and ANSI codes
*/
function greenBG(str: string): string;
/**
* Legacy alias for bgYellow
* @param str - Text to highlight
* @returns Text with yellow background and ANSI codes
*/
function yellowBG(str: string): string;
/**
* Legacy alias for bgBlue
* @param str - Text to highlight
* @returns Text with blue background and ANSI codes
*/
function blueBG(str: string): string;
/**
* Legacy alias for bgMagenta
* @param str - Text to highlight
* @returns Text with magenta background and ANSI codes
*/
function magentaBG(str: string): string;
/**
* Legacy alias for bgCyan
* @param str - Text to highlight
* @returns Text with cyan background and ANSI codes
*/
function cyanBG(str: string): string;
/**
* Legacy alias for bgWhite
* @param str - Text to highlight
* @returns Text with white background and ANSI codes
*/
function whiteBG(str: string): string;Functional API:
const colors = require('colors/safe');
console.log(colors.bgRed('Error'));
console.log(colors.bgGreen('Success'));
console.log(colors.bgYellow('Warning'));
console.log(colors.bgBrightBlue('Info'));String Prototype API:
const colors = require('colors');
console.log('Error'.bgRed);
console.log('Success'.bgGreen);
console.log('Warning'.bgYellow);
console.log('Info'.bgBrightBlue);Combining with text colors:
const colors = require('colors/safe');
// High contrast combinations
console.log(colors.white.bgRed('White text on red background'));
console.log(colors.black.bgYellow('Black text on yellow background'));
console.log(colors.yellow.bgBlue('Yellow text on blue background'));When using the default import, all background color functions are available as getters on String.prototype:
interface String {
bgBlack: string;
bgRed: string;
bgGreen: string;
bgYellow: string;
bgBlue: string;
bgMagenta: string;
bgCyan: string;
bgWhite: string;
bgGray: string;
bgGrey: string;
bgBrightRed: string;
bgBrightGreen: string;
bgBrightYellow: string;
bgBrightBlue: string;
bgBrightMagenta: string;
bgBrightCyan: string;
bgBrightWhite: string;
blackBG: string;
redBG: string;
greenBG: string;
yellowBG: string;
blueBG: string;
magentaBG: string;
cyanBG: string;
whiteBG: string;
}