LogoPear Docs

bare-inspect

Inspect objects as strings for debugging

stable

bare-inspect — Inspect objects as strings for debugging. It is a native addon and requires Bare >=1.18.0.

npm i bare-inspect

Usage

const inspect = require('bare-inspect')

console.log(inspect(globalThis))

API

Functions

inspect(value: unknown, opts?: InspectOptions): string

Source

Returns a string representation of value for debugging, similar to Node's util.inspect(). If value has a Symbol.for('bare.inspect') or Symbol.for('nodejs.util.inspect.custom') method, it is used to produce the output.

Parameters

ParameterTypeDefaultDescription
valueunknownThe value to produce a string representation of.
opts?InspectOptionsFormatting options; see InspectOptions.

Types

InspectOptions

interface InspectOptions {
  colors?: boolean
  depth?: number
  breakLength?: number
  stylize?: InspectStylize
}
Source

Options for inspect(). colors enables ANSI styling, depth limits how many levels of nested objects are inspected (defaults to 2), breakLength sets the line-wrap width (defaults to 80), and stylize is a custom function for applying styles to values.

InspectStylize

interface InspectStylize {
  (value: string, style: keyof typeof inspect.styles): string
}
Source

A function that applies a named style (such as 'string' or 'number') to a value before it's included in the output.

See also

On this page