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

es5-generators

v1.1.0

Published

Provides non-ES6 non-coroutine generators in an ES5-style package

Downloads

2

Readme

Generators for ES5

This package provides Promise-like generators which fit natively in ES5. If you are targeting ES6 directly or using transpilation to ES5, you might consider using the standard generators instead. However these generators will work within ES5 runtimes without any transpilation dependencies, which might be useful.

These do not use ES6 iterators or generators, so they are useful where wider compatibility is required.

Installation

Node (server-side):

npm install es5-generators

Now use require('es5-generators') to obtain the Generator class.

Bower (client-side, browser):

bower install es5-generators

Now include bower_components/es5-generators/Generator.js either directly on your page, within your Javascript build step, or using require('./bower_components/es5-generators/Generator.js') if you are using Browserify.

Usage

You can create a Generator in a similar way as a Promise:

new Generator(function(done, reject, emit) {
	emit(1);
	emit(2);
	emit(3);
	done();
});

Wrapping other data types

Generators can wrap other data types.

new Generator([1,2,3]); // emits 1, 2, 3
new Generator(Promise.resolve(123)); // emits 123

Consuming a Generator

You can iterate over a Generator as follows:

var generator = someKindOfQuery();
generator.emit(function(item) {
	console.log(item);
}).done(function() {
	console.log('--finished--');
});

Exceptions/Rejections

Exceptions and rejections work like they do with Promises:

var generator = aFailingQuery();
generator.catch(function(err) {
	console.log('The generator faulted');
});

var generator = new Generator(function(done, reject, emit) {
    reject({message:"Rejection message"});
    // Generator also catches exceptions
    throw {message: "Exception message"};
});

Promise Chaining

You can get all items at once in an array, and even start a promise chain off of a generator's completion:

var generator = someKindOfQuery();
generator.then(function(items) {
	console.log(items);
	return new Promise(...);
}).then(function(result) {
	console.log(result);
});

Note that using Generator.then() will cause O(N) memory usage instead of O(1), which would be very bad for infinite sets, for instance.

Testing

To test this package: npm test

Authors

License

This software is provided under the terms of the MIT License. See COPYING for details.