[Data] Add Pure Array Chunker & Batch Paginator in src/lib/data/array-chunk.ts
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
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
🎯 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
- Module Implementation: Create
src/lib/data/array-chunk.ts - Unit Test Suite: Create
tests/array-chunk.test.tsusing nativenode:testandnode:assert/strict.
📐 Specification & Interface Contracts
export function chunkArray<T>(
items: readonly T[],
chunkSize: number
): T[][];
Invariants & Behavior:
- Immutability: Does not mutate the source array.
- Even Sizing: Every sub-array except possibly the last has
length === chunkSize. - Remainder: The last sub-array contains any remaining elements (
length <= chunkSize). - Empty Handling: If
items.length === 0, returns an empty array[]. - Oversized Chunk: If
chunkSize >= items.length, returns[items.slice()]. - Validation:
- Throws
TypeErrorifitemsis not an array, orchunkSizeis not a number or isNaN. - Throws
RangeErrorifchunkSizeis not a positive integer (must be integer $\ge 1$).
- Throws
🧪 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TheVicky1/Pact_OS
-
area:finance difficulty:easy enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Text] Add Word-Boundary Preserving Smart Text Truncator in src/lib/text/smart-truncate.tsPossibly taken @rudraparmar76 claimed this today. Openarea:data difficulty:easy enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
TheVicky1/Pact_OS#760 · 1 comment ·
Maintainers usually reply within 1 day
-
area:habits difficulty:easy enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
area:analytics difficulty:easy enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
beginner-friendly difficulty:easy enhancement gamification good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
All issues in TheVicky1/Pact_OS
Similar issues
-
Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-javascript#26203 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bytedance/flowgram.ai#1235 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
devswha/herdr-web-ui#3325 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100