0.4.2 • Published 10 years ago

retext-inspect v0.4.2

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

retext-inspect Build Status Coverage Status

retext node inspector.

Installation

npm:

$ npm install retext-inspect

Component.js:

$ component install wooorm/retext-inspect

Bower:

$ bower install retext-inspect

Duo:

var inspect = require('wooorm/retext-inspect');

Usage

var Retext = require('retext');
var inspect = require('retext-inspect');

var retext = new Retext().use(inspect);

retext.parse('Some simple text.', function (err, tree) {
    /* Inspect a node: */
    console.log(tree.head.head.tail.inspect());
    /*
     * Logs:
     *
     * PunctuationNode[1]
     * └─ TextNode: '.'
     */

    /* Inspect a node in Node.js: */
    console.log(tree);
    /*
     * Logs:
     *
     * RootNode[1]
     * └─ ParagraphNode[1]
     *    └─ SentenceNode[6]
     *       ├─ WordNode[1]
     *       │  └─ TextNode: 'Some'
     *       ├─ WhiteSpaceNode[1]
     *       │  └─ TextNode: ' '
     *       ├─ WordNode[1]
     *       │  └─ TextNode: 'simple'
     *       ├─ WhiteSpaceNode[1]
     *       │  └─ TextNode: ' '
     *       ├─ WordNode[1]
     *       │  └─ TextNode: 'text'
     *       └─ PunctuationNode[1]
     *          └─ TextNode: '.'
     */
});

API

Retext#use(inspect, options?)

retext = new Retext().use(inspect, {
    'color': false
});

Options:

  • color (boolean, default true) - The diagram returned by inspect uses color to make things more awesome. Support is detected by checking if a util.inspect() exists (it does in Node.js). To overwrite this, pass an options object as a second argument to Retext#use(), with a color property set to false.

Node#inspect()

Get a string representing node.

There’s no need to call Node#inspect() when in Node.js. In Node.js, console.log and util.inspect all show the tree diagram as seen above.

To log the nodes as normal objects, pass customInspect: false to util.inspect():

console.log(util.inspect(tree, {
    'customInspect': false
}))

Performance

             TextOM.Node#inspect()
  1,062 op/s » A paragraph (5 sentences, 100 words)
    101 op/s » A section (10 paragraphs, 50 sentences, 1,000 words)
      9 op/s » An article (100 paragraphs, 500 sentences, 10,000 words)

License

MIT © Titus Wormer

0.4.2

10 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago