Class

StyledString

StyledString(text)

Constructor

# new StyledString(text)

StyledString provides methods to apply various ANSI color and style options to text strings. It implements the ColorizeOptions interface and proxies native string methods to the underlying text. This class allows for chaining of styling methods and easy application of colors and styles to text.

A class that extends string functionality with ANSI color and style options.

Parameters:
Name Type Description
text string

The initial text string to be styled.

Implements:
  • ColorizeOptions

View Source strings.ts, line 4

Members

# bgBlack

Getter that returns a new StyledString with black background color.

Applies black background color to the text.

View Source strings.ts, line 99

StyledString

# bgBlack

Getter that returns a new StyledString with black background color.

Applies black background color to the text.

View Source strings.ts, line 559

# bgBlue

Getter that returns a new StyledString with blue background color.

Applies blue background color to the text.

View Source strings.ts, line 119

StyledString

# bgBlue

Getter that returns a new StyledString with blue background color.

Applies blue background color to the text.

View Source strings.ts, line 583

# bgBrightBlack

Getter that returns a new StyledString with bright black background color.

Applies bright black (gray) background color to the text.

View Source strings.ts, line 139

StyledString

# bgBrightBlack

Getter that returns a new StyledString with bright black background color.

Applies bright black (gray) background color to the text.

View Source strings.ts, line 607

# bgBrightBlue

Getter that returns a new StyledString with bright blue background color.

Applies bright blue background color to the text.

View Source strings.ts, line 159

StyledString

# bgBrightBlue

Getter that returns a new StyledString with bright blue background color.

Applies bright blue background color to the text.

View Source strings.ts, line 631

# bgBrightCyan

Getter that returns a new StyledString with bright cyan background color.

Applies bright cyan background color to the text.

View Source strings.ts, line 169

StyledString

# bgBrightCyan

Getter that returns a new StyledString with bright cyan background color.

Applies bright cyan background color to the text.

View Source strings.ts, line 643

# bgBrightGreen

Getter that returns a new StyledString with bright green background color.

Applies bright green background color to the text.

View Source strings.ts, line 149

StyledString

# bgBrightGreen

Getter that returns a new StyledString with bright green background color.

Applies bright green background color to the text.

View Source strings.ts, line 619

# bgBrightMagenta

Getter that returns a new StyledString with bright magenta background color.

Applies bright magenta background color to the text.

View Source strings.ts, line 164

StyledString

# bgBrightMagenta

Getter that returns a new StyledString with bright magenta background color.

Applies bright magenta background color to the text.

View Source strings.ts, line 637

# bgBrightRed

Getter that returns a new StyledString with bright red background color.

Applies bright red background color to the text.

View Source strings.ts, line 144

StyledString

# bgBrightRed

Getter that returns a new StyledString with bright red background color.

Applies bright red background color to the text.

View Source strings.ts, line 613

# bgBrightWhite

Getter that returns a new StyledString with bright white background color.

Applies bright white background color to the text.

View Source strings.ts, line 174

StyledString

# bgBrightWhite

Getter that returns a new StyledString with bright white background color.

Applies bright white background color to the text.

View Source strings.ts, line 649

# bgBrightYellow

Getter that returns a new StyledString with bright yellow background color.

Applies bright yellow background color to the text.

View Source strings.ts, line 154

StyledString

# bgBrightYellow

Getter that returns a new StyledString with bright yellow background color.

Applies bright yellow background color to the text.

View Source strings.ts, line 625

# bgCyan

Getter that returns a new StyledString with cyan background color.

Applies cyan background color to the text.

View Source strings.ts, line 129

StyledString

# bgCyan

Getter that returns a new StyledString with cyan background color.

Applies cyan background color to the text.

View Source strings.ts, line 595

# bgGreen

Getter that returns a new StyledString with green background color.

Applies green background color to the text.

View Source strings.ts, line 109

StyledString

# bgGreen

Getter that returns a new StyledString with green background color.

Applies green background color to the text.

View Source strings.ts, line 571

# bgMagenta

Getter that returns a new StyledString with magenta background color.

Applies magenta background color to the text.

View Source strings.ts, line 124

StyledString

# bgMagenta

Getter that returns a new StyledString with magenta background color.

Applies magenta background color to the text.

View Source strings.ts, line 589

# bgRed

Getter that returns a new StyledString with red background color.

Applies red background color to the text.

