Skip to content

Commit

Permalink
[Refactor] use async-function for the eval parts
Browse files Browse the repository at this point in the history
Hopefully fixes #31.
  • Loading branch information
ljharb committed Jan 23, 2025
1 parent db36da5 commit 09fd6c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 27 deletions.
5 changes: 0 additions & 5 deletions getAsyncFunc.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions getAsyncFunc.js

This file was deleted.

6 changes: 4 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { AsyncFunction } from 'async-function';

declare namespace isAsyncFunction {
type AsyncFunction = (...args: any[]) => Promise<any>
export type { AsyncFunction };
}

declare function isAsyncFunction(fn: unknown): fn is isAsyncFunction.AsyncFunction;
declare function isAsyncFunction(fn: unknown): fn is AsyncFunction;

export = isAsyncFunction;
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
var hasToStringTag = require('has-tostringtag/shams')();
var getProto = require('get-proto');

var getAsyncFunc = require('./getAsyncFunc');

/** @type {import('.').AsyncFunction | false} */
var AsyncFunction;
var getAsyncFunc = require('async-function');

/** @type {import('.')} */
module.exports = function isAsyncFunction(fn) {
Expand All @@ -30,10 +27,6 @@ module.exports = function isAsyncFunction(fn) {
if (!getProto) {
return false;
}
if (typeof AsyncFunction === 'undefined') {
var asyncFunc = getAsyncFunc();
// eslint-disable-next-line no-extra-parens
AsyncFunction = asyncFunc ? /** @type {import('.').AsyncFunction} */ (getProto(asyncFunc)) : false;
}
return AsyncFunction && getProto(fn) === AsyncFunction;
var asyncFunc = getAsyncFunc();
return asyncFunc && asyncFunc.prototype === getProto(fn);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"url": "https://github.com/inspect-js/is-async-function/issues"
},
"dependencies": {
"async-function": "^1.0.0",
"call-bound": "^1.0.3",
"get-proto": "^1.0.1",
"has-tostringtag": "^1.0.2",
Expand Down

0 comments on commit 09fd6c3

Please sign in to comment.