# filter

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

Latest version **0.1.1** (published 2012-07-05) · 0 weekly downloads

## Install

```sh
npm install filter
pnpm add filter
yarn add filter
bun add filter
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2012-07-05 |
| First published | 2011-02-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Tim Smart |
| Maintainers | Tim-Smart |

## Links

- npm: https://www.npmjs.com/package/filter
- Repository: https://github.com/tim-smart/node-filter
- Issues: http://github.com/tim-smart/node-filter/issues
- npm.io page: https://npm.io/package/filter

## Recent versions

- 0.1.1 (latest) — 2012-07-05
- 0.1.0 — 2011-02-25

## README

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

----------------------

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

---
_Source: https://npm.io/package/filter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
