generator-function

1.0.0 • Public • Published

generator-function

Expose the ES2015 GeneratorFunction constructor.

Build Status Dependency Status devDependency Status npm version

Installation

npm install generator-function

Description

Like Functions, one could create generator functions from a JavaScript string through a special constructor called GeneratorFunction. However, the constructor function is not available as a global, so one has to use the constructor property of an existing generator function.

This module makes it easy to do so, and falls back gracefully when a runtime not supporting generator functions is encountered.

Usage

On a platform supporting generator functions:

var GeneratorFunction = require('generator-function')
 
var generatorFunction = new GeneratorFunction('arg1', 'yield arg1')
var generator = generatorFunction(1)
 
generator.next()
//=> { value: 1, done: false }
generator.next()
//=> { value: undefined, done: true }

On a runtime that does not support them:

var GeneratorFunction = require('generator-function')
 
GeneratorFunction
// => undefined

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i generator-function

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • timothygu