Add is.generator() and is.generatorFunction() (#4)

This commit is contained in:
Kunall Banerjee 2017-09-28 23:01:48 -04:00 committed by Sindre Sorhus
parent 000f66bbdc
commit dbe5cc8d82
3 changed files with 26 additions and 1 deletions

View file

@ -82,6 +82,11 @@ const hasPromiseAPI = x =>
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';
is.regExp = isObjectOfType('RegExp');
is.date = isObjectOfType('Date');
is.error = isObjectOfType('Error');