Skip to content

Laravel Collectionfor TypeScript

Always in sync with Laravel. TypeScript-first. Modern.

Alpha Release

This package is in alpha and under active development. APIs may change before the 1.0.0 stable release. Not recommended for production use yet.

Why collect-ts? ​

A living synchronization with Laravel Collections.

  • πŸ”„ Version tracked β€” laravelCollectionVersion: 12.43 in package.json
  • πŸ”§ Sync infrastructure β€” Scripts to pull updates from Laravel's repository
  • βœ… Test parity β€” Tests ported from Laravel's own test suite

When Laravel adds new methods, we add them. When bugs are fixed upstream, we fix them.

Installation ​

bash
npm install collect-ts
bash
pnpm add collect-ts
bash
yarn add collect-ts
bash
npx jsr add @ovdlinden/collect-ts

Quick Start ​

typescript
import { collect } from 'collect-ts'

const result = collect([1, 2, 3, 4, 5])
  .filter(n => n > 2)
  .map(n => n * 2)
  .sum()
// => 24

LazyCollection for Large Datasets ​

Process millions of items without loading everything into memory:

typescript
import { lazy } from 'collect-ts'

const result = lazy(hugeDataset)
  .filter(item => item.active)
  .map(item => item.id)
  .take(100)
  .all()
// Only processes what's needed

TypeScript-First ​

Not JavaScript with types bolted on. Real TypeScript with advanced patterns:

typescript
// Type-safe property extraction
const names = collect(users).pluck('name') // Collection<string>

// Higher-order messaging with full typing
const emails = collect(users).map.email // Collection<string>

// Conditional types that infer correctly
const flat = collect([[1, 2], [3, 4]]).collapse() // Collection<number>

Next Steps ​

Choose your path:

Released under the MIT License.