From 226e4d90dacdac0019866f805cf93179cb00d2f9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 29 Sep 2017 10:10:29 +0700 Subject: [PATCH] Clean up #4 --- index.js | 4 ++-- test.js | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 02036be..045577f 100644 --- a/index.js +++ b/index.js @@ -84,8 +84,8 @@ is.promise = x => is.nativePromise(x) || hasPromiseAPI(x); is.generator = x => is.iterable(x) && is.function(x.next) && is.function(x.throw); -// Change to use `isObjectOfType` once Node 4.x.x LTS is dropped -is.generatorFunction = x => x.constructor.name === 'GeneratorFunction'; +// TODO: Change to use `isObjectOfType` once Node.js 6 or higher is targeted +is.generatorFunction = x => is.function(x) && is.function(x.constructor) && x.constructor.name === 'GeneratorFunction'; is.regExp = isObjectOfType('RegExp'); is.date = isObjectOfType('Date'); diff --git a/test.js b/test.js index 89b4a41..b4b50e6 100644 --- a/test.js +++ b/test.js @@ -59,8 +59,11 @@ const types = new Map([ ]], ['promise', {then() {}, catch() {}}], ['generator', (function * () { - yield 42; + yield 4; })()], + ['generatorFunction', function * () { + yield 4; + }], ['map', new Map()], ['set', new Set()], ['weakMap', new WeakMap()], @@ -138,7 +141,7 @@ test('is.array', t => { }); test('is.function', t => { - testType(t, 'function'); + testType(t, 'function', ['generatorFunction']); }); test('is.buffer', t => { @@ -174,14 +177,11 @@ if (isNode8orHigher) { } test('is.generator', t => { - testType(t, 'generator', ['function']); + testType(t, 'generator'); }); test('is.generatorFunction', t => { - const gen = function * () { - yield 42; - }; - t.true(m.generatorFunction(gen)); + testType(t, 'generatorFunction', ['function']); }); test('is.map', t => {