@aboutbits/pagination
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -5,6 +5,7 @@ declare enum IndexType { | ||
} | ||
declare const calculatePagination: (page: number, size: number, total: number, config?: { | ||
indexType?: IndexType | undefined; | ||
maxPages?: number | undefined; | ||
} | undefined) => { | ||
type CalculatePaginationConfig = { | ||
indexType: IndexType; | ||
maxPages: number; | ||
}; | ||
declare const calculatePagination: (page: number, size: number, total: number, config?: Partial<CalculatePaginationConfig>) => { | ||
previous: { | ||
@@ -11,0 +12,0 @@ indexNumber: number; |
@@ -0,1 +1,12 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var IndexType; | ||
@@ -40,9 +51,11 @@ (function (IndexType) { | ||
}; | ||
var defaultCalculatePaginationConfig = { | ||
indexType: IndexType.ZERO_BASED, | ||
maxPages: 5, | ||
}; | ||
var calculatePagination = function (page, size, total, config) { | ||
var _a, _b; | ||
var _a = __assign(__assign({}, defaultCalculatePaginationConfig), config), indexType = _a.indexType, maxPages = _a.maxPages; | ||
if (total <= size) { | ||
return null; | ||
} | ||
var indexType = (_a = config === null || config === void 0 ? void 0 : config.indexType) !== null && _a !== void 0 ? _a : IndexType.ONE_BASED; | ||
var maxPages = (_b = config === null || config === void 0 ? void 0 : config.maxPages) !== null && _b !== void 0 ? _b : 5; | ||
var firstPage = indexType === IndexType.ZERO_BASED ? 0 : 1; | ||
@@ -49,0 +62,0 @@ var lastPage = Math.ceil(total / size) + (firstPage - 1); |
@@ -5,6 +5,7 @@ declare enum IndexType { | ||
} | ||
declare const calculatePagination: (page: number, size: number, total: number, config?: { | ||
indexType?: IndexType | undefined; | ||
maxPages?: number | undefined; | ||
} | undefined) => { | ||
type CalculatePaginationConfig = { | ||
indexType: IndexType; | ||
maxPages: number; | ||
}; | ||
declare const calculatePagination: (page: number, size: number, total: number, config?: Partial<CalculatePaginationConfig>) => { | ||
previous: { | ||
@@ -11,0 +12,0 @@ indexNumber: number; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -44,9 +55,11 @@ exports.IndexType = exports.calculatePagination = void 0; | ||
}; | ||
var defaultCalculatePaginationConfig = { | ||
indexType: IndexType.ZERO_BASED, | ||
maxPages: 5, | ||
}; | ||
var calculatePagination = function (page, size, total, config) { | ||
var _a, _b; | ||
var _a = __assign(__assign({}, defaultCalculatePaginationConfig), config), indexType = _a.indexType, maxPages = _a.maxPages; | ||
if (total <= size) { | ||
return null; | ||
} | ||
var indexType = (_a = config === null || config === void 0 ? void 0 : config.indexType) !== null && _a !== void 0 ? _a : IndexType.ONE_BASED; | ||
var maxPages = (_b = config === null || config === void 0 ? void 0 : config.maxPages) !== null && _b !== void 0 ? _b : 5; | ||
var firstPage = indexType === IndexType.ZERO_BASED ? 0 : 1; | ||
@@ -53,0 +66,0 @@ var lastPage = Math.ceil(total / size) + (firstPage - 1); |
{ | ||
"name": "@aboutbits/pagination", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Pagination", | ||
@@ -16,2 +16,6 @@ "keywords": [ | ||
"typings": "dist/index.d.ts", | ||
"engines": { | ||
"npm": "^8", | ||
"node": "^16" | ||
}, | ||
"scripts": { | ||
@@ -23,2 +27,3 @@ "build": "npm run build:node && npm run build:esm", | ||
"lint:fix": "npm run lint -- --fix", | ||
"typecheck": "tsc --noEmit", | ||
"test": "jest --config jestconfig.json --passWithNoTests", | ||
@@ -46,15 +51,16 @@ "prepare": "npm run build", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.9", | ||
"@typescript-eslint/eslint-plugin": "^3.8.0", | ||
"@typescript-eslint/parser": "^3.8.0", | ||
"eslint": "^7.6.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"eslint-plugin-jest": "^23.20.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"jest": "^26.2.2", | ||
"prettier": "^2.0.5", | ||
"ts-jest": "^26.1.4", | ||
"typescript": "^3.9.7" | ||
"@types/jest": "^28.1.3", | ||
"@typescript-eslint/eslint-plugin": "^5.30.0", | ||
"@typescript-eslint/parser": "^5.30.0", | ||
"eslint": "^8.18.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.5.3", | ||
"eslint-plugin-prettier": "^4.1.0", | ||
"jest": "^28.1.2", | ||
"jest-environment-jsdom": "^29.6.1", | ||
"prettier": "^2.7.1", | ||
"ts-jest": "^28.0.5", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
Pagination | ||
========== | ||
[![npm version](https://badge.fury.io/js/%40aboutbits%2Fpagination.svg)](https://badge.fury.io/js/%40aboutbits%2Fpagination) | ||
[![npm package](https://badge.fury.io/js/%40aboutbits%2Fpagination.svg)](https://badge.fury.io/js/%40aboutbits%2Fpagination) | ||
[![license](https://img.shields.io/github/license/aboutbits/pagination)](https://github.com/aboutbits/pagination/blob/master/license.md) | ||
@@ -6,0 +7,0 @@ This pagacke includes a pagination calculation, where you can simply pass some basic information to the calcualtion function, and in return you receive an object with all relevant pagination information. |
12520
216
111
13