Registry / serialization / unist-util-inspect

unist-util-inspect

JSON →
library8.1.0jsnpmunverified

unist-util-inspect is a utility for pretty-printing Abstract Syntax Trees (ASTs) that conform to the unist specification. It provides a human-readable, terser output format specifically tailored for unist nodes, making it easier to debug and understand tree structures compared to verbose JSON representations. The current stable version is 8.1.0, actively maintained with incremental updates. Major releases tend to align with Node.js LTS versions, requiring Node.js 16+ since version 8.0.0 and having transitioned to ESM-only in version 7.0.0. The library aims for a focused utility approach within the broader unified ecosystem, prioritizing clear and concise tree visualization and offering a custom format instead of generic object serialization.

npm install unist-util-inspect
INSTALL
IMPORT
SIG · UNIST-UTIL-INSPECT
U
unist-util-inspect
serializationjavascriptv8.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inspect
import { inspect } from 'unist-util-inspect'
const inspect = require('unist-util-inspect')
The package is ESM-only since v7.0.0. CommonJS `require()` is not supported.
inspectColor
import { inspectColor } from 'unist-util-inspect'
This function is deprecated since v8.1.0. Use `inspect(tree, { color: true })` instead.
Options
import type { Options } from 'unist-util-inspect'
Type-only import for configuring inspection options. Available since v5.0.0.

Demonstrates how to import and use the `inspect` function with a sample unist tree, showing both colored and uncolored output options.

import { u } from 'unist-builder'; import { inspect } from 'unist-util-inspect'; const complexTree = u('root', [ u('paragraph', [ u('text', 'Hello, world!'), u('emphasis', [u('text', 'This is emphasized.')]) ]), u('list', { ordered: true }, [ u('listItem', [u('text', 'First item')]), u('listItem', [u('strong', [u('text', 'Second item with strong text')])]) ]), u('code', { lang: 'js' }, 'console.log("Code example");') ]); console.log('--- Uncolored Inspection ---'); console.log(inspect(complexTree, { color: false, showPositions: true })); console.log('\n--- Colored Inspection (default) ---'); console.log(inspect(complexTree)); // Demonstrates basic usage and optional parameters for output control.
Debug
Known issues
breakingVersion 8.0.0 and newer require Node.js 16 or later. Running on older Node.js versions will result in an error.
fix
Upgrade your Node.js environment to version 16 or a newer maintained release.
affects: >=8.0.0
breakingThe package transitioned to ESM-only with an `export` map in v8.0.0, building upon its initial ESM migration in v7.0.0. Direct CommonJS `require()` statements will fail.
fix
Ensure you are using `import` statements for all package imports. If your project is CommonJS, you may need to convert it to ESM or use a dynamic import `import('unist-util-inspect')`.
affects: >=7.0.0
deprecatedThe `inspectColor` and `inspectNoColor` functions are deprecated. They will be removed in a future major version.
fix
Replace `inspectColor(tree)` with `inspect(tree, { color: true })` and `inspectNoColor(tree)` with `inspect(tree, { color: false })`.
affects: >=8.1.0
breakingVersion 5.0.0 introduced TypeScript types. While beneficial, this could cause breaking changes for existing TypeScript projects if type definitions conflict or are not handled correctly.
fix
Review type declarations and ensure compatibility with your project's TypeScript configuration. Use `import type` for type-only imports where appropriate.
affects: >=5.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require('unist-util-inspect')` in a CommonJS module after the package became ESM-only.
fix
Change your import statement to `import { inspect } from 'unist-util-inspect'` and ensure your project is configured for ESM, or use dynamic import `import('unist-util-inspect')`.
Error: This module requires Node.js 16 or later.
Running `unist-util-inspect` on a Node.js version older than 16.
fix
Update your Node.js environment to version 16 or newer. You can use `nvm` to manage Node.js versions easily.
Property 'inspectColor' does not exist on type 'typeof import("unist-util-inspect")'.
Using the deprecated `inspectColor` or `inspectNoColor` functions in a TypeScript project, potentially after they have been removed or type definitions have been updated.
fix
Migrate to using the `color` option with the main `inspect` function: `inspect(tree, { color: true })` for colored output and `inspect(tree, { color: false })` for uncolored output.
Upgrade
Version history
8.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
unist-util-inspect — npm install unist-util-inspect · libregistry