Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is-generator-function native replacement #122

Open
justinfagnani opened this issue Jul 27, 2024 · 1 comment
Open

is-generator-function native replacement #122

justinfagnani opened this issue Jul 27, 2024 · 1 comment

Comments

@justinfagnani
Copy link
Contributor

https://github.com/inspect-js/is-generator-function

There is a one-liner replacement:

const isGenerator = typeof fn === 'function' && Object.getPrototypeof(fn) === (function* () {}.constructor);

Though you probably want to cache the generator prototype (JS should make it a global, IMO).

is-generator-function depends on has-tostringtag (which depends on a third) so replacing this could eliminate up to three dependencies.

@Namchee
Copy link
Contributor

Namchee commented Aug 20, 2024

In Node context, we can also use util.types.isGeneratorFunction from v10 Node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants