Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

generator-function

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generator-function

Expose the GeneratorFunction constructor if supported by the runtime

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
38M
13.96%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

generators

FAQs

Package last updated on 11 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts