main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
947 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var toStr = Object.prototype.toString;
|
---|
| 4 | var fnToStr = Function.prototype.toString;
|
---|
| 5 | var isFnRegex = /^\s*async(?:\s+function(?:\s+|\()|\s*\()/;
|
---|
| 6 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
| 7 | var getProto = Object.getPrototypeOf;
|
---|
| 8 | var getAsyncFunc = function () { // eslint-disable-line consistent-return
|
---|
| 9 | if (!hasToStringTag) {
|
---|
| 10 | return false;
|
---|
| 11 | }
|
---|
| 12 | try {
|
---|
| 13 | return Function('return async function () {}')();
|
---|
| 14 | } catch (e) {
|
---|
| 15 | }
|
---|
| 16 | };
|
---|
| 17 | var AsyncFunction;
|
---|
| 18 |
|
---|
| 19 | module.exports = function isAsyncFunction(fn) {
|
---|
| 20 | if (typeof fn !== 'function') {
|
---|
| 21 | return false;
|
---|
| 22 | }
|
---|
| 23 | if (isFnRegex.test(fnToStr.call(fn))) {
|
---|
| 24 | return true;
|
---|
| 25 | }
|
---|
| 26 | if (!hasToStringTag) {
|
---|
| 27 | var str = toStr.call(fn);
|
---|
| 28 | return str === '[object AsyncFunction]';
|
---|
| 29 | }
|
---|
| 30 | if (!getProto) {
|
---|
| 31 | return false;
|
---|
| 32 | }
|
---|
| 33 | if (typeof AsyncFunction === 'undefined') {
|
---|
| 34 | var asyncFunc = getAsyncFunc();
|
---|
| 35 | AsyncFunction = asyncFunc ? getProto(asyncFunc) : false;
|
---|
| 36 | }
|
---|
| 37 | return getProto(fn) === AsyncFunction;
|
---|
| 38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.