1.1.0 • Published 5 months ago

@marianmeres/paging-store v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@marianmeres/paging-store

Simple utility for calculating paging data.

Install

$ npm i @marianmeres/paging-store

Example

const paging = calculatePaging({ total: 25, limit: 10, offset: 11 });

// paging is now:
{
    total: 25,
    limit: 10,
    offset: 11,
    isLast: false,
    isFirst: false,
    nextPage: 3,
    previousPage: 1,
    hasNext: true,
    hasPrevious: true,
    nextOffset: 20,
    previosOffset: 0,
    currentPage: 2,
    pageCount: 3,
    firstOffset: 0,
    lastOffset: 20,
}

// store api
const store = createPagingStore({ total: 25, limit: 10, offset: 0 });
store.subscribe((paging) => {/* see shape above */});
store.update(/*any/all of { total: ..., limit: ..., offset: ... }*/);
store.reset(limit?);
1.1.0

5 months ago

1.0.1

1 year ago