filt is for simple filters: node -e 'require("filt")(line => line.toUpperCase())'
JavaScript Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE.md
README.md
example1.js
example2.js
example3.js
example4.js
example5.sh
example6.sh
index.js
package.json

README.md

node filt

filt is for simple filters:

node -e 'require("filt")(line => line.toUpperCase())'

This module allows you to quickly write command-line filters - programs that read standard input line by line and print something on standard output.

Known problems

It prints an extra newline at the end - the split module used internally is apparently running the callback with an extra empty line at the end when there is none - I need to fix it.

Installation

Install to use in your project, updating the dependencies in package.json:

npm install filt --save

It currently has one dependency: split ...

Usage

Require the module:

var filt = require('filt');

Now filt is a function that gets a function that is called for each line of stdin.

Most basic usage:

filt(function (line) {
    console.log(line.toUpperCase());
});

Instead of calling console.log() you can also return a line to print:

filt(function (line) {
    return line.toUpperCase();
});

The same using ES6 syntax:

filt(line => line.toUpperCase());

Using require in the same line - this is the entire program:

require('filt')(line => line.toUpperCase());

Or straight from the command line:

node -e 'require("filt")(line => line.toUpperCase());'

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Rafał Pocztarski - https://github.com/rsp

License

MIT License (Expat). See LICENSE.md for details.