jonschlinkert / kind-of

Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
https://github.com/jonschlnkert
MIT License
347 stars 38 forks source link

Add async function support #24

Closed moeen closed 5 years ago

moeen commented 6 years ago

Add async function detection. #22

tunnckoCore commented 6 years ago

also, we were thinking about exposing options object as second argument, or something like that, because it's edge case and most may want to know is it genfn or normal (no matter async or not)

right, @jonschlinkert?

jonschlinkert commented 6 years ago

also, we were thinking about exposing options object as second argument,

I haven't decided on the best way to handle this. We can't merge this PR though, as it would break a lot of code. I'm leaning towards exposing another method for this.

ghost commented 5 years ago

Maybe you could add "hooks" support? That would not break existing code and would work great. Think about this:

kindOf(2);
kindOf.register(function a(b) { if(isAsyncFunction(b)) return `AsyncFunction`; return false; });

Sort of thing, if a hook returns false, the check does not stop.

ghost commented 5 years ago

I'll submit a PR with the hooks support.

ghost commented 5 years ago

Boom. See what you think!

jonschlinkert commented 5 years ago

Just because we can, doesn't mean we should -- Ian Malcolm, Jurassic Park

Honestly, after thinking about this more I really don't think this is a good idea. Offhand, I can think of code that would break if we implement this. Everyone would need to start adding multiple conditions to their code.

Instead, I suggest we expose a method, like isAsync or something, so that we can achieve the same end result without changing current behavior.

tunnckoCore commented 5 years ago

Agree.