Pagination for Nodejs and JavaScript..
I rewrite it to 3.0 making performance better and size smaller. So if you use 3.0 above, please check "How to use" section again.
$ npm install ts-pagination --save
import { getSimplePagination } from "ts-pagination";
const data = [
{ id: "1", name: "bb0", age: 25 },
{ id: "2", name: "bb1", age: 26 },
{ id: "3", name: "bb2", age: 27 },
{ id: "4", name: "bb3", age: 28 },
{ id: "5", name: "bb4", age: 29 },
{ id: "6", name: "bb5", age: 210 },
];
const sPagination = getSimplePagination(
{
currentPage: 1,
size: 5,
total: data.length,
},
3,
{
firstText: "first",
lastText: "last",
preGroupText: "<<",
nextGroupText: ">>",
PreText: "<",
nextText: ">",
isShowFirstLastItem: true,
isShowPrevNextGroupItem: true,
isShowPrevNextItem: true,
}
);
console.log(sPagination);
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
src | 100 | 100 | 100 | 100 |
_index.ts | 100 | 100 | 100 | 100 |
src/code | 100 | 100 | 100 | 100 |
core.ts | 100 | 100 | 100 | 100 |
getSimplePagination.ts | 100 | 100 | 100 | 100 |
-------------------------|---------|----------|---------|---------|-------------------
docker run --rm -it \
-w /app \
-v $(pwd):/app \
-p 3000:3000 \
-p 10000:10000 \
-p 24678:24678 \
node:16.19-alpine /bin/sh
apk add --no-cache bash &&\
npm i -g pnpm