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 | var isFnRegex = safeRegexTest(/^\s*(?:function)?\*/);
|
---|
[d565449] | 6 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
[79a0317] | 7 | var getProto = require('get-proto');
|
---|
| 8 |
|
---|
| 9 | var toStr = callBound('Object.prototype.toString');
|
---|
| 10 | var fnToStr = callBound('Function.prototype.toString');
|
---|
| 11 |
|
---|
[d565449] | 12 | var getGeneratorFunc = function () { // eslint-disable-line consistent-return
|
---|
| 13 | if (!hasToStringTag) {
|
---|
| 14 | return false;
|
---|
| 15 | }
|
---|
| 16 | try {
|
---|
| 17 | return Function('return function*() {}')();
|
---|
| 18 | } catch (e) {
|
---|
| 19 | }
|
---|
| 20 | };
|
---|
[79a0317] | 21 | /** @type {undefined | false | null | GeneratorFunctionConstructor} */
|
---|
[d565449] | 22 | var GeneratorFunction;
|
---|
| 23 |
|
---|
[79a0317] | 24 | /** @type {import('.')} */
|
---|
[d565449] | 25 | module.exports = function isGeneratorFunction(fn) {
|
---|
| 26 | if (typeof fn !== 'function') {
|
---|
| 27 | return false;
|
---|
| 28 | }
|
---|
[79a0317] | 29 | if (isFnRegex(fnToStr(fn))) {
|
---|
[d565449] | 30 | return true;
|
---|
| 31 | }
|
---|
| 32 | if (!hasToStringTag) {
|
---|
[79a0317] | 33 | var str = toStr(fn);
|
---|
[d565449] | 34 | return str === '[object GeneratorFunction]';
|
---|
| 35 | }
|
---|
| 36 | if (!getProto) {
|
---|
| 37 | return false;
|
---|
| 38 | }
|
---|
| 39 | if (typeof GeneratorFunction === 'undefined') {
|
---|
| 40 | var generatorFunc = getGeneratorFunc();
|
---|
[79a0317] | 41 | GeneratorFunction = generatorFunc
|
---|
| 42 | // eslint-disable-next-line no-extra-parens
|
---|
| 43 | ? /** @type {GeneratorFunctionConstructor} */ (getProto(generatorFunc))
|
---|
| 44 | : false;
|
---|
[d565449] | 45 | }
|
---|
| 46 | return getProto(fn) === GeneratorFunction;
|
---|
| 47 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.