UNPKG

ts-utls

Version:

Utilities for TypeScript library

35 lines 1.39 kB
/** * Split an array into chunks of the passed size * * @param {T[]} arr - The array to split * @param {number} chunkSize - The maximum size of chunks * @returns the chunked array of arrays */ export declare const chunk: <T>(arr: ReadonlyArray<T>, chunkSize: number) => Array<Array<T>>; /** * Flatten an array of arrays of items into an array of items * * @param {T[][]} arrs - The array of arrays to flatten * @returns the flattened array of items */ export declare const flatten: <T>(arrs: Array<Array<T>>) => Array<T>; /** * Group an array of objects by some field acting as key * * @param {T[]} arr - The array of objects * @param {K} key - The key to use * @returns the map array grouped by key */ export declare const groupBy: <T extends Record<string | number | symbol, any>, K extends keyof T>(arr: Array<T>, key: K) => Record<T[K], Array<T>>; /** * Returns a range of integers * * It is the equivalent of a for-loop with `i = start` and `i < start + size` with `i = i + step` at the end of each round * * @param {number} start - The starting point * @param {number} end - The number of items to return (not included) * @param {number} step - The (optional) step size between numbers (Default: 1) * @returns the array of integers */ export declare const range: (start: number, end: number, step?: number) => Array<number>; //# sourceMappingURL=array.d.ts.map