UNPKG

pagination-front-end

Version:

pagination-front-end é uma biblioteca voltada para realização de paginação no front end( pagination-front-end is a front-end paging library)

22 lines (17 loc) 546 B
import { FilterPaginationResult } from '../types' import { normalizePageSize } from './normalize' const filterPagination = <T>( items: T[] | null | undefined, pageSize: number, currentPage: number ): FilterPaginationResult<T> => { if (!items?.length) { return { contentItems: [] } } const safePageSize = normalizePageSize(pageSize) const startIndex = (currentPage - 1) * safePageSize return { contentItems: items.slice(startIndex, startIndex + safePageSize), } } export default filterPagination