Skip to content

Function inspect() ​

inspect(value: unknown, options?: InspectionOptions): string

Source: inspect.ts

Generates a human-readable string representation of a value.

This is intended for debugging purposes. It is an alternative to util.inspect, that supports more customization of the output.

Parameters ​

value ​

unknown

The value to inspect.

options? ​

InspectionOptions

Optional inspection options.

Returns ​

string

The resulting string.

Example ​

Note: The following examples omit the options parameter for simplicity. In reality, the return values will contain ANSI escape codes unless you explicitly set colors to false.

tsx
// Supports primitive values.
inspect(null) === "null"
inspect("example") === "\"example\""

// Supports objects and arrays (and other containers).
inspect({ size: 2, values: [true, false] }) === "{ size: 2, values: [true, false] }"

// Even supports React nodes.
inspect(<h1>Example</h1>) === "<h1>Example</h1>"

Built by Prozilla