View Source strings.ts, line 104

StyledString

# bgRed

Getter that returns a new StyledString with red background color.

Applies red background color to the text.

View Source strings.ts, line 565

# bgWhite

Getter that returns a new StyledString with white background color.

Applies white background color to the text.

View Source strings.ts, line 134

StyledString

# bgWhite

Getter that returns a new StyledString with white background color.

Applies white background color to the text.

View Source strings.ts, line 601

# bgYellow

Getter that returns a new StyledString with yellow background color.

Applies yellow background color to the text.

View Source strings.ts, line 114

StyledString

# bgYellow

Getter that returns a new StyledString with yellow background color.

Applies yellow background color to the text.

View Source strings.ts, line 577

# black

Getter that returns a new StyledString with black foreground color.

Applies black color to the text.

View Source strings.ts, line 19

StyledString

# black

Getter that returns a new StyledString with black foreground color.

Applies black color to the text.

View Source strings.ts, line 463

Getter that returns a new StyledString with blinking style.

Applies blinking style to the text.

View Source strings.ts, line 204

StyledString

Getter that returns a new StyledString with blinking style.

Applies blinking style to the text.

View Source strings.ts, line 685

# blue

Getter that returns a new StyledString with blue foreground color.

Applies blue color to the text.

View Source strings.ts, line 39

StyledString

# blue

Getter that returns a new StyledString with blue foreground color.

Applies blue color to the text.

View Source strings.ts, line 487

# bold

Getter that returns a new StyledString with bold style.

Applies bold style to the text.

View Source strings.ts, line 184

StyledString

# bold

Getter that returns a new StyledString with bold style.

Applies bold style to the text.

View Source strings.ts, line 661

# brightBlack

Getter that returns a new StyledString with bright black foreground color.

Applies bright black (gray) color to the text.

View Source strings.ts, line 59

StyledString

# brightBlack

Getter that returns a new StyledString with bright black foreground color.

Applies bright black (gray) color to the text.

View Source strings.ts, line 511

# brightBlue

Getter that returns a new StyledString with bright blue foreground color.

Applies bright blue color to the text.

View Source strings.ts, line 79

StyledString

# brightBlue

Getter that returns a new StyledString with bright blue foreground color.

Applies bright blue color to the text.

View Source strings.ts, line 535

# brightCyan

Getter that returns a new StyledString with bright cyan foreground color.

Applies bright cyan color to the text.

View Source strings.ts, line 89

StyledString

# brightCyan

Getter that returns a new StyledString with bright cyan foreground color.

Applies bright cyan color to the text.

View Source strings.ts, line 547

# brightGreen

Getter that returns a new StyledString with bright green foreground color.

Applies bright green color to the text.

View Source strings.ts, line 69

StyledString

# brightGreen

Getter that returns a new StyledString with bright green foreground color.

Applies bright green color to the text.

View Source strings.ts, line 523

# brightMagenta

Getter that returns a new StyledString with bright magenta foreground color.

Applies bright magenta color to the text.

View Source strings.ts, line 84

StyledString

# brightMagenta

Getter that returns a new StyledString with bright magenta foreground color.

Applies bright magenta color to the text.

View Source strings.ts, line 541

# brightRed

Getter that returns a new StyledString with bright red foreground color.

Applies bright red color to the text.

View Source strings.ts, line 64

StyledString

# brightRed

Getter that returns a new StyledString with bright red foreground color.

Applies bright red color to the text.

View Source strings.ts, line 517

# brightWhite

Getter that returns a new StyledString with bright white foreground color.

Applies bright white color to the text.

View Source strings.ts, line 94

StyledString

# brightWhite

Getter that returns a new StyledString with bright white foreground color.

Applies bright white color to the text.

View Source strings.ts, line 553

# brightYellow

Getter that returns a new StyledString with bright yellow foreground color.

Applies bright yellow color to the text.

View Source strings.ts, line 74

StyledString

# brightYellow

Getter that returns a new StyledString with bright yellow foreground color.

Applies bright yellow color to the text.

View Source strings.ts, line 529

# cyan

Getter that returns a new StyledString with cyan foreground color.

Applies cyan color to the text.

View Source strings.ts, line 49

StyledString

# cyan

Getter that returns a new StyledString with cyan foreground color.

Applies cyan color to the text.

View Source strings.ts, line 499

# dim

Getter that returns a new StyledString with dim style.

