{"id":13483918,"url":"https://github.com/syntax-tree/unist-util-visit","last_synced_at":"2025-12-12T04:28:02.726Z","repository":{"id":34512232,"uuid":"38453852","full_name":"syntax-tree/unist-util-visit","owner":"syntax-tree","description":"utility to visit nodes","archived":false,"fork":false,"pushed_at":"2024-04-30T11:38:57.000Z","size":195,"stargazers_count":300,"open_issues_count":0,"forks_count":20,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-12T23:48:21.596Z","etag":null,"topics":["syntax-tree","unist","unist-util","util","visit","walk"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2015-07-02T19:54:38.000Z","updated_at":"2025-04-25T03:26:43.000Z","dependencies_parsed_at":"2024-01-13T18:24:24.449Z","dependency_job_id":"0826326d-f0f2-4839-a130-a06fcdf47172","html_url":"https://github.com/syntax-tree/unist-util-visit","commit_stats":{"total_commits":158,"total_committers":13,"mean_commits":"12.153846153846153","dds":0.08860759493670889,"last_synced_commit":"3ef009be60a9739c0127a7274ea88f5d3fc21894"},"previous_names":["wooorm/unist-util-visit"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-visit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-visit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-visit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Funist-util-visit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/unist-util-visit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843166,"owners_count":21972868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["syntax-tree","unist","unist-util","util","visit","walk"],"created_at":"2024-07-31T17:01:16.866Z","updated_at":"2025-12-12T04:27:57.704Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# unist-util-visit\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[unist][] utility to walk the tree.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`visit(tree[, test], visitor[, reverse])`](#visittree-test-visitor-reverse)\n  * [`CONTINUE`](#continue)\n  * [`EXIT`](#exit)\n  * [`SKIP`](#skip)\n  * [`Action`](#action)\n  * [`ActionTuple`](#actiontuple)\n  * [`BuildVisitor`](#buildvisitor)\n  * [`Index`](#index)\n  * [`Test`](#test)\n  * [`Visitor`](#visitor)\n  * [`VisitorResult`](#visitorresult)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis is a very important utility for working with unist as it lets you walk the\ntree.\n\n## When should I use this?\n\nYou can use this utility when you want to walk the tree.\nYou can use [`unist-util-visit-parents`][vp] if you care about the entire stack\nof parents.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install unist-util-visit\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {CONTINUE, EXIT, SKIP, visit} from 'https://esm.sh/unist-util-visit@5'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {CONTINUE, EXIT, SKIP, visit} from 'https://esm.sh/unist-util-visit@5?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {visit} from 'unist-util-visit'\n\nconst tree = fromMarkdown('Some *emphasis*, **strong**, and `code`.')\n\nvisit(tree, 'text', function (node, index, parent) {\n  console.log([node.value, parent ? parent.type : index])\n})\n```\n\nYields:\n\n```js\n[ 'Some ', 'paragraph' ]\n[ 'emphasis', 'emphasis' ]\n[ ', ', 'paragraph' ]\n[ 'strong', 'strong' ]\n[ ', and ', 'paragraph' ]\n[ '.', 'paragraph' ]\n```\n\n## API\n\nThis package exports the identifiers [`CONTINUE`][api-continue],\n[`EXIT`][api-exit], [`SKIP`][api-skip], and [`visit`][api-visit].\nThere is no default export.\n\n### `visit(tree[, test], visitor[, reverse])`\n\nThis function works exactly the same as [`unist-util-visit-parents`][vp],\nbut [`Visitor`][api-visitor] has a different signature.\n\n### `CONTINUE`\n\nContinue traversing as normal (`true`).\n\n### `EXIT`\n\nStop traversing immediately (`false`).\n\n### `SKIP`\n\nDo not traverse this node’s children (`'skip'`).\n\n### `Action`\n\nUnion of the action types (TypeScript type).\nSee [`Action` in `unist-util-visit-parents`][vp-action].\n\n### `ActionTuple`\n\nList with an action and an index (TypeScript type).\nSee [`ActionTuple` in `unist-util-visit-parents`][vp-action-tuple].\n\n### `BuildVisitor`\n\nBuild a typed `Visitor` function from a tree and a test (TypeScript type).\nSee [`BuildVisitor` in `unist-util-visit-parents`][vp-build-visitor].\n\n### `Index`\n\nMove to the sibling at `index` next (TypeScript type).\nSee [`Index` in `unist-util-visit-parents`][vp-index].\n\n### `Test`\n\n[`unist-util-is`][unist-util-is] compatible test (TypeScript type).\n\n### `Visitor`\n\nHandle a node (matching `test`, if given) (TypeScript type).\n\nVisitors are free to transform `node`.\nThey can also transform `parent`.\n\nReplacing `node` itself, if `SKIP` is not returned, still causes its\ndescendants to be walked (which is a bug).\n\nWhen adding or removing previous siblings of `node` (or next siblings, in\ncase of reverse), the `Visitor` should return a new `Index` to specify the\nsibling to traverse after `node` is traversed.\nAdding or removing next siblings of `node` (or previous siblings, in case\nof reverse) is handled as expected without needing to return a new `Index`.\n\nRemoving the children property of `parent` still results in them being\ntraversed.\n\n###### Parameters\n\n* `node` ([`Node`][node])\n  — found node\n* `index` (`number` or `undefined`)\n  — index of `node` in `parent`\n* `parent` ([`Node`][node] or `undefined`)\n  — parent of `node`\n\n###### Returns\n\nWhat to do next.\n\nAn `Index` is treated as a tuple of `[CONTINUE, Index]`.\nAn `Action` is treated as a tuple of `[Action]`.\n\nPassing a tuple back only makes sense if the `Action` is `SKIP`.\nWhen the `Action` is `EXIT`, that action can be returned.\nWhen the `Action` is `CONTINUE`, `Index` can be returned.\n\n### `VisitorResult`\n\nAny value that can be returned from a visitor (TypeScript type).\nSee [`VisitorResult` in `unist-util-visit-parents`][vp-visitor-result].\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Action`][api-action],\n[`ActionTuple`][api-action-tuple], [`BuildVisitor`][api-build-visitor],\n[`Index`][api-index], [`Test`][api-test], [`Visitor`][api-visitor], and\n[`VisitorResult`][api-visitor-result].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `unist-util-visit@^5`,\ncompatible with Node.js 16.\n\n## Related\n\n* [`unist-util-visit-parents`][vp]\n  — walk the tree with a stack of parents\n* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)\n  — create a new tree with all nodes that pass a test\n* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)\n  — create a new tree with all nodes mapped by a given function\n* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)\n  — create a new tree by mapping (to an array) with the given function\n* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)\n  — remove nodes from a tree that pass a test\n* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)\n  — select nodes with CSS-like selectors\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definition --\u003e\n\n[build-badge]: https://github.com/syntax-tree/unist-util-visit/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/unist-util-visit/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit\n\n[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit.svg\n\n[downloads]: https://www.npmjs.com/package/unist-util-visit\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=unist-util-visit\n\n[size]: https://bundlejs.com/?q=unist-util-visit\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[unist]: https://github.com/syntax-tree/unist\n\n[node]: https://github.com/syntax-tree/unist#nodes\n\n[unist-util-is]: https://github.com/syntax-tree/unist-util-is\n\n[vp]: https://github.com/syntax-tree/unist-util-visit-parents\n\n[vp-action]: https://github.com/syntax-tree/unist-util-visit-parents#action\n\n[vp-action-tuple]: https://github.com/syntax-tree/unist-util-visit-parents#actiontuple\n\n[vp-build-visitor]: https://github.com/syntax-tree/unist-util-visit-parents#buildvisitor\n\n[vp-index]: https://github.com/syntax-tree/unist-util-visit-parents#index\n\n[vp-visitor-result]: https://github.com/syntax-tree/unist-util-visit-parents#visitorresult\n\n[api-visit]: #visittree-test-visitor-reverse\n\n[api-continue]: #continue\n\n[api-exit]: #exit\n\n[api-skip]: #skip\n\n[api-action]: #action\n\n[api-action-tuple]: #actiontuple\n\n[api-build-visitor]: #buildvisitor\n\n[api-index]: #index\n\n[api-test]: #test\n\n[api-visitor]: #visitor\n\n[api-visitor-result]: #visitorresult\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript","unist utilities","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-visit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Funist-util-visit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Funist-util-visit/lists"}