What is is-generator-function?
The is-generator-function package is a utility that allows you to check if a given function is a generator function. This can be particularly useful when working with code that dynamically generates functions or when integrating with libraries that may use generator functions for asynchronous control flow.
Check if a function is a generator function
This feature allows you to distinguish between regular JavaScript functions and generator functions. By passing a function to `isGeneratorFunction`, it returns `true` if the function is a generator function and `false` otherwise. This can be useful for dynamic function handling or when working with APIs that may provide generator functions.
const isGeneratorFunction = require('is-generator-function');
function* myGenerator() {}
const regularFunction = function() {};
console.log(isGeneratorFunction(myGenerator)); // true
console.log(isGeneratorFunction(regularFunction)); // false