generator-function <sup>Version Badge</sup>

github actions coverage License Downloads

npm badge

A function that returns the normally hidden GeneratorFunction constructor, when available.

Getting started

npm install --save generator-function

Usage/Examples

const assert = require('assert');
const GeneratorFunction = require('generator-function')();

const fn = new GeneratorFunction('return 1');

assert.equal(fn.toString(), 'function* anonymous(\n) {\nreturn 1\n}');

const iterator = fn();

assert.deepEqual(iterator.next(), { done: true, value: 1 });

Tests

Clone the repo, npm install, and run npm test

generator-function - Installation

To install generator-function via this registry, you'll need to install via the --registry parameter with your package manager.

n

NPM

npm install generator-function --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Yarn

yarn config set registry https://js.registry.sudovanilla.org
yarn install generator-function

Learn more about the config option.

PNPM

pnpm install generator-function --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Bun Logo

Bun

bun install generator-function --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Learn more about setting this up in your bunfig.toml configuration.


For Deno, add the following to your .npmrc file in your directory:

registry="https://js.registry.sudovanilla.org"

Then run the deno install command.

generator-function - Download

Download Tarball (v2.0.1)

Integrity sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g==
SHASUM 0e75dd410d1243687a0ba2e951b94eedb8f737a2
Tarball https://js.registry.sudovanilla.org/generator-function/-/generator-function-2.0.1.tgz