main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bound');
|
---|
4 | var safeRegexTest = require('safe-regex-test');
|
---|
5 |
|
---|
6 | var toStr = callBound('Object.prototype.toString');
|
---|
7 | var fnToStr = callBound('Function.prototype.toString');
|
---|
8 | var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
|
---|
9 |
|
---|
10 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
11 | var getProto = require('get-proto');
|
---|
12 |
|
---|
13 | var getAsyncFunc = function () { // eslint-disable-line consistent-return
|
---|
14 | if (!hasToStringTag) {
|
---|
15 | return false;
|
---|
16 | }
|
---|
17 | try {
|
---|
18 | return Function('return async function () {}')();
|
---|
19 | } catch (e) {
|
---|
20 | }
|
---|
21 | };
|
---|
22 |
|
---|
23 | /** @type {import('.').AsyncFunction | false} */
|
---|
24 | var AsyncFunction;
|
---|
25 |
|
---|
26 | /** @type {import('.')} */
|
---|
27 | module.exports = function isAsyncFunction(fn) {
|
---|
28 | if (typeof fn !== 'function') {
|
---|
29 | return false;
|
---|
30 | }
|
---|
31 | if (isFnRegex(fnToStr(fn))) {
|
---|
32 | return true;
|
---|
33 | }
|
---|
34 | if (!hasToStringTag) {
|
---|
35 | var str = toStr(fn);
|
---|
36 | return str === '[object AsyncFunction]';
|
---|
37 | }
|
---|
38 | if (!getProto) {
|
---|
39 | return false;
|
---|
40 | }
|
---|
41 | if (typeof AsyncFunction === 'undefined') {
|
---|
42 | var asyncFunc = getAsyncFunc();
|
---|
43 | // eslint-disable-next-line no-extra-parens
|
---|
44 | AsyncFunction = asyncFunc ? /** @type {import('.').AsyncFunction} */ (getProto(asyncFunc)) : false;
|
---|
45 | }
|
---|
46 | return getProto(fn) === AsyncFunction;
|
---|
47 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.