Git Product home page Git Product logo

findatag's Introduction

findatag

String tokenizer configured to recognize a particular pattern: {@[A-Za-z._] [attrs...]/}.

API

createParseStream(entityHandler)

This factory method creates a ParseStream initialized with the provided entity handler.

var finder = require('findatag');

var stream = finder.createParseStream(handler);
fs.createReadStream('./file/to/process').pipe(stream).pipe(process.stdout);

parse(file, entityHandler, callback)

Reads the file at the given file path and parses it, passing entity information to the provided entity handler.

var finder = require('findatag');

finder.process('./file/to/process', handler, function (err, result) {
    // result is the full processed file
});

Entity Handler

The parser needs to be provided with an entity handler that provides the implementation for what to be done when the parse encounters a particular entity: tag or text.

tags

Getter exposing an array of strings or a comma-delimited string containing the names of tags recognized by this handler.

onTag(definition, callback)

The method invoked when any given tag is enountered. The tag definition is has the structure:

{
    name: 'tagname',
    attributes: {
        'attributeName': 'attributeValue'
    }
}

The callback has the signature function (err, result) and should be invoked with the string with which to replace the original tag.

// ...

onTag: function (def, cb) {
    cb(null, def.name.toUpperCase());
}

//...

onText(chunk, callback) [optional]

This optional delegate method can perform operations on the provide text chunk. The callback has the signature function (err, result) and should be invoked with the string with which to replace the original text.

Example

var finder = require('findatag');

var entityHandler = {
    _handlers: {
       'pre': { ... },
       'foo': { ... }
    },

    get tags () {
        return Object.keys(this._handlers);
    },

    onTag: function (def, cb) {
        this._handlers[def.name].exec(def, cb);
    },

    onText: function (chunk, cb) {
        cb(null, chunk.toUpperCase();
    }
}

findatag's People

Contributors

aredridel avatar grawk avatar jasisk avatar jeffharrell avatar lensam69 avatar pvenkatakrishnan avatar rragan avatar subeeshcbabu avatar totherik avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.