3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
8 [**unist**][unist] utility to visit nodes.
15 npm install unist-util-visit
21 var u = require('unist-builder')
22 var visit = require('unist-util-visit')
24 var tree = u('tree', [
26 u('node', [u('leaf', '2')]),
31 visit(tree, 'leaf', function(node) {
39 { type: 'leaf', value: '1' }
40 { type: 'leaf', value: '2' }
41 { type: 'leaf', value: '3' }
46 ### `visit(tree[, test], visitor[, reverse])`
48 This function works exactly the same as [`unist-util-visit-parents`][vp],
49 but `visitor` has a different signature.
51 #### `next? = visitor(node, index, parent)`
53 Instead of being passed an array of ancestors, `visitor` is invoked with the
54 node’s [`index`][index] and its [`parent`][parent].
56 Otherwise the same as [`unist-util-visit-parents`][vp].
60 * [`unist-util-visit-parents`][vp]
61 — Like `visit`, but with a stack of parents
62 * [`unist-util-filter`](https://github.com/eush77/unist-util-filter)
63 — Create a new tree with all nodes that pass a test
64 * [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
65 — Create a new tree with all nodes mapped by a given function
66 * [`unist-util-remove`](https://github.com/eush77/unist-util-remove)
67 — Remove nodes from a tree that pass a test
68 * [`unist-util-select`](https://github.com/eush77/unist-util-select)
69 — Select nodes with CSS-like selectors
73 See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
75 See [`support.md`][support] for ways to get help.
77 This project has a [Code of Conduct][coc].
78 By interacting with this repository, organisation, or community you agree to
83 [MIT][license] © [Titus Wormer][author]
87 [build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-visit.svg
89 [build]: https://travis-ci.org/syntax-tree/unist-util-visit
91 [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit.svg
93 [coverage]: https://codecov.io/github/syntax-tree/unist-util-visit
95 [downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit.svg
97 [downloads]: https://www.npmjs.com/package/unist-util-visit
99 [size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit.svg
101 [size]: https://bundlephobia.com/result?p=unist-util-visit
103 [npm]: https://docs.npmjs.com/cli/install
107 [author]: https://wooorm.com
109 [contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
111 [support]: https://github.com/syntax-tree/.github/blob/master/support.md
113 [coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
115 [unist]: https://github.com/syntax-tree/unist
117 [vp]: https://github.com/syntax-tree/unist-util-visit-parents
119 [index]: https://github.com/syntax-tree/unist#index
121 [parent]: https://github.com/syntax-tree/unist#parent-1