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:
964 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var toStr = Object.prototype.toString;
|
---|
| 4 | var fnToStr = Function.prototype.toString;
|
---|
| 5 | var isFnRegex = /^\s*(?:function)?\*/;
|
---|
| 6 | var hasToStringTag = require('has-tostringtag/shams')();
|
---|
| 7 | var getProto = Object.getPrototypeOf;
|
---|
| 8 | var getGeneratorFunc = function () { // eslint-disable-line consistent-return
|
---|
| 9 | if (!hasToStringTag) {
|
---|
| 10 | return false;
|
---|
| 11 | }
|
---|
| 12 | try {
|
---|
| 13 | return Function('return function*() {}')();
|
---|
| 14 | } catch (e) {
|
---|
| 15 | }
|
---|
| 16 | };
|
---|
| 17 | var GeneratorFunction;
|
---|
| 18 |
|
---|
| 19 | module.exports = function isGeneratorFunction(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 GeneratorFunction]';
|
---|
| 29 | }
|
---|
| 30 | if (!getProto) {
|
---|
| 31 | return false;
|
---|
| 32 | }
|
---|
| 33 | if (typeof GeneratorFunction === 'undefined') {
|
---|
| 34 | var generatorFunc = getGeneratorFunc();
|
---|
| 35 | GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false;
|
---|
| 36 | }
|
---|
| 37 | return getProto(fn) === GeneratorFunction;
|
---|
| 38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.