es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
26 lines • 878 B
TypeScript
//#region src/predicate/isIterable.d.ts
/**
* Checks if a value is iterable, i.e. it implements the iterable protocol by
* providing a `Symbol.iterator` method.
*
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
* plain objects, `null`, and `undefined` are not.
*
* This function can be used as a TypeScript type predicate to narrow the type of
* `value` to `Iterable<unknown>`.
*
* @param value - The value to check.
* @returns `true` if `value` is iterable, `false` otherwise.
*
* @example
* isIterable([1, 2, 3]); // true
* isIterable('abc'); // true
* isIterable(new Set([1, 2, 3])); // true
* isIterable(new Map()); // true
* isIterable({ a: 1 }); // false
* isIterable(123); // false
* isIterable(null); // false
*/
declare function isIterable(value: unknown): value is Iterable<unknown>;
//#endregion
export { isIterable };