@wordpress/redux-routine
Version:
Redux middleware for generator coroutines.
19 lines (18 loc) • 633 B
text/typescript
/**
* Returns true if the given object is a generator, or false otherwise.
*
* @see https://www.ecma-international.org/ecma-262/6.0/#sec-generator-objects
*
* @param object Object to test.
*
* @return Whether object is a generator.
*/
export default function isGenerator( object: any ): object is Generator {
// Check that iterator (next) and iterable (Symbol.iterator) interfaces are satisfied.
// These checks seem to be compatible with several generator helpers as well as the native implementation.
return (
!! object &&
typeof object[ Symbol.iterator ] === 'function' &&
typeof object.next === 'function'
);
}