@bernierllc/pagination-handler
v0.1.4
Published
Pagination utilities for cursor, offset, and page-based pagination
Readme
@bernierllc/pagination-handler
Pagination utilities for cursor, offset, and page-based pagination strategies.
Overview
This core package provides pure functions for detecting, extracting, and managing pagination state across different pagination strategies commonly used in APIs.
Installation
npm install @bernierllc/pagination-handlerUsage
Detect Pagination Type
import { detectPaginationType } from '@bernierllc/pagination-handler';
const metadata = {
cursor: 'abc123',
nextCursor: 'def456'
};
const type = detectPaginationType(metadata);
// Returns: 'cursor'Extract Pagination State
import { extractPaginationState } from '@bernierllc/pagination-handler';
const metadata = {
offset: 0,
limit: 20,
total: 100
};
const state = extractPaginationState(metadata);
// Returns: { type: 'offset', current: 0, next: 20, pageSize: 20, total: 100 }Calculate Next Page
import { calculateNextPage } from '@bernierllc/pagination-handler';
const state = {
type: 'offset',
current: 0,
next: 20,
pageSize: 20
};
const nextPage = calculateNextPage(state);
// Returns: { type: 'offset', offset: 20, limit: 20 }Check for More Pages
import { hasMorePages } from '@bernierllc/pagination-handler';
const state = {
type: 'cursor',
next: 'def456'
};
const hasMore = hasMorePages(state);
// Returns: trueAPI Reference
Functions
detectPaginationType(metadata: PaginationMetadata): PaginationType | null- Detect pagination type from metadataextractPaginationState(metadata: PaginationMetadata): PaginationState | null- Extract pagination statecalculateNextPage(state: PaginationState, options?): PaginationOptions | null- Calculate next page parameterscalculatePreviousPage(state: PaginationState, options?): PaginationOptions | null- Calculate previous page parametershasMorePages(state: PaginationState): boolean- Check if more pages are availablenormalizePaginationOptions(options?): PaginationOptions- Normalize pagination options
License
Bernier LLC - Limited Use License
