UNPKG

@mcabreradev/filter

Version:

A powerful, SQL-like array filtering library for TypeScript and JavaScript with advanced pattern matching, MongoDB-style operators, deep object comparison, and zero dependencies

27 lines (26 loc) 903 B
export function calculateTotalPages(totalItems, pageSize) { return Math.ceil(totalItems / pageSize); } export function getPageData(data, currentPage, pageSize) { const startIndex = (currentPage - 1) * pageSize; const endIndex = startIndex + pageSize; return data.slice(startIndex, endIndex); } export function createPaginationResult(data, _allData, state) { const totalPages = calculateTotalPages(state.totalItems, state.pageSize); return { data, currentPage: state.currentPage, pageSize: state.pageSize, totalItems: state.totalItems, totalPages, hasNextPage: state.currentPage < totalPages, hasPreviousPage: state.currentPage > 1, }; } export function validatePageNumber(page, totalPages) { return Math.max(1, Math.min(page, totalPages)); } export function validatePageSize(size) { return Math.max(1, size); }