1.0.2 • Published 5 years ago

mhysa v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Mhysa

Dependency-free stream utils for Node.js

Released under the MIT license.

yarn add mhysa

Tested with Node.js versions 8+

fromArray(array)

Convert an array into a Readable stream of its elements

ParamTypeDescription
arrayT[]Array of elements to stream

map(mapper, options)

Return a ReadWrite stream that maps streamed chunks

ParamTypeDescription
mapper(chunk: T, encoding: string) => RMapper function, mapping each (chunk, encoding) to a new chunk (or a promise of such)
optionsobject
options.readableObjectModebooleanWhether this stream should behave as a readable stream of objects
options.writableObjectModebooleanWhether this stream should behave as a writable stream of objects

flatMap(mapper, options)

Return a ReadWrite stream that flat maps streamed chunks

ParamTypeDescription
mapper(chunk: T, encoding: string) => R[]Mapper function, mapping each (chunk, encoding) to an array of new chunks (or a promise of such)
optionsobject
options.readableObjectModebooleanWhether this stream should behave as a readable stream of objects
options.writableObjectModebooleanWhether this stream should behave as a writable stream of objects

filter(predicate, options)

Return a ReadWrite stream that filters out streamed chunks for which the predicate does not hold

ParamTypeDescription
predicate(chunk: T, encoding: string) => booleanPredicate with which to filter scream chunks
optionsobject
options.objectModebooleanbooleanWhether this stream should behave as a stream of objects

reduce(iteratee, initialValue, options)

Return a ReadWrite stream that reduces streamed chunks down to a single value and yield that value

ParamTypeDescription
iteratee(chunk: T, encoding: string) => RReducer function to apply on each streamed chunk
initialValueTInitial value
optionsobject
options.readableObjectModebooleanWhether this stream should behave as a readable stream of objects
options.writableObjectModebooleanWhether this stream should behave as a writable stream of objects

split(separator)

Return a ReadWrite stream that splits streamed chunks using the given separator

ParamTypeDescription
separatorstringSeparator to split by, defaulting to "\n"

join(separator)

Return a ReadWrite stream that joins streamed chunks using the given separator

ParamTypeDescription
separatorstringSeparator to join with

replace(searchValue, replaceValue)

Return a ReadWrite stream that replaces occurrences of the given string or regular expression in the streamed chunks with the specified replacement string

ParamTypeDescription
searchValuestring | RegExpSearch string to use
replaceValuestringReplacement string to use

parse()

Return a ReadWrite stream that parses the streamed chunks as JSON

stringify()

Return a ReadWrite stream that stringifies the streamed chunks to JSON

collect(options)

Return a ReadWrite stream that collects streamed chunks into an array or buffer

ParamTypeDescription
optionsobject
options.objectModebooleanWhether this stream should behave as a stream of objects

concat(streams)

Return a Readable stream of readable streams concatenated together

ParamTypeDescription
streams...Readable[]Readable streams to concatenate

merge(streams)

Return a Readable stream of readable streams merged together in chunk arrival order

ParamTypeDescription
streams...Readable[]Readable streams to merge

duplex(writable, readable)

Return a Duplex stream from a writable stream that is assumed to somehow, when written to, cause the given readable stream to yield chunks

ParamTypeDescription
writableWritableWritable stream assumed to cause the readable stream to yield chunks when written to
readableReadableReadable stream assumed to yield chunks when the writable stream is written to

child(childProcess)

Return a Duplex stream from a child process' stdin and stdout

ParamTypeDescription
childProcessChildProcessChild process from which to create duplex stream

last(readable)

Return a Promise resolving to the last streamed chunk of the given readable stream, after it has ended

ParamTypeDescription
readableReadableReadable stream to wait on
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.6.0-beta.0

5 years ago

0.5.0

5 years ago

0.5.0-beta.1

5 years ago

0.5.0-beta.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.6

5 years ago