npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@keepzen/object-stream

v0.2.0

Published

Transfrom Stream support map, filter and reduce

Downloads

8

Readme

@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'. |