unist-util-visit

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

Library
npm
v5.1.0
353stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity4
Maintenance20
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
88/100Excellent
Architecture85
Code Quality90
Innovation90
Learning Curve85

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 33 apps in this directory

TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
Python
49%
Other

Airbyte

Developer Tools · Data Engineering

21,916

Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.

View details
95
Repo Health
80
Technical
67
Dependency
Built with
Python49%
Kotlin42%
Updated today
Python
54%
Other

authentik

Authentication · Security

24,980

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
68
Dependency
Built with
Python54%
TypeScript33%
Updated today
Java
73%
Other

ByteChef

Automation · AI Agents

990

Unified open-source platform for AI agent orchestration and workflow automation with 180+ connectors, MCP support, and durable execution.

View details
81
Repo Health
82
Technical
73
Dependency
Built with
Java73%
TypeScript26%
Updated 2 days ago
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

50,753

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
88
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today
JavaScript
50%
Apache 2.0

claude-mem

AI Agents · AI Development

91,197

Give your AI coding agents persistent memory — claude-mem captures everything that happens during sessions, compresses it with AI, and surfaces the right context in every future session automatically.

View details
86
Repo Health
82
Technical
77
Dependency
Built with
JavaScript50%
TypeScript48%
Updated today
TypeScript
97%
Apache 2.0

Cline

AI Code Assistants

66,453

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
90
Repo Health
74
Technical
67
Dependency
Built with
TypeScript97%
Updated today
Rust
52%
Apache 2.0

cocoindex

Data Engineering · AI Development

11,350

An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.

View details
87
Repo Health
85
Technical
64
Dependency
Built with
Rust52%
Python48%
Updated yesterday
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,532

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
87
Repo Health
88
Technical
65
Dependency
Built with
TypeScript84%
Updated today

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

Search