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

more-streams

v0.5.7

Published

A collection of useful stream implementations

Downloads

38

Readme

more-streams

npm version Build Status Coverage Status Dependency Status

A collection of useful stream implementations.

This is a library that makes a number of general purpose stream implementation available for your everyday use. This collection will grow over time, so don't hesitate to make feature requests for a stream implementation that you think should be in this library.

Installation

npm install --save more-streams

Requirements

This library has been written to work with Node.js v6.x and the latest ES2015 features.

API

There are 2 ways to include streams:

var CountStream = require('more-streams').CountStream;

or

var CountStream = require('more-streams/CountStream');

All streams extend a standard stream implementation and pass on any constructor options that are standard for this type of stream. Some of the helpers extend that options object for their specific use.

For more details take a look at the jsdoc and the tests.

ConsoleStream

This is a stream that outputs data to console (or any other output). It supports coloring output based on regular expression matches.

var ConsoleStream = require('more-streams/ConsoleStream');
var out = new ConsoleStream({
  colors: [{
    match: /error/g,
    styles: ['red', 'bold']
  }]
});
otherStream.pipe(out);

// -> prints to console with errors in bold and red

For more styles that you can apply take a look at chalk

CountStream

This is a stream that will count the number of bytes that have passed through.

var CountStream = require('more-streams/CountStream');
var counter = new CountStream();
counter.on('end', () => console.log(counter.count)); // -> prints total stream bytes count
otherStream.pipe(counter).pipe(process.stdout);

The stream also allows you to set markers which will trigger an event that you can react to.

var CountStream = require('more-streams/CountStream');
var counter = new CountStream();
counter.addMarker(10);
counter.on('marker', (count, counter) => console.log(count, counter.count)); // -> prints 10, 10
otherStream.pipe(counter).pipe(process.stdout);

MultiplexStream

A stream that will copy data and pipe it to multiple streams.

var MultiplexStream = require('more-streams/MultiplexStream');
var mux = new MultiplexStream();
otherStream.pipe(mux).pipe([process.stdout, process.stdout]);

// -> prints same output to 2 consoles

OffsetStream

A stream that allows to omit data from the beginning and end of another stream.

var OffsetStream = require('more-streams/OffsetStream');
var offset = new OffsetStream({start: 10, end: 20});
otherStream.pipe(offset).pipe(process.stdout);

// -> prints from 10th byte to 20th byte of the total stream

SequenceStream

A stream that allows to sequentially read data from multiple streams into one.

var SequenceStream = require('more-streams/SequenceStream');
var demux = new SequenceStream();
demux.chain(otherStream1, otherStream2, otherStream3);
demux.pipe(process.stdout);

// -> prints in order from stream 1,2 and then 3 to console.

Sink

A stream that will consume all data given. Optionally this stream can buffer all incoming data for later use.

var Sink = require('more-streams/Sink');
var buffer = new Sink({ buffer: true });
buffer.on('end', () => console.log(buffer.message('hex')));  // -> prints to console
otherStream.pipe(buffer);

Writer

A stream that can be preloaded with data ready to be read when a stream triggers a read.

var Writer = require('more-streams/Writer');
var output = new Writer();
output.write('message');
output.pipe(process.stdout);

// -> prints to console 'message'

Tests

To run tests and generate a coverage report run:

npm test