source: imaps-frontend/node_modules/is-generator-function/index.js@ d565449

main
Last change on this file since d565449 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
Line 
1'use strict';
2
3var toStr = Object.prototype.toString;
4var fnToStr = Function.prototype.toString;
5var isFnRegex = /^\s*(?:function)?\*/;
6var hasToStringTag = require('has-tostringtag/shams')();
7var getProto = Object.getPrototypeOf;
8var 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};
17var GeneratorFunction;
18
19module.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.