export function chunk(array, size) {
    if (size <= 0 || !Number.isInteger(size)) {
        throw new Error(`Expected size to be an integer greater than 0 but found ${size}`);
    }
    if (array.length === 0) {
        return [];
    }
    const ret = Array.from({ length: Math.ceil(array.length / size) });
    let readIndex = 0;
    let writeIndex = 0;
    while (readIndex < array.length) {
        ret[writeIndex] = array.slice(readIndex, readIndex + size);
        writeIndex += 1;
        readIndex += size;
    }
    return ret;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2h1bmsuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaHVuay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFzQkEsTUFBTSxVQUFVLEtBQUssQ0FBSSxLQUFtQixFQUFFLElBQVk7SUFDeEQsSUFBSSxJQUFJLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsRUFBRTtRQUN4QyxNQUFNLElBQUksS0FBSyxDQUNiLDJEQUEyRCxJQUFJLEVBQUUsQ0FDbEUsQ0FBQztLQUNIO0lBRUQsSUFBSSxLQUFLLENBQUMsTUFBTSxLQUFLLENBQUMsRUFBRTtRQUN0QixPQUFPLEVBQUUsQ0FBQztLQUNYO0lBRUQsTUFBTSxHQUFHLEdBQUcsS0FBSyxDQUFDLElBQUksQ0FBTSxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLEdBQUcsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQ3hFLElBQUksU0FBUyxHQUFHLENBQUMsQ0FBQztJQUNsQixJQUFJLFVBQVUsR0FBRyxDQUFDLENBQUM7SUFFbkIsT0FBTyxTQUFTLEdBQUcsS0FBSyxDQUFDLE1BQU0sRUFBRTtRQUMvQixHQUFHLENBQUMsVUFBVSxDQUFDLEdBQUcsS0FBSyxDQUFDLEtBQUssQ0FBQyxTQUF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