Skip to main content

Batch - API

A primitive to represent a batch of items.

Installation

npm is the default package manager for Node.js, and to where tscommon is published.
Your project is using npm if it has a package-lock.json file in its root folder.

Run the following command in your terminal:

terminal
npm install @tscommon/batch

Usage

main.ts
import { Batch } from '@tscommon/batch';

const items = [1, 2, 3, 4, 5];

for (const batch of Batch.from(items, 3)) {
console.log(batch);
}

// Output:
// Batch { index: 0, items: [ 1, 2, 3 ] }
// Batch { index: 1, items: [ 4, 5 ] }