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.
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
none
Very easy to use, just install
npm install nth-generator --save
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
genx().nth(4)
[ { name: 'paul', age: 25 }, 'Calculus' ]
["age", 17, { day: "Monday" }]
- NodeJs - Server Environment
- @thesirtaylor - Idea & Initial work
See also the list of contributors who participated in this project.
- You, the users and contributors