npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

streamfilter

v4.0.0

Published

Filtering streams.

Downloads

1,183,170

Readme

streamfilter

Filtering streams.

GitHub license

streamfilter is a function based filter for streams inspired per gulp-filter but no limited to Gulp nor to objectMode streams.

Installation

First, install streamfilter in your project:

npm install --save streamfilter

Getting started

There are 3 common usages:

Simple filter

import { StreamFilter } from 'streamfilter';

const filter = new StreamFilter((chunk, encoding, cb) => {
  const mustBeFiltered = chunk.length() > 128;

  if (mustBeFiltered) {
    cb(true);
    return;
  }
  cb(false);
});

// Print to stdout a filtered stdin
process.stdin.pipe(filter).pipe(process.stdout);

Filter and restore

import { filterStream } from 'streamfilter';

// Here we use the functionnal help
const filter = new filterStream(
  // Here we use an async callback instead
  async (chunk, encoding) => {
    const mustBeFiltered = chunk.length() > 128;

    if (mustBeFiltered) {
      return true;
    }
    return false;
  },
  {
    restore: true,
  },
);

// Print accepted chunks in stdout
filter.pipe(process.stdout);

// Print filtered one to stderr
filter.restore.pipe(process.stderr);

Filter and restore as a passthrough stream

Let's reach total hype!

import { StreamFilter } from 'streamfilter';
import { Transform } from 'stream';

// Filter values
const filter = new StreamFilter(
  (chunk, encoding, cb) => {
    const mustBeFiltered = chunk.length() > 128;
    if (mustBeFiltered) {
      cb(true);
      return;
    }
    cb(false);
  },
  {
    restore: true,
    passthrough: true,
  },
);

// Uppercase strings
const mySuperTransformStream = new Transform({
  transform: (chunk, encoding, cb) =>
    cb(null, Buffer.from(chunk.toString(encoding).toUpperCase(), encoding)),
});

// Pipe stdin
process.stdin
  .pipe(filter)
  // Edit kept chunks
  .pipe(mySuperTransformStream)
  // Restore filtered chunks
  .pipe(filter.restore)
  // and output!
  .pipe(process.stdout);

Note that in this case, this is your responsibility to end the restore stream by piping in another stream or ending it manually.

API

Classes

Functions

StreamFilter

Filter piped in streams according to the given filterCallback.

Kind: global class

new StreamFilter(filterCallback, options)

Options are passed in as is in the various stream instances spawned by this module. So, to use the objectMode, simply pass in the options.objectMode value set to true.

Returns: StreamFilter - The filtering stream

| Param | Type | Description | | --- | --- | --- | | filterCallback | function | Callback applying the filters | | options | Object | Filtering options | | options.passthrough | boolean | Set to true, this option changes the restore stream nature from a readable stream to a passthrough one, allowing you to reuse the filtered chunks in an existing pipeline. | | options.restore | boolean | Set to true, this option create a readable stream allowing you to use the filtered chunks elsewhere. The restore stream is exposed in the FilterStream instance as a restore named property. |

filterStream(filterCallback, options) ⇒

Utility function if you prefer a functional way of using this lib

Kind: global function
Returns: Stream

| Param | | --- | | filterCallback | | options |

Authors

License

MIT