@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
14 lines (13 loc) • 486 B
JavaScript
function resolvePagination(input, defaultLimit) {
const limit = input.limit ?? defaultLimit;
const offset = input.offset ?? (null != input.page ? (input.page - 1) * limit : 0);
let page = input.page ?? 1;
if (null != input.offset) page = limit > 0 ? Math.floor(offset / limit) + 1 : 1;
else if (null == input.page) page = limit > 0 ? Math.floor(offset / limit) + 1 : 1;
return {
page,
limit,
offset
};
}
export { resolvePagination };