package
Utility to "pipe" async iterables together
npm install it-pipeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Utility to "pipe" async iterables together
$ npm i it-pipe<script> tagLoading 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.
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) {
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 IterablefirstFn or any of fns may be a duplex object (an object with a sink and source).Licensed under either of
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.
alanshaw
alan138@gmail.com
Estimated unpacked size across 8 packages.
218.2 kB
Includes dependencies.
3 direct dependencies.