Output
The Output class provides methods for formatted and styled console output.
- If we put
options.silenttotrue, nothing will be printed - If we put
options.colorstofalse, no colors will be printed
Example
const out = new Output({ silent: false });
out.write('Hello, World!');
out.success('Operation completed successfully.');
out.error('An error occurred.');
out.line(out.t`Hello {green.bold.dim World, this is colored!} and this aint`
out.line(`Hello {green.bold.dim World, this is colored!} and this aint`)
out.line(out.color.red('This is red text'));Constructors
new Output()
new Output(options): OutputCreates an instance of Output.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Partial options to override the default settings. |
Returns
Example
const output = new Output({ silent: true });Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
|
|
| ‐ | |
|
| ‐ | ||
| ( |
| Blocks are delimited by an opening curly brace ({), a style, some content, and a closing curly brace (}). Template styles are chained exactly like normal Chalk styles. See https://github.com/chalk/chalk-template Example | |
| ( |
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
| ‐ |
Accessors
colorsEnabled
Get Signature
get colorsEnabled(): booleanReturns
boolean
err
Get Signature
get err(): WriteStream & objectThe output stream for standard messages.
Example
output.out.write('Hello, World!');
output.out.write('Hello, World!').write('Hello, World!');
output.out.write('Hello, World!').writeln('Hello, World!');Returns
WriteStream & object
isSilent
Get Signature
get isSilent(): booleanReturns
boolean
nl
Get Signature
get nl(): thisReturns
this
out
Get Signature
get out(): WriteStream & objectThe output stream for standard messages.
Example
output.out.write('Hello, World!');
output.out.write('Hello, World!').write('Hello, World!');
output.out.write('Hello, World!').writeln('Hello, World!');Returns
WriteStream & object
Methods
configure()
configure(options): OutputConfigures the Output instance with new options.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Partial options to merge with the current settings. |
Returns
The current Output instance.
Example
output.configure({ colors: false });disableColors()
disableColors(): OutputReturns
dump()
dump(...args): thisDumps the provided arguments to the output stream using util.inspect.
Parameters
| Parameter | Type | Description |
|---|---|---|
... |
| The arguments to dump. |
Returns
this
The current Output instance.
Example
output.dump({ key: 'value' }, [1, 2, 3]);enableColors()
enableColors(): OutputReturns
error()
error(text): OutputWrites an error message to the output stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The error message. |
Returns
The current Output instance.
Example
output.error('An error occurred.');line()
line(text?): thisWrites text followed by a newline to the output stream.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
|
|
| The text to write. |
Returns
this
The current Output instance.
Example
output.line('Hello, World!');silence()
silence(): OutputReturns
success()
success(text): OutputWrites a success message to the output stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The success message. |
Returns
The current Output instance.
Example
output.success('Operation completed successfully.');unsilence()
unsilence(): OutputReturns
warn()
warn(text): OutputWrites a warning message to the output stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The warning message. |
Returns
The current Output instance.
Example
output.warn('This is a warning message.');write()
write(text): thisWrites text to the output stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The text to write. |
Returns
this
The current Output instance.
Example
output.write('Hello, World!');writeln()
writeln(text?): thisWrites text followed by a newline to the output stream.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
|
|
| The text to write. |
Returns
this
The current Output instance.
Example
output.writeln('Hello, World!');