{"id":13339471,"url":"https://github.com/0phoff/unist-util-walker","last_synced_at":"2025-10-28T01:33:28.467Z","repository":{"id":43762722,"uuid":"511589561","full_name":"0phoff/unist-util-walker","owner":"0phoff","description":"Walk unist trees with enter and leave functions","archived":false,"fork":false,"pushed_at":"2022-07-11T13:02:25.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T20:57:42.627Z","etag":null,"topics":["ast","syntax-tree","traverse","tree","unifiedjs","unist","unist-util","visit","walk"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/0phoff.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}},"created_at":"2022-07-07T15:54:33.000Z","updated_at":"2022-07-08T07:22:27.000Z","dependencies_parsed_at":"2022-08-22T14:50:12.931Z","dependency_job_id":null,"html_url":"https://github.com/0phoff/unist-util-walker","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0phoff%2Funist-util-walker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0phoff%2Funist-util-walker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0phoff%2Funist-util-walker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0phoff%2Funist-util-walker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0phoff","download_url":"https://codeload.github.com/0phoff/unist-util-walker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239487290,"owners_count":19646981,"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":["ast","syntax-tree","traverse","tree","unifiedjs","unist","unist-util","visit","walk"],"created_at":"2024-07-29T19:20:03.701Z","updated_at":"2025-10-28T01:33:23.432Z","avatar_url":"https://github.com/0phoff.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# UNIST UTIL WALKER\n_Talk the Talk - Walk the Tree_  \n[![npm version](https://img.shields.io/npm/v/unist-util-walker?color=blue\u0026logo=npm)](https://www.npmjs.com/package/unist-util-walker)\n[![npm downloads](https://img.shields.io/npm/dt/unist-util-walker?color=blue\u0026logo=nodedotjs)](https://www.npmjs.com/package/unist-util-walker)\n[![main](https://github.com/0phoff/unist-util-walker/actions/workflows/main.yml/badge.svg)](https://github.com/0phoff/unist-util-walker/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/0phoff/unist-util-walker/branch/master/graph/badge.svg?token=JWVVNRI6IK)](https://codecov.io/gh/0phoff/unist-util-walker)\n\n\u003c/div\u003e\n\nInspired by [estree-walker](https://github.com/Rich-Harris/estree-walker), this package provides a method to walk unist trees, by providing an `enter` and `leave` function.\nThe main advantage over [unist-util-visit](https://github.com/syntax-tree/unist-util-visit) is that we can enter all child nodes and accumulate data,\nwhich we can then use in the leave function of the parent.\n\n## Installation\nThis package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.\n\n### NPM\n```bash\nnpm install unist-util-walker\n```\n\n### YARN\n```bash\nyarn add unist-util-walker\n```\n\n### PNPM\n```bash\npnpm add unist-util-walker\n```\n\n## Usage\n```typescript\nimport type { Node, Parent } from 'unist';\nimport { walk } from 'unist-util-walker';\nimport { u } from 'unist-builder';\n\nconst tree: Node = u('root', [\n  u('subtree', {id: 1}),\n  u('subtree', {id: 2}, [\n    u('node', [u('leaf', {id: 1}), u('leaf', {id: 2})]),\n    u('leaf', {id: 3}),\n    u('void'),\n  ]),\n]);\n\nwalk(tree, {\n  enter(node: Node, parent?: Parent, index?: number) {\n    // some code happens\n  },\n  leave(node: Node, parent?: Parent, index?: number) {\n    // some code happens\n  }\n});\n```\n\nInside of the `enter` and `leave` functions, you can call the following functions:\n\n- `this.break()`  \n  Skips children and the leave function of the current node (only useful in enter).\n- `this.skip()`  \n  Skips children, but still runs the leave function of the current node (only useful in enter).\n- `this.remove()`  \n  Removes the node from the tree (has no effect on root node).\n- `this.replace(node: Node)`  \n  Replaces the node with a new one.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0phoff%2Funist-util-walker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0phoff%2Funist-util-walker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0phoff%2Funist-util-walker/lists"}