LogoPear Docs
ReferencesBareModules

bare-console

WHATWG debugging console for JavaScript

stable

bare-console — WHATWG debugging console for JavaScript.

Mirrors the Node.js console module.

npm i bare-console

Usage

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)

Source

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

ParameterTypeDefaultDescription
log?LogThe logging backend to write through. Defaults to a bare-logger instance, or bare-system-logger on Android.

assert(condition: unknown, ...data: unknown[]): void

Source

If condition is falsy, log data prefixed with 'Assertion failed'. Otherwise do nothing.

Parameters

ParameterTypeDefaultDescription
conditionunknownThe value tested for truthiness; when falsy, data is logged.
dataunknown[]Values logged after the 'Assertion failed' prefix when condition is falsy.

clear(): void

Source

Forward to log.clear().

Console: ConsoleConstructor

Source

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

Source

Increment and log the counter identified by label (default 'default').

Parameters

ParameterTypeDefaultDescription
label?stringThe label identifying the timer or counter (default 'default').

countReset(label?: string): void

Source

Remove the counter identified by label (default 'default').

Parameters

ParameterTypeDefaultDescription
label?stringThe label identifying the timer or counter (default 'default').

debug(...data: unknown[]): void

Source

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

error(...data: unknown[]): void

Source

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

info(...data: unknown[]): void

Source

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

log(...data: unknown[]): void

Source

Alias for info; forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

table(tabularData: unknown, properties?: readonly string[]): void

Source

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

ParameterTypeDefaultDescription
tabularDataunknownThe data to render as a table.
properties?readonly string[]Object keys to include as columns; ignored for Map and Set.

time(label?: string): void

Source

Start a timer identified by label (default 'default'). Warns if a timer with the same label is already running.

Parameters

ParameterTypeDefaultDescription
label?stringThe label identifying the timer or counter (default 'default').

timeEnd(label?: string): void

Source

Log the elapsed time and remove the timer identified by label (default 'default').

Parameters

ParameterTypeDefaultDescription
label?stringThe label identifying the timer or counter (default 'default').

timeLog(label?: string, ...data: unknown[]): void

Source

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

ParameterTypeDefaultDescription
label?stringThe label identifying the timer (default 'default').
dataunknown[]Additional values logged after the elapsed time.

trace(...data: unknown[]): void

Source

Log a stack trace prefixed with the formatted data.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values formatted and prefixed onto the stack trace.

warn(...data: unknown[]): void

Source

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

See also

On this page