🔨 changes
This commit is contained in:
parent
bd72dbd1e5
commit
83e48df329
3 changed files with 9 additions and 6 deletions
4
index.js
4
index.js
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
8
test.js
8
test.js
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue