@monstermann/fn
Version:
A utility library for TypeScript.
35 lines (33 loc) • 703 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/function/isAsyncIterable.ts
/**
* `isAsyncIterable(value)`
*
* Checks if a value is an async iterable by testing for the presence of `Symbol.asyncIterator`.
*
* ```ts
* isAsyncIterable(
* (async function* () {
* yield 1;
* })(),
* ); // true
*
* isAsyncIterable([1, 2, 3]); // false
* ```
*
* ```ts
* pipe(
* (async function* () {
* yield 1;
* })(),
* isAsyncIterable(),
* ); // true
*
* pipe([1, 2, 3], isAsyncIterable()); // false
* ```
*/
const isAsyncIterable = dfdlT((value) => {
return value != null && typeof value[Symbol.asyncIterator] === "function";
}, 1);
//#endregion
export { isAsyncIterable };