Nuclear Package Magnet

    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});

    Keywords

    none

    Install

    npm i pagination-ts

    DownloadsWeekly Downloads

    4

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    21.4 kB

    Total Files

    51

    Last publish

    Collaborators

    • shsssskn