3.0.1 • Published 12 months ago

it-pipe v3.0.1

Weekly downloads
7,058
License
Apache-2.0 OR MIT
Repository
github
Last release
12 months ago

it-pipe

codecov CI

Utility to "pipe" async iterables together

Table of contents

Install

$ npm i it-pipe

Browser <script> tag

Loading this module through a script tag will make it's exports available as ItPipe in the global namespace.

<script src="https://unpkg.com/it-pipe/dist/index.min.js"></script>

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).

API Docs

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.

@lodestar/beacon-nodejs-libp2p-noisetlg-managerlibp2p@everything-registry/sub-chunk-1939miniswapmint.club-v2-filebasemtcrawleemultistream-selectnft.storagenft.storage-vmyel-client@xmader/ipfs-core@waku/core@waku/peer-exchange@waku/staging@zalastax/nolb-it-@web3-storage/multistream-select@zippie/ipfs-bitswap@zerodao/requestaxon-webtorrentaxonproto-lib@autismjs/protocol@aztec/p2p@compendia/ipfs-bitswap-commonjs@compendia/ipfs-core@compendia/libp2p-commonjsbotania@dao-xyz/libp2p-webrtc@dao-xyz/libp2p-noise@daishi/ipfs-pubsub-room@dcdn/data-transfer@dcdn/graphsync@blockless/browser-node@canvas-js/gossiplog@canvas-js/libp2p-okra-service@canvas-js/pubsub-service-discovery@canvas-js/storequorum-gossipsubvelitminimatlg-manager-testwagglewalletdropxzarsk-chain@decloudlabs/stk-v2starpcss-ipfs-bitswapss-ipfs-bitswap-teststorverse-sao-model@libp2p/autonat@chainsafe/libp2p-gossipsub@chainsafe/libp2p-noise@chainsafe/libp2p-yamux@cinderlink/clientchatterbox-corechatternet-lib@coaty/binding.libp2p@collabswarm/collabswarm-automerge@helia/unixfs@helia/verified-fetch@individe/libp2p-snappy-muxer@drtc/create@digitalnative/p2p@djack-sdk/network@djack-sdk/serverdagula@douganderson444/ipfs-core@achingbrain/libp2p-gossipsub@achingbrain/libp2p-noise@eridanus-network/connection@eridanus-network/js-core.peer@ethereumjs/client@functionland/box@functionland/protocols@galtproject/browser-ipfs@galtproject/libp2p-gossipsub@galtproject/libp2p-interfaces@galtproject/js-ipfs@heirtrust/heirtrust-sdk@gxchain2/network@hoprnet/hopr-utils@hashprotocol/libp2p-noise@0xvaibhav/libp2p-events@0xvaibhav/libp2p-events-client@instadapp/iga-node@instadapp/interop-nodedenetwork-gossipsubdatastore-core@dstack-js/transport@dstanesc/ipfs-core-store-access@filebase/client@fluencelabs/js-client@fluencelabs/js-peer@fluencelabs/connection@chris.troutner/ipfs-cli@chris.troutner/ipfs-core@chris.troutner/ipfs-grpc-server@chris.troutner/ipfs-http-server@chris.troutner/orbitdb-helia
3.0.1

12 months ago

3.0.0

12 months ago

2.0.5

1 year ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago