New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

filter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter

A stream filter for node, to create pipable filters for arbitary streams.

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

/ () | |_ ___ _ __ | || | | / _ \ '| | | | | || __/ |
|
| |
||____|_|

USAGE'

var Filter = require('filter');

/*

  • Create a filter fast. Put the write method in the arguments. */ var my_filter = new Filter(function (data) { data.replace('foo', 'bar');

// Just emit a data event to pass the data on. this.emit('data', data); });

/*

  • Or you can overwrite the write method yourself. */ var my_filter = new Filter;

my_filter.write = function (data) { data = data.replace('foo', 'bar');

// Just emit a data event to pass the data on. this.emit('data', data); };

/*

  • Or make a new constructor altogether! */ var util = require('util');

var CoffeeFilter = function () { this.replace = 'coffee'; this.with = 'water';

// Make sure to call the Filter constructor. Filter.call(this); };

// Inherit methods. util.inherits(CoffeeFilter, Filter);

// Then overwrite the write method. CoffeeFilter.prototype.write = function (data) { data = data.replace(this.replace, this.with);

this.emit('data', data); };

// Create a instance var coffee_filter = new CoffeeFilter;

/**

  • Some example pipe action.
  • Will read from java.txt, replace Java with Node, then save to node.txt -
  • all in real time! */ var fs = require('fs');

var read_stream = fs.createReadStream('/home/guy/java.txt'), write_stream = fs.createWriteStream('/home/guy/node.txt');

var filter = new Filter(function (data) { this.emit('data', data.replace(/java/gi, 'node')); });

read_stream.setEncoding('utf8');

read_stream.pipe(filter); filter.pipe(write_stream);

FAQs

Package last updated on 05 Jul 2012

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