.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / unist-util-visit / readme.md
1 # unist-util-visit
2
3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
7
8 [**unist**][unist] utility to visit nodes.
9
10 ## Install
11
12 [npm][]:
13
14 ```bash
15 npm install unist-util-visit
16 ```
17
18 ## Usage
19
20 ```javascript
21 var u = require('unist-builder')
22 var visit = require('unist-util-visit')
23
24 var tree = u('tree', [
25   u('leaf', '1'),
26   u('node', [u('leaf', '2')]),
27   u('void'),
28   u('leaf', '3')
29 ])
30
31 visit(tree, 'leaf', function(node) {
32   console.log(node)
33 })
34 ```
35
36 Yields:
37
38 ```js
39 { type: 'leaf', value: '1' }
40 { type: 'leaf', value: '2' }
41 { type: 'leaf', value: '3' }
42 ```
43
44 ## API
45
46 ### `visit(tree[, test], visitor[, reverse])`
47
48 This function works exactly the same as [`unist-util-visit-parents`][vp],
49 but `visitor` has a different signature.
50
51 #### `next? = visitor(node, index, parent)`
52
53 Instead of being passed an array of ancestors, `visitor` is invoked with the
54 node’s [`index`][index] and its [`parent`][parent].
55
56 Otherwise the same as [`unist-util-visit-parents`][vp].
57
58 ## Related
59
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
70
71 ## Contribute
72
73 See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
74 started.
75 See [`support.md`][support] for ways to get help.
76
77 This project has a [Code of Conduct][coc].
78 By interacting with this repository, organisation, or community you agree to
79 abide by its terms.
80
81 ## License
82
83 [MIT][license] © [Titus Wormer][author]
84
85 <!-- Definition -->
86
87 [build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-visit.svg
88
89 [build]: https://travis-ci.org/syntax-tree/unist-util-visit
90
91 [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit.svg
92
93 [coverage]: https://codecov.io/github/syntax-tree/unist-util-visit
94
95 [downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit.svg
96
97 [downloads]: https://www.npmjs.com/package/unist-util-visit
98
99 [size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit.svg
100
101 [size]: https://bundlephobia.com/result?p=unist-util-visit
102
103 [npm]: https://docs.npmjs.com/cli/install
104
105 [license]: license
106
107 [author]: https://wooorm.com
108
109 [contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
110
111 [support]: https://github.com/syntax-tree/.github/blob/master/support.md
112
113 [coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
114
115 [unist]: https://github.com/syntax-tree/unist
116
117 [vp]: https://github.com/syntax-tree/unist-util-visit-parents
118
119 [index]: https://github.com/syntax-tree/unist#index
120
121 [parent]: https://github.com/syntax-tree/unist#parent-1