mesh-fetcher
Version:
A Node.js package for fetching data from multiple APIs with enhanced features.
30 lines (29 loc) • 861 B
TypeScript
import { ChunkArrayOptions } from '../types';
/**
* Splits an array into smaller arrays of specified size.
*
* @template T - The type of elements in the array
* @param {Array<T>} array - The array to split into chunks
* @param {number} size - The size of each chunk
* @param {ChunkArrayOptions} [options] - Options for chunking behavior
* @returns {Array<T[]>} An array of chunks
*
* @example
* ```typescript
* const arr = [1, 2, 3, 4, 5];
*
* // Basic chunking
* const chunks = chunkArray(arr, 2);
* // [[1, 2], [3, 4], [5]]
*
* // With padding
* const padded = chunkArray(arr, 2, {
* padLastChunk: true,
* padValue: 0
* });
* // [[1, 2], [3, 4], [5, 0]]
* ```
*
* @throws {Error} If size is less than or equal to 0
*/
export declare function chunkArray<T>(array: Array<T>, size: number, options?: ChunkArrayOptions): Array<T[]>;