@arckit/resultset
v1.0.1
Published
Pagination, filtering, and result set utilities with Effect Schema branded types
Downloads
228
Maintainers
Readme
@arckit/resultset
Pagination, filtering, and result set utilities with Effect Schema branded types.
📑 Table of Contents
- 🪧 About
- 📦 Installation
- 🚀 Usage
- 📖 API
- 🤗 Contributing
- 📝 License
Type-safe pagination and filtering utilities using Effect Schema branded types for Page and PageSize. Ensures values are always valid positive integers at the type level.
pnpm add @arckit/resultsetPagination
import { Page, PageSize, paginate } from '@arckit/resultset';
const items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'];
const result = paginate(items, { page: Page(2), pageSize: PageSize(5) });
// { items: ['f', 'g', 'h', 'i', 'j'], totalItems: 11, currentPage: 2, pageSize: 5 }Filtering
import { filtered } from '@arckit/resultset';
const result = filtered(paginatedResult, { search: 'hello' });
// Adds search metadata to the resultPage(value: number) => Page
Branded positive integer. Clamps to 1 minimum, rounds to nearest integer.
PageSize(value: number) => PageSize
Branded positive integer. Clamps to 1 minimum, rounds to nearest integer.
paginate<T>(items: T[], params?) => Paginated<T>
| Parameter | Description |
|-----------|-------------|
| items | The full array to paginate |
| params.page | Page number (default: 1) |
| params.pageSize | Items per page (default: 10) |
filtered<T>(result: T, params?) => Filtered<T>
| Parameter | Description |
|-----------|-------------|
| result | The result object to augment |
| params.search | Optional search string to attach |
See CONTRIBUTING.md for details.
MIT © Marc Gavanier
