Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

it-pipe

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-pipe

Utility to "pipe" async iterables together

  • 2.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
decreased by-17.51%
Maintainers
2
Weekly downloads
 
Created
Source

it-pipe

codecov CI

Utility to "pipe" async iterables together

Table of contents

Install

$ npm i it-pipe

Based on this definition of streaming iterables https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9.

Almost identical to the pipeline function from the streaming-iterables module except that it supports duplex streams and will automatically wrap a "source" as the first param in a function.

Usage

import { pipe } from 'it-pipe'

const result = await pipe(
  // A source is just an iterable, this is shorthand for () => [1, 2, 3]
  [1, 2, 3],
  // A transform takes a source, and returns a source.
  // This transform doubles each value asynchronously.
  function transform (source) {
    return (async function * () { // A generator is async iterable
      for await (const val of source) yield val * 2
    })()
  },
  // A sink, it takes a source and consumes it, optionally returning a value.
  // This sink buffers up all the values from the source and returns them.
  async function collect (source) {
    const vals = []
    for await (const val of source) {
      vals.push(val)
    }
    return vals
  }
)

console.log(result) // 2,4,6

API

pipe(firstFn, ...fns)

Calls firstFn and then every function in fns with the result of the previous function. The final return is the result of the last function in fns.

Note:

  • firstFn may be a Function or an Iterable
  • firstFn or any of fns may be a duplex object (an object with a sink and source).

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

FAQs

Package last updated on 06 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc