shelving
Version:
Toolkit for using data in JavaScript.
37 lines (36 loc) • 2.28 kB
TypeScript
/** Is an unknown value an iterable? */
export declare const isIterable: (value: unknown) => value is Iterable<unknown>;
/** An iterable containing items or nested iterables of items. */
export type DeepIterable<T> = T | Iterable<DeepIterable<T>>;
/** Flatten one or more iterables. */
export declare function flattenItems<T>(items: DeepIterable<T>): Iterable<T>;
/**
* Does an iterable have one or more items.
* - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
*/
export declare function hasItems(items: Iterable<unknown>): boolean;
/** Count the number of items in an iterable. */
export declare function countItems(items: Iterable<unknown>): number;
/**
* Yield a range of numbers from `start` to `end`
* - Yields in descending order if `end` is lower than `start`
*/
export declare function getRange(start: number, end: number): Iterable<number>;
/**
* Apply a limit to an iterable set of items.
* - Checks `items.size` or `items.length` first to see if the limit is necessary.
*/
export declare function limitItems<T>(items: Iterable<T>, limit: number): Iterable<T>;
/** Pick items from an iterable set of items. */
export declare function pickItems<T>(items: Iterable<T>, ...pick: T[]): Iterable<T>;
/** Omit items from an iterable set of items. */
export declare function omitItems<T>(items: Iterable<T>, ...omit: T[]): Iterable<T>;
/** Reduce an iterable set of items using a reducer function. */
export declare function reduceItems<T>(items: Iterable<T>, reducer: (previous: T, item: T) => T, initial: T): T;
export declare function reduceItems<T>(items: Iterable<T>, reducer: (previous: T | undefined, item: T) => T, initial?: T): T | undefined;
export declare function reduceItems<I, O>(items: Iterable<I>, reducer: (previous: O, item: I) => O, initial: O): O;
export declare function reduceItems<I, O>(items: Iterable<I>, reducer: (previous: O | undefined, item: I) => O, initial?: O): O | undefined;
/** Yield chunks of a given size. */
export declare function getChunks<T>(items: Iterable<T>, size: number): Iterable<readonly T[]>;
/** Merge two or more iterables into a single iterable set. */
export declare function mergeItems<T>(...inputs: [Iterable<T>, Iterable<T>, ...Iterable<T>[]]): Iterable<T>;