@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
29 lines (28 loc) • 897 B
JavaScript
// type PaginationResult<T = IEntity> = { docs: T[] } & IPagination;
// type PaginationResult<T = IEntity> = PaginatedDocs<T>;
export async function getPagination(items, page = 1, limit = 10) {
const totalDocs = items.length;
const totalPages = Math.ceil(items.length / limit);
const hasNextPage = page < totalPages;
const hasPrevPage = page > 1;
const index = page - 1;
const from = index * limit;
const to = Math.min((index + 1) * limit, totalDocs);
const docs = items.slice(from, to);
const pagination = {
totalDocs,
totalPages,
page,
limit,
hasNextPage,
hasPrevPage,
nextPage: hasNextPage ? page + 1 : null,
prevPage: hasPrevPage ? page - 1 : null,
pagingCounter: from + 1
};
return {
docs,
...pagination
};
}
//# sourceMappingURL=pagination.service.js.map