| 1 | # generator-function <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
|---|
| 2 |
|
|---|
| 3 | [![github actions][actions-image]][actions-url]
|
|---|
| 4 | [![coverage][codecov-image]][codecov-url]
|
|---|
| 5 | [![License][license-image]][license-url]
|
|---|
| 6 | [![Downloads][downloads-image]][downloads-url]
|
|---|
| 7 |
|
|---|
| 8 | [![npm badge][npm-badge-png]][package-url]
|
|---|
| 9 |
|
|---|
| 10 | A function that returns the normally hidden `GeneratorFunction` constructor, when available.
|
|---|
| 11 |
|
|---|
| 12 | ## Getting started
|
|---|
| 13 |
|
|---|
| 14 | ```sh
|
|---|
| 15 | npm install --save generator-function
|
|---|
| 16 | ```
|
|---|
| 17 |
|
|---|
| 18 | ## Usage/Examples
|
|---|
| 19 |
|
|---|
| 20 | ```js
|
|---|
| 21 | const assert = require('assert');
|
|---|
| 22 | const GeneratorFunction = require('generator-function')();
|
|---|
| 23 |
|
|---|
| 24 | const fn = new GeneratorFunction('return 1');
|
|---|
| 25 |
|
|---|
| 26 | assert.equal(fn.toString(), 'function* anonymous(\n) {\nreturn 1\n}');
|
|---|
| 27 |
|
|---|
| 28 | const iterator = fn();
|
|---|
| 29 |
|
|---|
| 30 | assert.deepEqual(iterator.next(), { done: true, value: 1 });
|
|---|
| 31 | ```
|
|---|
| 32 |
|
|---|
| 33 | ## Tests
|
|---|
| 34 |
|
|---|
| 35 | Clone the repo, `npm install`, and run `npm test`
|
|---|
| 36 |
|
|---|
| 37 | [package-url]: https://npmjs.org/package/generator-function
|
|---|
| 38 | [npm-version-svg]: https://versionbadg.es/TimothyGu/generator-function.svg
|
|---|
| 39 | [deps-svg]: https://david-dm.org/TimothyGu/generator-function.svg
|
|---|
| 40 | [deps-url]: https://david-dm.org/TimothyGu/generator-function
|
|---|
| 41 | [dev-deps-svg]: https://david-dm.org/TimothyGu/generator-function/dev-status.svg
|
|---|
| 42 | [dev-deps-url]: https://david-dm.org/TimothyGu/generator-function#info=devDependencies
|
|---|
| 43 | [npm-badge-png]: https://nodei.co/npm/generator-function.png?downloads=true&stars=true
|
|---|
| 44 | [license-image]: https://img.shields.io/npm/l/generator-function.svg
|
|---|
| 45 | [license-url]: LICENSE
|
|---|
| 46 | [downloads-image]: https://img.shields.io/npm/dm/generator-function.svg
|
|---|
| 47 | [downloads-url]: https://npm-stat.com/charts.html?package=generator-function
|
|---|
| 48 | [codecov-image]: https://codecov.io/gh/TimothyGu/generator-function/branch/main/graphs/badge.svg
|
|---|
| 49 | [codecov-url]: https://app.codecov.io/gh/TimothyGu/generator-function/
|
|---|
| 50 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/TimothyGu/generator-function
|
|---|
| 51 | [actions-url]: https://github.com/TimothyGu/generator-function/actions
|
|---|