# 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
Members
# bgBlack
Getter that returns a new StyledString with black background color.
Applies black background color to the text.
StyledString
# bgBlack
Getter that returns a new StyledString with black background color.
Applies black background color to the text.
# bgBlue
Getter that returns a new StyledString with blue background color.
Applies blue background color to the text.
StyledString
# bgBlue
Getter that returns a new StyledString with blue background color.
Applies blue background color to the text.
# bgBrightBlack
Getter that returns a new StyledString with bright black background color.
Applies bright black (gray) background color to the text.
StyledString
# bgBrightBlack
Getter that returns a new StyledString with bright black background color.
Applies bright black (gray) background color to the text.
# bgBrightBlue
Getter that returns a new StyledString with bright blue background color.
Applies bright blue background color to the text.
StyledString
# bgBrightBlue
Getter that returns a new StyledString with bright blue background color.
Applies bright blue background color to the text.
# bgBrightCyan
Getter that returns a new StyledString with bright cyan background color.
Applies bright cyan background color to the text.
StyledString
# bgBrightCyan
Getter that returns a new StyledString with bright cyan background color.
Applies bright cyan background color to the text.
# bgBrightGreen
Getter that returns a new StyledString with bright green background color.
Applies bright green background color to the text.
StyledString
# bgBrightGreen
Getter that returns a new StyledString with bright green background color.
Applies bright green background color to the text.
# bgBrightMagenta
Getter that returns a new StyledString with bright magenta background color.
Applies bright magenta background color to the text.
StyledString
# bgBrightMagenta
Getter that returns a new StyledString with bright magenta background color.
Applies bright magenta background color to the text.
# bgBrightRed
Getter that returns a new StyledString with bright red background color.
Applies bright red background color to the text.
StyledString
# bgBrightRed
Getter that returns a new StyledString with bright red background color.
Applies bright red background color to the text.
# bgBrightWhite
Getter that returns a new StyledString with bright white background color.
Applies bright white background color to the text.
StyledString
# bgBrightWhite
Getter that returns a new StyledString with bright white background color.
Applies bright white background color to the text.
# bgBrightYellow
Getter that returns a new StyledString with bright yellow background color.
Applies bright yellow background color to the text.
StyledString
# bgBrightYellow
Getter that returns a new StyledString with bright yellow background color.
Applies bright yellow background color to the text.
# bgCyan
Getter that returns a new StyledString with cyan background color.
Applies cyan background color to the text.
StyledString
# bgCyan
Getter that returns a new StyledString with cyan background color.
Applies cyan background color to the text.
# bgGreen
Getter that returns a new StyledString with green background color.
Applies green background color to the text.
StyledString
# bgGreen
Getter that returns a new StyledString with green background color.
Applies green background color to the text.
# bgMagenta
Getter that returns a new StyledString with magenta background color.
Applies magenta background color to the text.
StyledString
# bgMagenta
Getter that returns a new StyledString with magenta background color.
Applies magenta background color to the text.
# bgRed
Getter that returns a new StyledString with red background color.
Applies red background color to the text.
StyledString
# bgRed
Getter that returns a new StyledString with red background color.
Applies red background color to the text.
# bgWhite
Getter that returns a new StyledString with white background color.
Applies white background color to the text.
StyledString
# bgWhite
Getter that returns a new StyledString with white background color.
Applies white background color to the text.
# bgYellow
Getter that returns a new StyledString with yellow background color.
Applies yellow background color to the text.
StyledString
# bgYellow
Getter that returns a new StyledString with yellow background color.
Applies yellow background color to the text.
# black
Getter that returns a new StyledString with black foreground color.
Applies black color to the text.
StyledString
# black
Getter that returns a new StyledString with black foreground color.
Applies black color to the text.
# blink
Getter that returns a new StyledString with blinking style.
Applies blinking style to the text.
StyledString
# blink
Getter that returns a new StyledString with blinking style.
Applies blinking style to the text.
# blue
Getter that returns a new StyledString with blue foreground color.
Applies blue color to the text.
StyledString
# blue
Getter that returns a new StyledString with blue foreground color.
Applies blue color to the text.
StyledString
# bold
Getter that returns a new StyledString with bold style.
Applies bold style to the text.
# brightBlack
Getter that returns a new StyledString with bright black foreground color.
Applies bright black (gray) color to the text.
StyledString
# brightBlack
Getter that returns a new StyledString with bright black foreground color.
Applies bright black (gray) color to the text.
# brightBlue
Getter that returns a new StyledString with bright blue foreground color.
Applies bright blue color to the text.
StyledString
# brightBlue
Getter that returns a new StyledString with bright blue foreground color.
Applies bright blue color to the text.
# brightCyan
Getter that returns a new StyledString with bright cyan foreground color.
Applies bright cyan color to the text.
StyledString
# brightCyan
Getter that returns a new StyledString with bright cyan foreground color.
Applies bright cyan color to the text.
# brightGreen
Getter that returns a new StyledString with bright green foreground color.
Applies bright green color to the text.
StyledString
# brightGreen
Getter that returns a new StyledString with bright green foreground color.
Applies bright green color to the text.
# brightMagenta
Getter that returns a new StyledString with bright magenta foreground color.
Applies bright magenta color to the text.
StyledString
# brightMagenta
Getter that returns a new StyledString with bright magenta foreground color.
Applies bright magenta color to the text.
# brightRed
Getter that returns a new StyledString with bright red foreground color.
Applies bright red color to the text.
StyledString
# brightRed
Getter that returns a new StyledString with bright red foreground color.
Applies bright red color to the text.
# brightWhite
Getter that returns a new StyledString with bright white foreground color.
Applies bright white color to the text.
StyledString
# brightWhite
Getter that returns a new StyledString with bright white foreground color.
Applies bright white color to the text.
# brightYellow
Getter that returns a new StyledString with bright yellow foreground color.
Applies bright yellow color to the text.
StyledString
# brightYellow
Getter that returns a new StyledString with bright yellow foreground color.
Applies bright yellow color to the text.
# cyan
Getter that returns a new StyledString with cyan foreground color.
Applies cyan color to the text.
StyledString
# cyan
Getter that returns a new StyledString with cyan foreground color.
Applies cyan color to the text.
# dim
Getter that returns a new StyledString with dim style.
Applies dim (decreased intensity) style to the text.
StyledString
# dim
Getter that returns a new StyledString with dim style.
Applies dim (decreased intensity) style to the text.
# doubleUnderline
Getter that returns a new StyledString with double underline style.
Applies double underline style to the text.
StyledString
# doubleUnderline
Getter that returns a new StyledString with double underline style.
Applies double underline style to the text.
# green
Getter that returns a new StyledString with green foreground color.
Applies green color to the text.
StyledString
# green
Getter that returns a new StyledString with green foreground color.
Applies green color to the text.
# hidden
Getter that returns a new StyledString with hidden text.
Hides the text (same color as background).
StyledString
# hidden
Getter that returns a new StyledString with hidden text.
Hides the text (same color as background).
# inverse
Getter that returns a new StyledString with inverted colors.
Inverts the foreground and background colors of the text.
StyledString
# inverse
Getter that returns a new StyledString with inverted colors.
Inverts the foreground and background colors of the text.
# italic
Getter that returns a new StyledString with italic style.
Applies italic style to the text.
StyledString
# italic
Getter that returns a new StyledString with italic style.
Applies italic style to the text.
# magenta
Getter that returns a new StyledString with magenta foreground color.
Applies magenta color to the text.
StyledString
# magenta
Getter that returns a new StyledString with magenta foreground color.
Applies magenta color to the text.
# noBlink
Getter that returns a new StyledString with blinking style removed.
Removes blinking style from the text.
StyledString
# noBlink
Getter that returns a new StyledString with blinking style removed.
Removes blinking style from the text.
# noHidden
Getter that returns a new StyledString with hidden style removed.
Removes hidden style from the text.
StyledString
# noHidden
Getter that returns a new StyledString with hidden style removed.
Removes hidden style from the text.
# noInverse
Getter that returns a new StyledString with color inversion removed.
Removes color inversion from the text.
StyledString
# noInverse
Getter that returns a new StyledString with color inversion removed.
Removes color inversion from the text.
# noItalicOrFraktur
Getter that returns a new StyledString with italic or fraktur style removed.
Removes italic or fraktur style from the text.
StyledString
# noItalicOrFraktur
Getter that returns a new StyledString with italic or fraktur style removed.
Removes italic or fraktur style from the text.
# noStrikethrough
Getter that returns a new StyledString with strikethrough style removed.
Removes strikethrough style from the text.
StyledString
# noStrikethrough
Getter that returns a new StyledString with strikethrough style removed.
Removes strikethrough style from the text.
# noUnderline
Getter that returns a new StyledString with underline style removed.
Removes underline style from the text.
StyledString
# noUnderline
Getter that returns a new StyledString with underline style removed.
Removes underline style from the text.
# normalColor
Getter that returns a new StyledString with normal color intensity.
Resets the text color to normal intensity.
StyledString
# normalColor
Getter that returns a new StyledString with normal color intensity.
Resets the text color to normal intensity.
# red
Getter that returns a new StyledString with red foreground color.
Applies red color to the text.
StyledString
# red
Getter that returns a new StyledString with red foreground color.
Applies red color to the text.
# reset
Getter that returns a new StyledString with all styling reset.
Resets all styling applied to the text.
StyledString
# reset
Getter that returns a new StyledString with all styling reset.
Resets all styling applied to the text.
# strikethrough
Getter that returns a new StyledString with strikethrough style.
Applies strikethrough style to the text.
StyledString
# strikethrough
Getter that returns a new StyledString with strikethrough style.
Applies strikethrough style to the text.
# underline
Getter that returns a new StyledString with underline style.
Applies underline style to the text.
StyledString
# underline
Getter that returns a new StyledString with underline style.
Applies underline style to the text.
# white
Getter that returns a new StyledString with white foreground color.
Applies white color to the text.
StyledString
# white
Getter that returns a new StyledString with white foreground color.
Applies white color to the text.
# yellow
Getter that returns a new StyledString with yellow foreground color.
Applies yellow color to the text.
StyledString
# yellow
Getter that returns a new StyledString with yellow foreground color.
Applies yellow color to the text.
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. |
The StyledString instance with the background color applied.
# 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. |
The StyledString instance with the 256-color background applied.
# 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). |
The StyledString instance with the RGB background color applied.
# clear() → {StyledString}
Removes all ANSI color and style codes from the text.
Clears all styling from the text.
The StyledString instance with cleared styling.
# 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. |
The StyledString instance with the 256-color foreground applied.
# 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. |
The StyledString instance with the foreground color applied.
# 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. |
The StyledString instance with the raw ANSI code applied.
# 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). |
The StyledString instance with the RGB foreground color applied.
# 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. |
The StyledString instance with the style applied.
# toString() → {string}
Returns the underlying text with all applied styling.
Converts the StyledString to a regular string.
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. |
A StyledString object with additional styling methods.