Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
is-generator-fn
Advanced tools
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.
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
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.
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.
Check if something is a generator function
$ npm install is-generator-fn
const isGeneratorFn = require('is-generator-fn');
isGeneratorFn(function * () {});
//=> true
isGeneratorFn(function () {});
//=> false
MIT © Sindre Sorhus
FAQs
Check if something is a generator function
The npm package is-generator-fn receives a total of 12,099,401 weekly downloads. As such, is-generator-fn popularity was classified as popular.
We found that is-generator-fn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.