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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 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 |
|
---|
[d565449] | 10 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
[79a0317] | 11 | var getProto = require('get-proto');
|
---|
| 12 |
|
---|
[d565449] | 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 | };
|
---|
[79a0317] | 22 |
|
---|
| 23 | /** @type {import('.').AsyncFunction | false} */
|
---|
[d565449] | 24 | var AsyncFunction;
|
---|
| 25 |
|
---|
[79a0317] | 26 | /** @type {import('.')} */
|
---|
[d565449] | 27 | module.exports = function isAsyncFunction(fn) {
|
---|
| 28 | if (typeof fn !== 'function') {
|
---|
| 29 | return false;
|
---|
| 30 | }
|
---|
[79a0317] | 31 | if (isFnRegex(fnToStr(fn))) {
|
---|
[d565449] | 32 | return true;
|
---|
| 33 | }
|
---|
| 34 | if (!hasToStringTag) {
|
---|
[79a0317] | 35 | var str = toStr(fn);
|
---|
[d565449] | 36 | return str === '[object AsyncFunction]';
|
---|
| 37 | }
|
---|
| 38 | if (!getProto) {
|
---|
| 39 | return false;
|
---|
| 40 | }
|
---|
| 41 | if (typeof AsyncFunction === 'undefined') {
|
---|
| 42 | var asyncFunc = getAsyncFunc();
|
---|
[79a0317] | 43 | // eslint-disable-next-line no-extra-parens
|
---|
| 44 | AsyncFunction = asyncFunc ? /** @type {import('.').AsyncFunction} */ (getProto(asyncFunc)) : false;
|
---|
[d565449] | 45 | }
|
---|
| 46 | return getProto(fn) === AsyncFunction;
|
---|
| 47 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.