Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-generator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-generator - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

23

is-generator.js

@@ -1,3 +0,22 @@

module.exports = function (f) {
return typeof f === 'function' && f.constructor.name === 'GeneratorFunction';
/**
* Check whether an object is a generator.
*
* @param {Object} obj
* @return {Boolean}
*/
exports = module.exports = function (obj) {
return typeof obj === 'function' &&
typeof obj.next === 'function' &&
typeof obj.throw === 'function';
};
/**
* Check whether a function is generator.
*
* @param {Function} fn
* @return {Boolean}
*/
exports.fn = function (fn) {
return typeof fn === 'function' &&
fn.constructor.name === 'GeneratorFunction';
};

4

package.json
{
"name": "is-generator",
"version": "0.0.1",
"description": "Check whether a function is a generator",
"version": "0.0.2",
"description": "Check whether a value is a generator or generator function",
"main": "is-generator.js",

@@ -6,0 +6,0 @@ "scripts": {

# is-generator
Check whether a given value is a generator function.
Check whether a given value is a generator.

@@ -14,7 +14,12 @@ ## Installation

```javascript
var isGenerator = require('is-generator');
var isGenerator = require('is-generator');
var isGeneratorFn = require('is-generator').fn;
isGenerator(null); //=> false
isGenerator(function () {}); //=> false
isGenerator(function* () {}); //=> true
isGenerator(null); //=> false
isGenerator(function* () {}); //=> false
isGenerator((function* () {})()); //=> true
isGeneratorFn(null); //=> false
isGeneratorFn(function () {}); //=> false
isGeneratorFn(function* () {}); //=> true
```

@@ -21,0 +26,0 @@

@@ -7,12 +7,28 @@ /* global describe, it */

describe('is-generator', function () {
it('should return false with non-generators', function () {
assert(!isGenerator(null));
assert(!isGenerator(25));
assert(!isGenerator('test'));
assert(!isGenerator(function () {}));
describe('generators', function () {
it('should return false with non-generators', function () {
assert(!isGenerator(null));
assert(!isGenerator(25));
assert(!isGenerator('test'));
assert(!isGenerator(function () {}));
assert(!isGenerator(function* () {}));
});
it('should return true with a generator', function () {
assert(!isGenerator((function* () {})()));
});
});
it('should return true with a generator', function () {
assert(isGenerator(function* () { yield 'something'; }));
describe('generator functions', function () {
it('should return false with non-generator function', function () {
assert(!isGenerator.fn(null));
assert(!isGenerator.fn(25));
assert(!isGenerator.fn('test'));
assert(!isGenerator.fn(function () {}));
});
it('should return true with a generator function', function () {
assert(isGenerator.fn(function* () { yield 'something'; }));
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc