UNPKG

2.34 kBMarkdownView Raw
1# unist-util-inspect [![Build Status](https://img.shields.io/travis/wooorm/unist-util-inspect.svg)](https://travis-ci.org/wooorm/unist-util-inspect) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/unist-util-inspect.svg)](https://codecov.io/github/wooorm/unist-util-inspect?branch=master)
2
3[Unist](https://github.com/wooorm/unist) node inspector.
4
5## Installation
6
7[npm](https://docs.npmjs.com/cli/install):
8
9```bash
10npm install unist-util-inspect
11```
12
13[Component.js](https://github.com/componentjs/component):
14
15```bash
16component install wooorm/unist-util-inspect
17```
18
19[Bower](http://bower.io/#install-packages):
20
21```bash
22bower install unist-util-inspect
23```
24
25[Duo](http://duojs.org/#getting-started):
26
27```javascript
28var inspect = require('wooorm/unist-util-inspect');
29```
30
31**unist-util-inspect** is also available for [bower](http://bower.io/#install-packages),
32[component](https://github.com/componentjs/component), [duo](http://duojs.org/#getting-started),
33and for AMD, CommonJS, and globals ([uncompressed](unist-util-inspect.js) and
34[compressed](unist-util-inspect.min.js)).
35
36## Usage
37
38```javascript
39var retext = require('retext');
40var inspect = require('unist-util-inspect');
41
42retext().use(function (cst) {
43 console.log(inspect(cst));
44}).process('Some simple text.');
45```
46
47Yields:
48
49```text
50RootNode[1]
51└─ ParagraphNode[1]
52 └─ SentenceNode[6]
53 ├─ WordNode[1]
54 │ └─ TextNode: 'Some'
55 ├─ WhiteSpaceNode[1]
56 │ └─ TextNode: ' '
57 ├─ WordNode[1]
58 │ └─ TextNode: 'simple'
59 ├─ WhiteSpaceNode[1]
60 │ └─ TextNode: ' '
61 ├─ WordNode[1]
62 │ └─ TextNode: 'text'
63 └─ PunctuationNode[1]
64 └─ TextNode: '.'
65```
66
67## API
68
69### inspect([node](https://github.com/wooorm/unist#unist-nodes))
70
71By default, color support is enabled on node and disabled anywhere else.
72See below on how to change that.
73
74**Parameters**
75
76* `node` ([`Node`](https://github.com/wooorm/unist#unist-nodes)).
77
78**Returns** `string` — String representing `node`.
79
80### inspect.\<style\>\[.\<style\>...\](node)
81
82Where `style` is either `color` or `noColor`.
83
84To explicitly add or remove ANSI sequences, use either `inspect.color(node)`
85or `inspect.noColor(node)`.
86
87## License
88
89[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)