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