Skip to main content
styleText - node__util.d.ts - Node documentation
function styleText

Usage in Deno

```typescript import { styleText } from "node:node__util.d.ts"; ```
styleText(): string
Stability: 1.1 - Active development This function returns a formatted text considering the `format` passed. ```js import { styleText } from 'node:util'; const errorMessage = styleText('red', 'Error! Error!'); console.log(errorMessage); ``` `util.inspect.colors` also provides text formats such as `italic`, and `underline` and you can combine both: ```js console.log( util.styleText(['underline', 'italic'], 'My italic underlined message'), ); ``` When passing an array of formats, the order of the format applied is left to right so the following style might overwrite the previous one. ```js console.log( util.styleText(['red', 'green'], 'text'), // green ); ``` The full list of formats can be found in [modifiers](https://nodejs.org/docs/latest-v22.x/api/util.html#modifiers).

Parameters

A text format or an Array of text formats defined in `util.inspect.colors`.
text: string
The text to to be formatted.

Return Type

string