pagination-ts

0.1.0 • Public • Published

pagination-ts

Example

make start-example

Usage

fetcher type

fetcher typeを作成する必要があります

type order = {
  direction: string;
  columnName: string;
};

type fetcher<T, U> = {
  count(cond: T): number;
  fetchPage(
    cond: T,
    limit: number,
    offset: number,
    orders: order[],
  ): Array<U>;
};

Example

function parseFruitCondition(query) {
  // 
}

const pagination = new Pagination();
const p = pagintion.parseQuery(req.query);
const cond = parseFruitCondition(req.query)

const {totalCount, totalPages, pages} = pagination.fetch(fetcher, {
  limit: p.limit,
  page: p.page,
  cond,
  orders: p.sort,
});

res.setHeader('X-Total-Count', totalCount);
res.setHeader('X-Total-Pages', totalPages);
res.json({pages});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    0
    • beta
  • 0.1.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    0

Package Sidebar

Install

npm i pagination-ts

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

21.4 kB

Total Files

51

Last publish

Collaborators

  • shsssskn