[Data] Add Pure Array Chunker & Batch Paginator in src/lib/data/array-chunk.ts

Open Beginner friendly
#752 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, testing

Research direction

Create src/lib/data/array-chunk.ts and tests/array-chunk.test.ts; start by checking the project's TypeScript configuration and nearby utility tests. Implement the specified generic chunking behavior and input validation, then cover the listed cases with node:test and node:assert/strict. Done means the tests pass and npx tsc --noEmit reports no errors.

Written by the indexing model from the issue text.

Description

area:data beginner-friendly difficulty:easy enhancement good first issue
🎯 Feature Overview & Context

In PACT OS, local-first synchronization and batch Supabase mutation queues require splitting large entity arrays into fixed-size batches (e.g. processing 25 habit logs per payload). This utility provides a pure, immutable array chunker function.


🧩 Scope & Deliverables
  1. Module Implementation: Create src/lib/data/array-chunk.ts
  2. Unit Test Suite: Create tests/array-chunk.test.ts using native node:test and node:assert/strict.

📐 Specification & Interface Contracts
export function chunkArray<T>(
  items: readonly T[],
  chunkSize: number
): T[][];
Invariants & Behavior:
  1. Immutability: Does not mutate the source array.
  2. Even Sizing: Every sub-array except possibly the last has length === chunkSize.
  3. Remainder: The last sub-array contains any remaining elements (length <= chunkSize).
  4. Empty Handling: If items.length === 0, returns an empty array [].
  5. Oversized Chunk: If chunkSize >= items.length, returns [items.slice()].
  6. Validation:
    • Throws TypeError if items is not an array, or chunkSize is not a number or is NaN.
    • Throws RangeError if chunkSize is not a positive integer (must be integer $\ge 1$).

🧪 Acceptance Criteria
  • TypeScript strict mode passes with 0 errors (npx tsc --noEmit).
  • Uses extensionless import in test file (import { chunkArray } from '../src/lib/data/array-chunk').
  • Unit tests cover arrays smaller than chunk size, exact multiples, non-multiples with remainder, empty arrays, and error throwing.
  • Zero external dependencies added.
Dominant language
TypeScript
Stars
5
Forks
7
Avg merge
1d 16h
Merged PRs (30d)
79

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TheVicky1/Pact_OS

All issues in TheVicky1/Pact_OS

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.