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

duplex-to

v2.0.0

Published

Wraps a duplex stream and hides the readable or the writable interface

Downloads

82,006

Readme

duplex-to

build status npm version

duplex-to wraps a duplex stream with a Proxy and hides the readable or the writable interface. Hidding part of the interface can be useful in cases where errors are thrown or the code behaves different based on the interface type. This package allows to show only one part of a duplex stream for those cases.

Usage

readable

The readable function wraps a duplex stream to show only the readable interface. It can be loaded either by path or from the main module by property:

import readable from 'duplex-to/readable.js'
import { readable } from 'duplex-to'

The function is a factory which returns the wrapped stream. The stream which should be wrapped must be given as argument:

const readableStream = readable(duplexStream)

writable

The writable function wraps a duplex stream to show only the writable interface. It can be loaded either by path or from the main module by property:

import writable from 'duplex-to/writable.js'
import { writable } from 'duplex-to'

The function is a factory which returns the wrapped stream. The stream which should be wrapped must be given as argument:

const writableStream = writable(duplexStream)

Example

The following examples creates a PassThrough duplex stream, which is used to write a text string and allows to access it via the readable stream interface. The function noWritablesAccepted accepts only readable streams and writes the data from the stream to stdout. Passing the PassThrough object to the function would throw an error, but with the wrapper only the readable part is visible to the function.

import duplexToReadable from 'duplex-to/readable.js'
import { isWritableStream } from 'is-stream'
import { PassThrough } from 'readable-stream'

// dummy function which
//   - doesn't accept streams with writable interface
//   - just writes the incoming data to stdout 
function noWritablesAccepted (stream) {
  if (isWritableStream(stream)) {
    throw new Error('no writable streams supported')
  }

  stream.on('data', chunk => process.stdout.write(chunk))
}

const stream = new PassThrough()
const readable = duplexToReadable(stream)

// the next line would throw an error if it would be called with stream
noWritablesAccepted(readable)

stream.write('Hello ')
stream.end('World!\n')