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
- new ObjectStream()
- instance
- .transform ⇒
ObjectStream
- .filterIn ⇒
ObjectStream
- .source() ⇒
ReadableStream
|ObjectStream
- .finish(f)
- .map(f, options) ⇒
ObjectStream
- .reduce(f, initResult) ⇒
ObjectStream
- .cond(conds) ⇒
ObjectStream
- .filter(f) ⇒
ObjectStream
- .filterOut(f) ⇒
ObjectStream
- .if(cond, then, elseFun) ⇒
ObjectStream
- .observer(f) ⇒
ObjectStream
- .transform ⇒
- static
- .create() ⇒
ObjectStream
- .from(upstream, where) ⇒
ObjectStream
- .create() ⇒
- ~getChuckToLinesHandler(code) ⇒
function
- ~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
- ~ObjectStream
- new ObjectStream()
- instance
- .transform ⇒
ObjectStream
- .filterIn ⇒
ObjectStream
- .source() ⇒
ReadableStream
|ObjectStream
- .finish(f)
- .map(f, options) ⇒
ObjectStream
- .reduce(f, initResult) ⇒
ObjectStream
- .cond(conds) ⇒
ObjectStream
- .filter(f) ⇒
ObjectStream
- .filterOut(f) ⇒
ObjectStream
- .if(cond, then, elseFun) ⇒
ObjectStream
- .observer(f) ⇒
ObjectStream
- .transform ⇒
- static
- .create() ⇒
ObjectStream
- .from(upstream, where) ⇒
ObjectStream
- .create() ⇒
Do NOT create instance with new
.
Just use static methods to get instance.
Alias of map method.
Kind: instance property of ObjectStream
Param | Type |
---|---|
f | functtion |
Alias offilter method.
Kind: instance property of ObjectStream
Param | Type |
---|---|
f, | function |
Get the source of this stream.
Kind: instance method of ObjectStream
Add finish
event handler for this stream.
Kind: instance method of ObjectStream
Param | Type | Description |
---|---|---|
f | function |
A function require no argument. |
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 . |
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 . |
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 . |
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 . |
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. |
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. |
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. |
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
- .
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. |
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'. |