unist-util-visit

Tiny utility to walk unist syntax trees and run a visitor on matching nodes

Library
npm
v5.1.0
360 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
40 /100 Fair
Development Activity 0
Maintenance 20
Community 60
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 85
Code Quality 90
Innovation 90
Learning Curve 85

unist-util-visit is a small, focused utility from the unified/syntax-tree collective for walking unist abstract syntax trees such as mdast (Markdown), hast (HTML), and nlcst (natural language). It performs depth-first traversal and calls a visitor function for every node, or only for nodes matching a unist-util-is compatible test.

The visitor receives each node along with its index and parent, and can inspect, mutate, skip subtrees, or stop the walk entirely by returning control actions. It is one of the most widely depended-on building blocks in the remark, rehype, and retext plugin ecosystems.

What You Get

  • A single visit(tree[, test], visitor[, reverse]) function that covers the common tree-walking use case
  • Control actions CONTINUE, SKIP, and EXIT to steer or stop traversal from inside the visitor
  • unist-util-is compatible tests so you can target nodes by type, property, or predicate function
  • Rich TypeScript types that infer the concrete node and parent types for a given tree and test
  • ESM-only, dependency-light package that works in Node.js, Deno, and browsers via esm.sh

Common Use Cases

  • Writing remark, rehype, or retext plugins that transform Markdown, HTML, or prose syntax trees
  • Collecting or rewriting specific node types (links, headings, images, text) across a document
  • Mutating a tree in place - removing, replacing, or reordering nodes during a single walk
  • Extracting data such as all headings or code blocks for tables of contents or indexes

Under The Hood

Architecture

The entire runtime lives in lib/index.js, where the exported visit function is a thin ergonomic wrapper around visitParents from the sibling unist-util-visit-parents package. visit first normalizes its overloaded arguments - detecting whether the second argument is a visitor or a unist-util-is test and whether the third is a visitor or the reverse flag - then delegates the actual depth-first traversal to visitParents. It adapts the parents-stack callback signature into the friendlier (node, index, parent) shape by taking the last element of the parents array as parent and computing index via parent.children.indexOf(node). The CONTINUE, EXIT, and SKIP action constants are simply re-exported from the parents package. index.js at the root re-exports the public runtime and the types live in index.d.ts.

Tech Stack

This is pure ESM JavaScript ("type": "module", single "exports": "./index.js") authored with JSDoc and compiled to .d.ts declarations via the TypeScript compiler. Runtime dependencies are minimal: @types/unist, unist-util-is, and unist-util-visit-parents. Development tooling includes c8 for coverage, tsd and type-coverage for type checking, and xo/prettier/remark for linting and formatting. It targets Node.js 16 and up.

Code Quality

Quality is exemplary for a micro-utility. A dedicated test.js suite exercises the API and the build enforces 100% code coverage (c8 --100) and 100% type coverage (typeCoverage.atLeast: 100, strict). The source is densely annotated with JSDoc, including elaborate conditional-type machinery that infers which nodes reach the visitor and what their parents can be. Naming is consistent with the wider syntax-tree ecosystem and error handling is unnecessary given the pure, side-effect-free traversal design.

API Design

The public surface is deliberately tiny: one visit function plus three action constants. Function overloads make the test argument optional while preserving precise types, so a visitor for 'text' nodes is typed as receiving a text node. The README documents every export and type thoroughly, and getting started requires almost no boilerplate - import visit, pass a tree and a callback. This minimalism and strong typing are why it underpins so much of the unified ecosystem.

Used by 36 apps in this directory

TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

29,041

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
90
Repo Health
73
Technical
65
Dependency
Built with
TypeScript 99%
Updated 6 days ago
TypeScript
87%
MIT

medusa

Ecommerce

36,897

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
94
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 1 weeks ago
Go
53%
MIT

memos

Note Taking

64,031

Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.

View details
91
Repo Health
78
Technical
65
Dependency
Built with
Go 53%
TypeScript 46%
Updated 6 days ago
TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,674

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
80
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated 6 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,266

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
59
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 1 months ago
TypeScript
96%
Other

Refly

AI Development · Automation · No Code Platforms

7,537

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
68
Repo Health
76
Technical
63
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
67%
MIT

Scalar

Developer Tools

16,313

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 67%
Vue 29%
Updated 6 days ago
Rust
77%
Apache 2.0

SlateDB

Databases · Developer Tools

3,585

Embedded KV store built on object storage with zero replication cost

View details
87
Repo Health
73
Technical
73
Dependency
Built with
Rust 77%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers