@giancosta86/stream-utils
v2.2.0
Published
Utilities for streams and iterables
Downloads
14
Maintainers
Readme
stream-utils
Utilities for streams and iterables
stream-utils is a minimalist TypeScript library providing utilities for streams and iterables.
In particular:
AsyncIterable.from()
takes a variable list of arguments of any type, creating anAsyncIterable
which returns their values. Each argument can be:an
Iterable
or anAsyncIterable
: in this case, its elements will be yielded, one by oneany other data type: it will be yielded as it is
AsyncIterable.wrapXml()
: takes anAsyncIterable<string>
of XML chunks and returns another - having a customizable XML opening tag at the beginning and the related closing tag at the endaddBatchListener()
: attaches an event listener - to any event of anyStream
- that gets called only after such event has been notified the number of timesIterable.isEmpty()
: returns if theIterable
is emptyIterable.isSupported()
: type guard ensuring that the value is anIterable
Iterable.getFirst()
: returns the first item of anIterable
; if suchIterable
is empty, an error is thrownIterable.equals()
: returnstrue
if the two given iterables have the same length - and all the items at the same position are equal according to the given equality function passed as the optional 3rd argument (by default, strict equality via===
)Iterable.rangeIncluding()
: returns anIterable<number>
returning the values from the lower bound L up to the upper bound U - including both. If L > U, an emptyIterable
is returned instead
Installation
npm install @giancosta86/stream-utils
or
yarn add @giancosta86/stream-utils
The public API entirely resides in the root package index, so you shouldn't reference specific modules.
Further reference
For additional examples, please consult the unit tests in the source code repository.