What is is-generator?
The is-generator npm package is a utility for checking if a given value is a generator function or a generator object. This can be useful in various scenarios where you need to handle generator functions or objects differently from other types of functions or objects.
What are is-generator's main functionalities?
Check if a value is a generator function
This feature allows you to check if a given function is a generator function. The `isGenerator.fn` method returns true if the input is a generator function and false otherwise.
const isGenerator = require('is-generator');
function* genFunc() {}
console.log(isGenerator.fn(genFunc)); // true
console.log(isGenerator.fn(function() {})); // false
Check if a value is a generator object
This feature allows you to check if a given value is a generator object. The main `isGenerator` method returns true if the input is a generator object and false otherwise.
const isGenerator = require('is-generator');
function* genFunc() {}
const genObj = genFunc();
console.log(isGenerator(genObj)); // true
console.log(isGenerator({})); // false
Other packages similar to is-generator
is-generator-function
The is-generator-function package provides a utility to check if a given function is a generator function. It is similar to the `isGenerator.fn` method in the is-generator package but does not provide functionality to check for generator objects.
is-gen-fn
The is-gen-fn package is another utility for checking if a function is a generator function. It is similar to `isGenerator.fn` but is a smaller, more focused package that only provides this single functionality.
is-generator
Check whether a value is a generator or generator function.
Installation
npm install is-generator --save
Usage
var isGenerator = require('is-generator');
var isGeneratorFn = require('is-generator').fn;
isGenerator(null);
isGenerator(function* () {});
isGenerator((function* () {})());
isGeneratorFn(null);
isGeneratorFn(function () {});
isGeneratorFn(function* () {});
License
MIT