Skip to content

KeepZen/ObjectStream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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

Param Type
f functtion

objectStream.filterIn ⇒ ObjectStream

Alias offilter method.

Kind: instance property of ObjectStream

Param Type
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

Param Type Description
f function A function require no argument.

objectStream.map(f, options) ⇒ ObjectStream

Transform upstream with function f.

Kind: instance method of ObjectStream

Param Type Description
f function f(data)=>anotherFormOfData
options object
options.spread boolean Whether to spread the result if it is a array. The Default value is false.
options.filterOutUndefined boolean Whether 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

Param Type Description
f function (result,data)=>resultType;
initResult object The 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

Param Type Description
conds Array(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

Param Type Description
f function (obj)=>boolean .

objectStream.filterOut(f) ⇒ ObjectStream

Filter out items from upstream.

Kind: instance method of ObjectStream

Param Type Description
f function If 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

Param Type Description
cond function function(obj)=>boolean.
then function function(obj)=>anotherObj. The condition is satisfied, the function will be called.
elseFun function function(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

Param Type Description
f function The 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

Param Type Description
upstream ReadableStream
where function A 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)

Param Type Default Description
code string "utf8" The encode of the chuck. Default is 'uft8'.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published