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

strung

v1.3.0

Published

Readable stream to send a string, Writable stream to gather a string, or both.

Downloads

175

Readme

strung

Build Status npm version Coverage Status

Readable stream to send a string, Writable stream to gather a string, or both.

Features:

  1. uses StringDecoder to properly decode Buffer chunks into strings.
  2. stores string chunks in an array to concatenate (and cache result) upon accessing property strung.string. This avoids concatenating each time a chunk is received.
  3. reusable via reset/pipe.
  4. is a Duplex so it can be both a source and a sink at the same time.

Install

npm install --save strung

Usage

Show:

  1. using it as a source (a Readable with string content)
  2. using it as a sink (a Writable collecting string content)
  3. as both a source and a sink at once
  4. getting its class
  5. resetting an instance with a new string (to use as a source)
  6. resetting an instance with pipe(string) (to use as a source)
// Piping out: Strung as a source

// 1a. get builder function:
const buildStrung = require('strung')

// 1b. create instance with string to pipe out:
const strung = buildStrung('some string')

// 1c. pipe string to another stream:
strung.pipe(anotherStream)


// 2a. get builder function to use to create instances:
const buildStrung = require('strung')

// 2b. create an instance with a string and pipe it to another stream:
buildStrung('some string').pipe(anotherStream)

//  or:
buildStrung.pipe('some string').pipe(anotherStream)


// Piping in: Strung as a sink

// 3a. get strung function to create an instance:
const buildStrung = require('strung')

// 3b. create a source strung:
const sink = Strung()

// 3c. use event to get full string from sink:
sink.on('finish', () => {
  console.log('collected string:', sink.string)
})

// 3d. pipe stream to strung:
anotherStream.pipe(sink)


// Both source and sink

// 4a. get build function:
const buildStrung = require('strung')

// 4b. build an instance:
const strung = buildStrung('some string')

// 4c. use event to get full string from it
strung.on('finish', () => {
  console.log('collected string:', strung.string)
})

// 4d. pipe to another stream and then back to itself:
//  * acts as a Readable to provide the string.
//  * acts as a Writable to receive the final string.
strung.pipe(anotherStream).pipe(strung)


// Or, use separate instances for source and sink.

// Also, the Strung class is also exported as a sub-property:
const { Strung } = require('strung')

// 6b. create an instance as a source (has a string) (can be a sink, too)
const source = new Strung('some string')

// 6c. create an instance as a sink (no string) (also a source w/out content)
const sink = new Strung


// Reset strung instance with new string

// 7a. create a strung instance:
const strung = buildStrung('some string')

// 7b. use event to continue when it's done:
strung.on('finish', () => {
  console.log('collected string:', strung.string)

  // 7d. reuse it to pipe something else via reset
  strung.reset('a new string').pipe(differentStream).pipe(strung)

  // OR:
  // 7e. call pipe with a string which does a reset and returns itself
  strung.pipe('a new string').pipe(differentStream).pipe(strung)
})

// 7c. pipe strung into first stream and then itself:
strung.pipe(anotherStream).pipe(strung)

MIT License