Unist Tree Inspector

8.1.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

view raw JSON →