What is is-generator-fn?
The is-generator-fn package is a simple utility that allows you to check if a given function is a generator function. This can be particularly useful when working with or developing libraries that need to handle generator functions differently from regular functions, or when you want to enforce that a certain function passed to your code is a generator function for execution purposes.
What are is-generator-fn's main functionalities?
Check if a function is a generator function
This feature allows you to distinguish between generator functions and regular functions. By passing a function to `isGeneratorFn`, it returns `true` if the function is a generator function and `false` otherwise. This can be useful in scenarios where specific handling or behavior is required for generator functions.
const isGeneratorFn = require('is-generator-fn');
function* generatorFunction() {}
const regularFunction = function() {};
console.log(isGeneratorFn(generatorFunction)); // true
console.log(isGeneratorFn(regularFunction)); // false
Other packages similar to is-generator-fn
is-generator
Similar to is-generator-fn, is-generator checks if a given value is a generator object, which is different from checking if a function is a generator function. While is-generator-fn checks the function definition, is-generator checks the runtime object produced by calling a generator function.
is-generator-function
This package offers functionality similar to is-generator-fn by providing a way to determine if a function is a generator function. The main difference might be in implementation details or updates, but both packages serve the same purpose of identifying generator functions.
is-generator-fn
Check if something is a generator function
Install
$ npm install is-generator-fn
Usage
import isGeneratorFunction from 'is-generator-fn';
isGeneratorFunction(function * () {});
isGeneratorFunction(function () {});
Related