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

findatag

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

findatag

A specialized tokenizer for finding dust-style tags ({@tagname [attributes]/})

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
314
increased by11.35%
Maintainers
3
Weekly downloads
 
Created
Source

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();
    }
}

Keywords

FAQs

Package last updated on 16 Apr 2015

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