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)

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

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

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

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

countReset(label?: string): void

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

Parameters

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

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

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

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

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

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

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

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

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

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

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

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

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

Log a stack trace prefixed with the formatted data.

Parameters

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

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

Forward data to the corresponding method on the backend.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to log.

See also

  • Builds on bare-format, bare-hrtime, bare-logger, bare-system-logger, and bare-type.
  • Bare modules — the full bare-* catalog.
  • Bare runtime API — the runtime these modules extend.

On this page