UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

19 lines 1.3 kB
import ObjectIterator from './internal/ObjectIterator'; import type { IteratorOrIterable } from './types'; import FunctionIterator from './internal/FunctionIterator'; /** * Converts most objects that can be an `Iterator` into one. The supported inputs are: * - An `Iterator`, will return the input as is/unchanged. * - An `Iterable`, will return the input with it's `Symbol.iterator` property called. So this includes any object that * has a `Symbol.iterator` property. Like Arrays, Strings, Maps, Sets, etc. * - Any `function` with an optional `sentinel` argument, will return a `FunctionIterator`. This iterator will call the * input `func` once per `next()` call and will stop once the value of `sentinel` (default: undefined) is returned from * `func`. * - Any other non-nullable object, will return an ObjectIterator that iterates over the input object's own properties * deeply. */ export declare function toIterator<T>(it: IteratorOrIterable<T>): Iterator<T>; export declare function toIterator<TFunc extends (...args: any[]) => any, TSentinel = undefined>(func: TFunc, sentinel?: TSentinel): FunctionIterator<TFunc, TSentinel>; export declare function toIterator(object: Record<PropertyKey, any>): ObjectIterator<any>; export default toIterator; //# sourceMappingURL=toIterator.d.ts.map