bare-console
WHATWG debugging console for JavaScript
bare-console — WHATWG debugging console for JavaScript.
Mirrors the Node.js console module.
npm i bare-consoleUsage
const Console = require('bare-console')
const console = new Console()
console.log('Hello')
console.error(new Error('Something happened'))
console.time()
for (let i = 0; i < 1000000000; i++) {}
console.timeEnd()
console.trace('Show me')To install console as a global, require the bare-console/global subpath:
require('bare-console/global')
console.log('Hello')API
Console
new Console(log?: Log)
Construct a new Console. By default, output is written through bare-logger (<https://github.com/holepunchto/bare-logger>), or bare-system-logger (<https://github.com/holepunchto/bare-system-logger>) on Android.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
log? | Log | — | The logging backend to write through. Defaults to a bare-logger instance, or bare-system-logger on Android. |
assert(condition: unknown, ...data: unknown[]): void
If condition is falsy, log data prefixed with 'Assertion failed'. Otherwise do nothing.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
condition | unknown | — | The value tested for truthiness; when falsy, data is logged. |
data | unknown[] | — | Values logged after the 'Assertion failed' prefix when condition is falsy. |
clear(): void
Forward to log.clear().
Console: ConsoleConstructor
Construct a new Console. By default, output is written through bare-logger (<https://github.com/holepunchto/bare-logger>), or bare-system-logger (<https://github.com/holepunchto/bare-system-logger>) on Android.
count(label?: string): void
Increment and log the counter identified by label (default 'default').
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label identifying the timer or counter (default 'default'). |
countReset(label?: string): void
Remove the counter identified by label (default 'default').
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label identifying the timer or counter (default 'default'). |
debug(...data: unknown[]): void
Forward data to the corresponding method on the backend.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values to log. |
error(...data: unknown[]): void
Forward data to the corresponding method on the backend.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values to log. |
info(...data: unknown[]): void
Forward data to the corresponding method on the backend.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values to log. |
log(...data: unknown[]): void
Alias for info; forward data to the corresponding method on the backend.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values to log. |
table(tabularData: unknown, properties?: readonly string[]): void
Render tabularData as a table. Arrays and plain objects use an (index) column; Map and Set use an (iteration index) column with key and values (or values only) headers. Pass properties to restrict which object keys are shown as columns; the argument is ignored for Map and Set. Values that aren't tabular (primitives, null, functions) fall back to console.log(tabularData).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
tabularData | unknown | — | The data to render as a table. |
properties? | readonly string[] | — | Object keys to include as columns; ignored for Map and Set. |
time(label?: string): void
Start a timer identified by label (default 'default'). Warns if a timer with the same label is already running.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label identifying the timer or counter (default 'default'). |
timeEnd(label?: string): void
Log the elapsed time and remove the timer identified by label (default 'default').
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label identifying the timer or counter (default 'default'). |
timeLog(label?: string, ...data: unknown[]): void
Log the elapsed time for the timer identified by label (default 'default'), along with any additional data. Output uses milliseconds for short durations and seconds beyond one second.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label identifying the timer (default 'default'). |
data | unknown[] | — | Additional values logged after the elapsed time. |
trace(...data: unknown[]): void
Log a stack trace prefixed with the formatted data.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values formatted and prefixed onto the stack trace. |
warn(...data: unknown[]): void
Forward data to the corresponding method on the backend.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | Values to log. |
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.