UNPKG

nodedb-json

Version:

A lightweight JSON-based database for Node.js with TypeScript support, indexing, and complex query capabilities

28 lines 991 B
export function validatePagination(pagination) { const { page, pageSize } = pagination; if (!Number.isInteger(page) || !Number.isInteger(pageSize) || page < 1 || pageSize < 1) { throw new Error('Pagination page and pageSize must be positive integers'); } } export function applyPagination(data, pagination) { const { page, pageSize } = pagination; validatePagination(pagination); const totalItems = data.length; const totalPages = Math.ceil(totalItems / pageSize); const currentPage = page; const startIndex = (currentPage - 1) * pageSize; const endIndex = startIndex + pageSize; const paginatedData = data.slice(startIndex, endIndex); return { data: paginatedData, pagination: { currentPage, pageSize, totalItems, totalPages, hasPrevious: currentPage > 1, hasNext: currentPage < totalPages } }; } //# sourceMappingURL=paginator.js.map