Applies dim (decreased intensity) style to the text.

View Source strings.ts, line 189

StyledString

# dim

Getter that returns a new StyledString with dim style.

Applies dim (decreased intensity) style to the text.

View Source strings.ts, line 667

# doubleUnderline

Getter that returns a new StyledString with double underline style.

Applies double underline style to the text.

View Source strings.ts, line 224

StyledString

# doubleUnderline

Getter that returns a new StyledString with double underline style.

Applies double underline style to the text.

View Source strings.ts, line 709

# green

Getter that returns a new StyledString with green foreground color.

Applies green color to the text.

View Source strings.ts, line 29

StyledString

# green

Getter that returns a new StyledString with green foreground color.

Applies green color to the text.

View Source strings.ts, line 475

# hidden

Getter that returns a new StyledString with hidden text.

Hides the text (same color as background).

View Source strings.ts, line 214

StyledString

# hidden

Getter that returns a new StyledString with hidden text.

Hides the text (same color as background).

View Source strings.ts, line 697

# inverse

Getter that returns a new StyledString with inverted colors.

Inverts the foreground and background colors of the text.

View Source strings.ts, line 209

StyledString

# inverse

Getter that returns a new StyledString with inverted colors.

Inverts the foreground and background colors of the text.

View Source strings.ts, line 691

# italic

Getter that returns a new StyledString with italic style.

Applies italic style to the text.

View Source strings.ts, line 194

StyledString

# italic

Getter that returns a new StyledString with italic style.

Applies italic style to the text.

View Source strings.ts, line 673

# magenta

Getter that returns a new StyledString with magenta foreground color.

Applies magenta color to the text.

View Source strings.ts, line 44

StyledString

# magenta

Getter that returns a new StyledString with magenta foreground color.

Applies magenta color to the text.

View Source strings.ts, line 493

Getter that returns a new StyledString with blinking style removed.

Removes blinking style from the text.

View Source strings.ts, line 244

StyledString

Getter that returns a new StyledString with blinking style removed.

Removes blinking style from the text.

View Source strings.ts, line 733

# noHidden

Getter that returns a new StyledString with hidden style removed.

Removes hidden style from the text.

View Source strings.ts, line 254

StyledString

# noHidden

Getter that returns a new StyledString with hidden style removed.

Removes hidden style from the text.

View Source strings.ts, line 745

# noInverse

Getter that returns a new StyledString with color inversion removed.

Removes color inversion from the text.

View Source strings.ts, line 249

StyledString

# noInverse

Getter that returns a new StyledString with color inversion removed.

Removes color inversion from the text.

View Source strings.ts, line 739

# noItalicOrFraktur

Getter that returns a new StyledString with italic or fraktur style removed.

Removes italic or fraktur style from the text.

View Source strings.ts, line 234

StyledString

# noItalicOrFraktur

Getter that returns a new StyledString with italic or fraktur style removed.

Removes italic or fraktur style from the text.

View Source strings.ts, line 721

# noStrikethrough

Getter that returns a new StyledString with strikethrough style removed.

Removes strikethrough style from the text.

View Source strings.ts, line 259

StyledString

# noStrikethrough

Getter that returns a new StyledString with strikethrough style removed.

Removes strikethrough style from the text.

View Source strings.ts, line 751

# noUnderline

Getter that returns a new StyledString with underline style removed.

Removes underline style from the text.

View Source strings.ts, line 239

StyledString

# noUnderline

Getter that returns a new StyledString with underline style removed.

Removes underline style from the text.

View Source strings.ts, line 727

# normalColor

Getter that returns a new StyledString with normal color intensity.

Resets the text color to normal intensity.

View Source strings.ts, line 229

StyledString

# normalColor

Getter that returns a new StyledString with normal color intensity.

Resets the text color to normal intensity.

View Source strings.ts, line 715

# red

Getter that returns a new StyledString with red foreground color.

Applies red color to the text.

View Source strings.ts, line 24

StyledString

# red

Getter that returns a new StyledString with red foreground color.

Applies red color to the text.

View Source strings.ts, line 469

# reset

Getter that returns a new StyledString with all styling reset.

Resets all styling applied to the text.

View Source strings.ts, line 179

StyledString

# reset

Getter that returns a new StyledString with all styling reset.

Resets all styling applied to the text.

View Source strings.ts, line 655

# strikethrough

Getter that returns a new StyledString with strikethrough style.

