Skip to content

syntax-tree/unist-util-inspect

Repository files navigation

unist-util-inspect Build Status Coverage Status

Unist node inspector.

Installation

npm:

npm install unist-util-inspect

Component.js:

component install wooorm/unist-util-inspect

Bower:

bower install unist-util-inspect

Duo:

var inspect = require('wooorm/unist-util-inspect');

unist-util-inspect is also available for bower, component, duo, and for AMD, CommonJS, and globals (uncompressed and compressed).

Usage

var retext = require('retext');
var inspect = require('unist-util-inspect');

retext().use(function () {
    return function (cst) {
        console.log(inspect(cst));
    }
}).process('Some simple text.');

Yields:

RootNode[1] (1:1-1:18, 0-17)
└─ ParagraphNode[1] (1:1-1:18, 0-17)
   └─ SentenceNode[6] (1:1-1:18, 0-17)
      ├─ WordNode[1] (1:1-1:5, 0-4)
      │  └─ TextNode: "Some" (1:1-1:5, 0-4)
      ├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)
      ├─ WordNode[1] (1:6-1:12, 5-11)
      │  └─ TextNode: "simple" (1:6-1:12, 5-11)
      ├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)
      ├─ WordNode[1] (1:13-1:17, 12-16)
      │  └─ TextNode: "text" (1:13-1:17, 12-16)
      └─ PunctuationNode: "." (1:17-1:18, 16-17)

API

inspect(node)

By default, color support is enabled on node and turned off anywhere else. See below on how to change that.

Parameters

Returns string — String representing node.

inspect.<style>[.<style>...](node)

Where style is either color or noColor.

To explicitly add or remove ANSI sequences, use either inspect.color(node) or inspect.noColor(node).

License

MIT © Titus Wormer

Contributors 6