source: imaps-frontend/node_modules/is-async-function/index.js@ 79a0317

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
RevLine 
[d565449]1'use strict';
2
[79a0317]3var callBound = require('call-bound');
4var safeRegexTest = require('safe-regex-test');
5
6var toStr = callBound('Object.prototype.toString');
7var fnToStr = callBound('Function.prototype.toString');
8var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
9
[d565449]10var hasToStringTag = require('has-tostringtag/shams')();
[79a0317]11var getProto = require('get-proto');
12
[d565449]13var 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]24var AsyncFunction;
25
[79a0317]26/** @type {import('.')} */
[d565449]27module.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.