gitwtfhub

wtf is unist-util-visit?

joshuakgoldberg/unist-util-visit — explained in plain English

Analysis updated 2026-07-08 · repo last pushed 2026-01-22

Audience · developerComplexity · 2/5MaintainedLicenseSetup · easy

TL;DR

A small JavaScript utility that walks through document trees (like parsed Markdown) node by node, letting you inspect or modify each piece of text along the way.

Mindmap

mindmap
  root((repo))
    What it does
      Walks document trees
      Runs function per node
      Filters node types
    Use cases
      Spellcheckers
      Link rewriters
      Linters
    Tech stack
      TypeScript
      JavaScript
      Node.js
    Features
      Skip children
      Stop early
      Full node context
    Audience
      Developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Build a spellchecker that scans only text nodes in a Markdown document.

REASON 2

Create a tool that finds and rewrites all links in parsed content.

REASON 3

Write a linter that flags problematic formatting in structured documents.

What's in the stack?

JavaScriptTypeScriptNode.js

How it stacks up

joshuakgoldberg/unist-util-visit0verflowme/alarm-clock0xhassaan/nn-from-scratch
Stars0
LanguageCSSPython
Last pushed2026-01-222022-10-03
MaintenanceMaintainedDormant
Setup difficultyeasyeasymoderate
Complexity2/52/54/5
Audiencedevelopervibe coderdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Install via npm and pass it a parsed syntax tree along with a visitor function.

You can use, copy, modify, and distribute this software freely, including in commercial projects, as long as you include the copyright notice and license text.

Wtf does this do

When you write something in Markdown, a tool converts your text into a tree-like structure where each piece, a paragraph, a bold word, a code snippet, becomes a "node." The unist-util-visit package gives developers a simple way to walk through that tree, stopping at each node along the way. It's essentially a tour guide for structured text content. The core idea is straightforward: you hand the tool your tree and a function. It then walks through every node in order and runs your function on each one. Your function can just look at the node (to find something specific, for instance), or it can change it entirely. As it walks, the tool gives your function context about where it is, the current node, its position (index) among its siblings, and its parent node. You can also filter which nodes to stop at, so you don't have to inspect every single one. Developers use this when they need to find, read, or modify specific parts of a document. For example, if you have a Markdown file and want to find every piece of plain text, you could use this tool to visit only "text" nodes and log their contents. It's the kind of utility you'd reach for when building something like a spellchecker, a tool that rewrites links, or a linter that flags problematic formatting, anything where you need to scan or transform structured content piece by piece. One thing worth noting is the fine-grained control it gives you over the walking process. At any point, your function can tell the tool to keep going as normal, stop entirely (useful once you've found what you need), or skip the children of the current node. This means you can bail out early or skip deeply nested sections you don't care about, which is helpful for performance when dealing with large documents. The project also includes TypeScript types, which helps developers catch mistakes before they run their code.

Yoink these prompts

Prompt 1
Write a function using unist-util-visit that finds all link nodes in a Markdown AST and replaces their URLs with lowercase versions.
Prompt 2
Using unist-util-visit, write a visitor that logs every text node's value from this Markdown tree so I can see all plain text content.
Prompt 3
Create a unist-util-visit script that stops visiting as soon as it finds the first code block node and returns its contents.

Frequently asked questions

wtf is unist-util-visit?

A small JavaScript utility that walks through document trees (like parsed Markdown) node by node, letting you inspect or modify each piece of text along the way.

Is unist-util-visit actively maintained?

Maintained — commit in last 6 months (last push 2026-01-22).

What license does unist-util-visit use?

You can use, copy, modify, and distribute this software freely, including in commercial projects, as long as you include the copyright notice and license text.

How hard is unist-util-visit to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is unist-util-visit for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.