diondiondion cdc2d91d43 [Glitch] Fix ValidationError when loading many collections at once
Port 2b6b2fcb6ff7f0c066260c0aa3f14f34e4bc3588 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-06-07 14:37:47 +02:00

16 lines
411 B
TypeScript

/**
* Splits a long array so that the resulting nested arrays
* never exceed the `maxLength` provided.
* Useful when dealing with endpoints that accept a limited number
* of parameters
*/
export function batchArray<T>(array: T[], maxLength: number) {
const result: T[][] = [];
for (let i = 0; i < array.length; i += maxLength) {
result.push(array.slice(i, i + maxLength));
}
return result;
}