co
co copied to clipboard
Is there a way to check one variable is a thunk ?
FYI
nope.
Well, if you know that foo is a function, and in the source code (foo.toString()) you see that it accepts only a cb (or callback, etc) argument, then you can assume that foo is a thunk. But don't do that.
I think you have an XY Problem, so what is your problem that you want to solve with this?
that may help you tunnckoCore/is-async-function, it's not for thunks but for async functions at all. See the examples on readme, see the tests.
I'm open to add more possible variants than cb and callback, but it seems it works for fs and commonly used libs that are async.
Also look
make-callback make synchronous function to have callback api
always-callback - create async function from sync or remains async if async function is given
always-promise - create promise from async or sync function
^ both work for fs, JSON.parse/stringify and etc.
@tunnckoCore Good job
@Pana I dont know, it's pseudo, but works. Tried to not use regexp, for that slice just 150 chars then indexOf. Using regexp was 2x slower.
But yea, thanks! : )