summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/unist-util-visit/readme.md
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/unist-util-visit/readme.md')
-rw-r--r--tools/node_modules/eslint/node_modules/unist-util-visit/readme.md73
1 files changed, 55 insertions, 18 deletions
diff --git a/tools/node_modules/eslint/node_modules/unist-util-visit/readme.md b/tools/node_modules/eslint/node_modules/unist-util-visit/readme.md
index 1d68eef6f8..9446a1543d 100644
--- a/tools/node_modules/eslint/node_modules/unist-util-visit/readme.md
+++ b/tools/node_modules/eslint/node_modules/unist-util-visit/readme.md
@@ -1,6 +1,6 @@
# unist-util-visit [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
-[Unist][] node visitor. Useful when working with [**remark**][remark],
+[unist][] node visitor. Useful when working with [**remark**][remark],
[**retext**][retext], or [**rehype**][rehype].
## Installation
@@ -17,7 +17,7 @@ npm install unist-util-visit
var remark = require('remark');
var visit = require('unist-util-visit');
-var tree = remark.parse('Some _emphasis_, **importance**, and `code`.');
+var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
visit(tree, 'text', visitor);
@@ -29,37 +29,46 @@ function visitor(node) {
Yields:
```js
-{ type: 'text', value: 'Some ' }
-{ type: 'text', value: 'emphasis' }
-{ type: 'text', value: ', ' }
-{ type: 'text', value: 'importance' }
-{ type: 'text', value: ', and ' }
-{ type: 'text', value: '.' }
+{type: 'text', value: 'Some '}
+{type: 'text', value: 'emphasis'}
+{type: 'text', value: ', '}
+{type: 'text', value: 'importance'}
+{type: 'text', value: ', and '}
+{type: 'text', value: '.'}
```
## API
-### `visit(node[, test], visitor[, reverse])`
+### `visit(tree[, test], visitor[, reverse])`
-Visit nodes. Optionally filtering nodes. Optionally in reverse.
+Visit nodes ([**inclusive descendants**][descendant] of `tree`). Optionally
+filtering nodes. Optionally in reverse.
###### Parameters
-* `node` ([`Node`][node])
- — Node to search
+* `tree` ([`Node`][node])
+ — Tree to traverse
* `test` ([`Test`][is], optional)
- — Node type or other [`is`][is]-compatible test
+ — [`is`][is]-compatible test (such as a node type)
* `visitor` ([Function][visitor])
- — Visitor invoked when a node is found
+ — Function invoked when a node is found that passes `test`
* `reverse` (`boolean`, default: `false`)
— When falsey, checking starts at the first child and continues
through to later children. When truthy, this is reversed.
This **does not** mean checking starts at the deepest node and
continues on to the highest node
-#### `stop? = visitor(node, index, parent)`
+#### `next? = visitor(node, index, parent)`
-Invoked when a node (matching `test`, if given) is found.
+Invoked when a node (matching `test` if given) is found.
+
+You can transform visited nodes. You can transform `parent`, but if adding or
+removing [**children**][child] before `index`, you should return a new `index`
+(`number`) from `visitor` to specify the next sibling to visit. Replacing
+`node` itself still causes its descendants to be visited. Adding or removing
+nodes after `index` is handled as expected without needing to return a new
+`index`. Removing the `children` property on `parent` still results in them
+being traversed.
###### Parameters
@@ -69,7 +78,19 @@ Invoked when a node (matching `test`, if given) is found.
###### Returns
-`boolean?` - When `false`, visiting is immediately stopped.
+* `visit.EXIT` (`false`)
+ — Stop traversing immediately
+* `visit.CONTINUE` (`true`)
+ — Continue traversing as normal (same behaviour as not returning anything)
+* `visit.SKIP` (`'skip'`)
+ — Do not enter this node (traversing into its children), but do continue
+ with the next sibling
+* `index` (`number`)
+ — Move to the sibling at position `index` next (after `node` itself is
+ traversed). Useful if you’re mutating the tree (such as removing the node
+ you’re currently on, or any of its preceding siblings). Results less than
+ `0` or greater than or equal to `children.length` stop iteration of the
+ parent
## Related
@@ -84,6 +105,14 @@ Invoked when a node (matching `test`, if given) is found.
* [`unist-util-select`](https://github.com/eush77/unist-util-select)
— Select nodes with CSS-like selectors
+## Contribute
+
+See [`contribute.md` in `syntax-tree/unist`][contribute] for ways to get
+started.
+
+This organisation has a [Code of Conduct][coc]. By interacting with this
+repository, organisation, or community you agree to abide by its terms.
+
## License
[MIT][license] © [Titus Wormer][author]
@@ -114,6 +143,14 @@ Invoked when a node (matching `test`, if given) is found.
[node]: https://github.com/syntax-tree/unist#node
+[descendant]: https://github.com/syntax-tree/unist#descendant
+
+[child]: https://github.com/syntax-tree/unist#child
+
[is]: https://github.com/syntax-tree/unist-util-is#istest-node-index-parent-context
-[visitor]: #stop--visitornode-index-parent
+[visitor]: #next--visitornode-index-parent
+
+[contribute]: https://github.com/syntax-tree/unist/blob/master/contributing.md
+
+[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md