<commit_before># mdast-util-visit [![Build Status](https://img.shields.io/travis/wooorm/mdast-util-visit.svg?style=flat)](https://travis-ci.org/wooorm/mdast-util-visit) [![Coverage Status](https://img.shields.io/coveralls/wooorm/mdast-util-visit.svg?style=flat)](https://coveralls.io/r/wooorm/mdast-util-visit?branch=master)

[**mdast**](https://github.com/wooorm/mdast) utility to recursively walk
over nodes: both forwards and backwards.

## Installation

[npm](https://docs.npmjs.com/cli/install):

```bash
npm install mdast-util-visit
```

**mdast-util-visit** is also available for [bower](http://bower.io/#install-packages),
[component](https://github.com/componentjs/component), and
[duo](http://duojs.org/#getting-started), and as an AMD, CommonJS, and globals
module, [uncompressed](mdast-util-visit.js) and
[compressed](mdast-util-visit.min.js).

## Usage

```js
/*
 * Dependencies.
 */

var mdast = require('mdast');
var visit = require('mdast-util-visit');

/*
 * AST.
 */

var ast = mdast.parse('Some *emphasis*, **strongness**, and `code`.');

visit(ast, 'text', console.log.bind(console));
/*
 * {type: 'text', 'value': 'Some '}
 * {type: 'text', 'value': 'emphasis'}
 * {type: 'text', 'value': ', '}
 * {type: 'text', 'value': 'strongness'}
 * {type: 'text', 'value': ', and '}
 * {type: 'text', 'value': '.'}
 */
```

## API

### visit(ast\[, type\], callback\[, reverse\])

Visit nodes. Optionally by [node type](https://github.com/wooorm/mdast/blob/master/doc/nodes.md),
Optionally in reverse.

*   `ast` (`Node`)
    — [**mdast** node](https://github.com/wooorm/mdast/blob/master/doc/nodes.md);

*   `type` (`string`, optional)
    — Optional node type to invoke `callback` for. By default, all nodes are
    visited.

*   `callback` (`function(node, index?, parent?)`)
    — Callback when a node (matching `type`) is found. Invoked with the node,
    its index in `parent` (or `null`), and its parent (or `null`).

    Can return `false` to stop checking.<commit_msg>Add note about synchronicity to `readme.md`<commit_after># mdast-util-visit [![Build Status](https://img.shields.io/travis/wooorm/mdast-util-visit.svg?style=flat)](https://travis-ci.org/wooorm/mdast-util-visit) [![Coverage Status](https://img.shields.io/coveralls/wooorm/mdast-util-visit.svg?style=flat)](https://coveralls.io/r/wooorm/mdast-util-visit?branch=master)

[**mdast**](https://github.com/wooorm/mdast) utility to recursively walk
over nodes: both forwards and backwards.

## Installation

[npm](https://docs.npmjs.com/cli/install):

```bash
npm install mdast-util-visit
```

**mdast-util-visit** is also available for [bower](http://bower.io/#install-packages),
[component](https://github.com/componentjs/component), and
[duo](http://duojs.org/#getting-started), and as an AMD, CommonJS, and globals
module, [uncompressed](mdast-util-visit.js) and
[compressed](mdast-util-visit.min.js).

## Usage

```js
/*
 * Dependencies.
 */

var mdast = require('mdast');
var visit = require('mdast-util-visit');

/*
 * AST.
 */

var ast = mdast.parse('Some *emphasis*, **strongness**, and `code`.');

visit(ast, 'text', console.log.bind(console));
/*
 * {type: 'text', 'value': 'Some '}
 * {type: 'text', 'value': 'emphasis'}
 * {type: 'text', 'value': ', '}
 * {type: 'text', 'value': 'strongness'}
 * {type: 'text', 'value': ', and '}
 * {type: 'text', 'value': '.'}
 */
```

## API

### visit(ast\[, type\], callback\[, reverse\])

>   `visit` is synchronous.

Visit nodes. Optionally by [node type](https://github.com/wooorm/mdast/blob/master/doc/nodes.md),
Optionally in reverse.

*   `ast` (`Node`)
    — [**mdast** node](https://github.com/wooorm/mdast/blob/master/doc/nodes.md);

*   `type` (`string`, optional)
    — Optional node type to invoke `callback` for. By default, all nodes are
    visited.

*   `callback` (`function(node, index?, parent?)`)
    — Callback when a node (matching `type`) is found. Invoked with the node,
    its index in `parent` (or `null`), and its parent (or `null`).

    Can return `false` to stop checking.
{'fraction_non_alphanumeric': 0.2114002478314746, 'fraction_numerical': 0.0, 'mean_word_length': 4.374167776298269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3537820', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1428, 'n_words': 317}