0.2.0 • Published 6 years ago

@keepzen/object-stream v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@keepzen/object-stream

You can find the source at GitHub.

Now do not need to write the tedious of .pipe(ObjectStream.someMethod(f))s. map(f), reduce(f) and other methods have piped this stream into the new one.

@keepzen/object-stream~ObjectStream

ObjectStream.

It is a transform stream, use to transform items of upstream to a another form.

A stream like a array, they are all have items. We can map, filter, and reduce on an array, and now with help of ObjectStream, we can do these on stream.

Kind: inner class of @keepzen/object-stream

new ObjectStream()

Do NOT create instance with new.

Just use static methods to get instance.

objectStream.transform ⇒ ObjectStream

Alias of map method.

Kind: instance property of ObjectStream

ParamType
ffuncttion

objectStream.filterIn ⇒ ObjectStream

Alias offilter method.

Kind: instance property of ObjectStream

ParamType
f,function

objectStream.source() ⇒ ReadableStream | ObjectStream

Get the source of this stream.

Kind: instance method of ObjectStream

objectStream.finish(f)

Add finish event handler for this stream.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunctionA function require no argument.

objectStream.map(f, options) ⇒ ObjectStream

Transform upstream with function f.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunctionf(data)=>anotherFormOfData
optionsobject
options.spreadbooleanWhether to spread the result if it is a array. The Default value is false.
options.filterOutUndefinedbooleanWhether filter out the undefined from upstream. The default is false.

objectStream.reduce(f, initResult) ⇒ ObjectStream

Reduce the upstream with function f.

The return stream will read many time from upstream, but just write once to downstream.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunction(result,data)=>resultType;
initResultobjectThe initialization result pass to reducer f.

objectStream.cond(conds) ⇒ ObjectStream

Process the items with conditions.

If there are some conditions can not be handle, they are jest ignored, and not to flow to downstream.

Kind: instance method of ObjectStream

ParamTypeDescription
condsArray(object)The item of the array, is a object, like {pred,mapper}, the precd is function(object)=>boolean, and mapper is function(object)=>annotherObject.

objectStream.filter(f) ⇒ ObjectStream

Filter the stream.

Iff the f(obj) == true, the obj will flow to downstream.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunction(obj)=>boolean .

objectStream.filterOut(f) ⇒ ObjectStream

Filter out items from upstream.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunctionIf f(data) == true, the data will filter out from upstream.

objectStream.if(cond, then, elseFun) ⇒ ObjectStream

If-then-else clause in stream.

Kind: instance method of ObjectStream

ParamTypeDescription
condfunctionfunction(obj)=>boolean.
thenfunctionfunction(obj)=>anotherObj. The condition is satisfied, the function will be called.
elseFunfunctionfunction(obj)=>anotherObje. The condition is not satisfied this function will be called. This is option. If there is not elseFn, the item which don't satisfy the condition, will be ignored.

objectStream.observer(f) ⇒ ObjectStream

Just observe the stream items with function f, not change them.

Kind: instance method of ObjectStream

ParamTypeDescription
ffunctionThe function use to observer stream item.

ObjectStream.create() ⇒ ObjectStream

Create a ObjectStream instance.

You can use .map(f), .filter(f) or other methods to get a new stream object, but the function f will never be called, until some data be write to this stream or one readable stream pipe to this object.

Kind: static method of ObjectStream
Returns: ObjectStream - .

ObjectStream.from(upstream, where) ⇒ ObjectStream

Create a new stream from a upstream.

Kind: static method of ObjectStream

ParamTypeDescription
upstreamReadableStream
wherefunctionA Function return boolean. Default is function always return true.

@keepzen/object-stream~getChuckToLinesHandler(code) ⇒ function

Get a function that can use to transform a chuck to Array of string.

Kind: inner method of @keepzen/object-stream
Returns: function - - f(bufferOrString)=>Array(string)

ParamTypeDefaultDescription
codestring"utf8"The encode of the chuck. Default is 'uft8'.
0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago