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

generator-extensions

v1.0.6

Published

_Like Reactive Extensions for Generators_

Downloads

3

Readme

Generator Extensions

Like Reactive Extensions for Generators

Installation

Add the library to your project

npm install --save generator-extensions

Activate the extensions

require('generator-extensions')

Use the synchronous extensions

function* range(a, b) {
    for (let i = a; i < b; i++) {
        yield i
    }
}

const zero = range(10,20)
    .flatMap(x => [x, -x])
    .map(x => x * 2)
    .reduce((a, b) => a + b)

Use the asynchronous extensions

async function* range(a, b) {
    for (let i = a; i < b; i++) {
        yield i
    }
}

const zero = range(10,20)
    .flatMap(x => [x, -x])
    .map(x => x * 2)
    .reduce((a, b) => a + b)

Operators

toArray

Collects the generator into a single array.

flatMap

The flatMap() method first maps each element using a mapping function, then flattens the result into a new generator.

flat

The flat([depth = 1]) flattens each element to a specified depth into a new generator.

map

The map() method creates a new generator with the results of calling a provided function on every element in the calling generator.

entries

The entries() method returns a new generator that contains the key/value pairs for each index in the generator.

filter

The filter() method creates a new generator with all elements that pass the test implemented by the provided function.

find

The find() method returns the value of the first element in the provided generator that satisfies the provided testing function.

findIndex

The findIndex() method returns the index of the first element in the generator that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.

keys

The keys() method returns a new generator that contains the keys for each index in the generator.

reduce

The reduce() method executes a reducer function (that you provide) on each element of the generator, resulting in a single output value.

some

The some() method tests whether at least one element in the generator passes the test implemented by the provided function. It returns a Boolean value.

every

The every() method tests whether all elements in the generator pass the test implemented by the provided function. It returns a Boolean value.

tap

Execute a function for each element without changing the value emitted.

count

forEach

The forEach() method executes a provided function once for each generator element.

parallel (async only)

The parallel() method executes a provided async function in parallel with other elements, up to a limit provided by the second parameter (default: Infinity). The resulting generator may be in a different order than the source generator.