🔨 changes

This commit is contained in:
Kunall Banerjee 2017-09-26 18:18:28 -04:00
parent bd72dbd1e5
commit 83e48df329
3 changed files with 9 additions and 6 deletions

View file

@ -81,9 +81,9 @@ is.promise = x => {
);
};
is.generator = x => x && typeof x.next === 'function' && typeof x.throw === 'function';
is.generator = x => is.iterable(x) && is.function(x.next) && is.function(x.throw);
is.generatorFunction = x => x.constructor.name === 'GeneratorFunction';
is.generatorFunction = x => getObjectType(x) === 'GeneratorFunction';
is.regExp = x => getObjectType(x) === 'RegExp';
is.date = x => getObjectType(x) === 'Date';

View file

@ -79,6 +79,9 @@ Keep in mind that [functions are objects too](https://developer.mozilla.org/en-U
Returns `true` for any object with a `.then()` and `.catch()` method. Prefer this one over `.nativePromise()` as you usually want to allow userland promise implementations too.
##### .generator(value)
Returns `true` for any object that implements its own `.next()` and `.throw()` methods and has a function definition for `Symbol.iterator`.
##### .generatorFunction(value)
##### .map(value)

View file

@ -54,6 +54,9 @@ const types = new Map([
PromiseSubclassFixture.resolve()
]],
['promise', {then() {}, catch() {}}],
['generator', (function * () {
yield 42;
})()],
['map', new Map()],
['set', new Set()],
['weakMap', new WeakMap()],
@ -167,10 +170,7 @@ if (isNode8orHigher) {
}
test('is.generator', t => {
const genObj = (function * () {
yield 42;
})();
t.true(m.generator(genObj));
testType(t, 'generator', ['function']);
});
test('is.generatorFunction', t => {