Applies strikethrough style to the text.

View Source strings.ts, line 219

StyledString

# strikethrough

Getter that returns a new StyledString with strikethrough style.

Applies strikethrough style to the text.

View Source strings.ts, line 703

# text

The styled text as a regular string.

The text

View Source strings.ts, line 264

string

# text

The styled text as a regular string.

The text

View Source strings.ts, line 757

# underline

Getter that returns a new StyledString with underline style.

Applies underline style to the text.

View Source strings.ts, line 199

StyledString

# underline

Getter that returns a new StyledString with underline style.

Applies underline style to the text.

View Source strings.ts, line 679

# white

Getter that returns a new StyledString with white foreground color.

Applies white color to the text.

View Source strings.ts, line 54

StyledString

# white

Getter that returns a new StyledString with white foreground color.

Applies white color to the text.

View Source strings.ts, line 505

# yellow

Getter that returns a new StyledString with yellow foreground color.

Applies yellow color to the text.

View Source strings.ts, line 34

StyledString

# yellow

Getter that returns a new StyledString with yellow foreground color.

Applies yellow color to the text.

View Source strings.ts, line 481

Methods

# background(n) → {StyledString}

Sets the background color of the text using ANSI color codes.

Applies a background color to the text.

Parameters:
Name Type Description
n number

The ANSI color code for the background color.

View Source strings.ts, line 788

The StyledString instance with the background color applied.

StyledString

# bgColor256(n) → {StyledString}

Sets the background color using the extended 256-color palette.

Applies a 256-color background color to the text.

Parameters:
Name Type Description
n number

The color number from the 256-color palette.

View Source strings.ts, line 812

The StyledString instance with the 256-color background applied.

StyledString

# bgRgb(r, g, b) → {StyledString}

Sets the background color using RGB values.

Applies an RGB background color to the text.

Parameters:
Name Type Description
r number

The red component (0-255).

g number

The green component (0-255).

b number

The blue component (0-255).

View Source strings.ts, line 832

The StyledString instance with the RGB background color applied.

StyledString

# clear() → {StyledString}

Removes all ANSI color and style codes from the text.

Clears all styling from the text.

View Source strings.ts, line 764

The StyledString instance with cleared styling.

StyledString

# color256(n) → {StyledString}

Sets the text color using the extended 256-color palette.

Applies a 256-color foreground color to the text.

Parameters:
Name Type Description
n number

The color number from the 256-color palette.

View Source strings.ts, line 804

The StyledString instance with the 256-color foreground applied.

StyledString

# foreground(n) → {StyledString}

Sets the text color using ANSI color codes.

Applies a foreground color to the text.

Parameters:
Name Type Description
n number

The ANSI color code for the foreground color.

View Source strings.ts, line 780

The StyledString instance with the foreground color applied.

StyledString

# raw(rawAnsi) → {StyledString}

Allows direct application of ANSI escape sequences to the text.

Applies raw ANSI codes to the text.

Parameters:
Name Type Description
rawAnsi string

The raw ANSI escape sequence to apply.

View Source strings.ts, line 772

The StyledString instance with the raw ANSI code applied.

StyledString

# rgb(r, g, b) → {StyledString}

Sets the text color using RGB values.

Applies an RGB foreground color to the text.

Parameters:
Name Type Description
r number

The red component (0-255).

g number

The green component (0-255).

b number

The blue component (0-255).

View Source strings.ts, line 822

The StyledString instance with the RGB foreground color applied.

StyledString

# style(n) → {StyledString}

Sets text styles such as bold, italic, or underline using ANSI style codes.

Applies a text style to the string.

Parameters:
Name Type Description
n number | string

The style code or key from the styles object.

View Source strings.ts, line 796

The StyledString instance with the style applied.

StyledString

# toString() → {string}

Returns the underlying text with all applied styling.

Converts the StyledString to a regular string.

View Source strings.ts, line 839

The styled text as a regular string.

string

# static style(t) → {StyledString}

This function takes a string and returns a StyledString object, which is an enhanced version of the original string with additional methods for applying various ANSI color and style options. It sets up a mapper object with methods for different styling operations and then defines properties on the text string to make these methods accessible.

Applies styling to a given text string.

Parameters:
Name Type Description
t Array.<string>

The input text to be styled.

View Source strings.ts, line 402

A StyledString object with additional styling methods.

StyledString