helper function for generator functions, calls the nth yield value or an array of the nth yield values.

Usage no npm install needed!

<script type="module">
  import nthGenerator from 'https://cdn.skypack.dev/nth-generator';



📝 Table of Contents

🧐 About

Eliminates the need to call .next() a couple of times on your generator function before yielding needed values

This is a package of helper functions that return the yield of the nth value or the yields of nth values of generator functions. They return these values immediately, instead of calling .next() severally before a particular yield value(s) can be returned.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine.


Just a properly set up JavaScript development environment, most preferably VSCode, for proper viewing of the JSDoc



Very easy to use, just install

npm install nth-generator --save

🎈 Usage

Importing the package at the top of your file make the helper functions .nth() and .nths() available to your project

var nthGenerator = require('nth-generator');

or ES6

import {nthGenerator} from 'nth-generator'

call the helper functions on the generator function, not on references to the generator function

function* genx() {
  yield {
    name: "paul",
    age: 25,
  yield "Calculus";
  yield 23;
  yield ["age", 17, { day: "Monday" }];
  return 5;
//to use .nths() we provide an array of the indices we need to return and the lenght of available generator yields as arguments, starts from index 1
genx().nths([1,2], 5);
//to use .nth() we provide only an index of the yield we need to return, starts from index 1

[ { name: 'paul', age: 25 }, 'Calculus' ]

["age", 17, { day: "Monday" }]

⛏️ Built Using

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

  • You, the users and contributors