Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

retext-visit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retext-visit

Retext node visitor

  • 0.2.2
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

retext-visit Build Status Coverage Status

retext node visitor.

Installation

npm:

$ npm install retext-visit

Component:

$ component install wooorm/retext-visit

Bower:

$ bower install retext-visit

Usage

var Retext,
    retext,
    inspect,
    visit;

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

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

API

Node#visit(function(Node): boolean?)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /* Visit every node in the first sentence. */
    tree.head.head.visit(function (node) {
        console.log(node);
    });
    /**
     * Logs:
     *
     * WordNode[1]
     * └─ TextNode: 'A'
     * TextNode: 'A'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'simple'
     * TextNode: 'simple'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'English'
     * TextNode: 'English'
     * WhiteSpaceNode[1]
     * └─ TextNode: ' '
     * TextNode: ' '
     * WordNode[1]
     * └─ TextNode: 'sentence'
     * TextNode: 'sentence'
     * PunctuationNode[1]
     * └─ TextNode: '.'
     * TextNode: '.'
     */
});

Invoke callback for every descendant of the operated on context.

  • callback (function(Node): boolean?): Visitor. Stops visiting when it returns false.

Node#visit(type, callback)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /* Visit every word node. */
    tree.visit(tree.WORD_NODE, function (node) {
        console.log(node);
    });
    /**
     * WordNode[1]
     * └─ TextNode: 'A'
     * WordNode[1]
     * └─ TextNode: 'simple'
     * WordNode[1]
     * └─ TextNode: 'English'
     * WordNode[1]
     * └─ TextNode: 'sentence'
     */
});

Invoke callback for every descendant of the context of type.

  • type: Type of visited nodes.
  • callback (function(Node): boolean?): Visitor. Stops visiting when the return value is false.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 27 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc