@dazejs/framework
Version:
Daze.js - A powerful web framework for Node.js
62 lines • 2.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Paginator = void 0;
class Paginator {
constructor(items, total, currentPage, perPage, option) {
this._items = items;
this._perPage = perPage;
this._currentPage = currentPage;
this._total = total;
this._option = option;
}
static configure(option) {
if (option.currentPageKey)
this.currentPageKey = option.currentPageKey;
if (option.perPageKey)
this.perPageKey = option.perPageKey;
if (option.totalkey)
this.totalkey = option.totalkey;
}
getDataKey() {
var _a, _b;
return (_b = (_a = this._option) === null || _a === void 0 ? void 0 : _a.dataKey) !== null && _b !== void 0 ? _b : Paginator.dataKey;
}
getCurrentPageKey() {
var _a, _b;
return (_b = (_a = this._option) === null || _a === void 0 ? void 0 : _a.currentPageKey) !== null && _b !== void 0 ? _b : Paginator.currentPageKey;
}
getTotalKey() {
var _a, _b;
return (_b = (_a = this._option) === null || _a === void 0 ? void 0 : _a.totalkey) !== null && _b !== void 0 ? _b : Paginator.totalkey;
}
getPerPageKey() {
var _a, _b;
return (_b = (_a = this._option) === null || _a === void 0 ? void 0 : _a.perPageKey) !== null && _b !== void 0 ? _b : Paginator.perPageKey;
}
getCurrentPage() {
return Number(this._currentPage);
}
getPerPage() {
return Number(this._perPage);
}
getTotal() {
return Number(this._total);
}
getData() {
return this._items;
}
toJSON() {
return {
[this.getCurrentPageKey()]: this.getCurrentPage(),
[this.getPerPageKey()]: this.getPerPage(),
[this.getTotalKey()]: this.getTotal(),
[this.getDataKey()]: this.getData()
};
}
}
exports.Paginator = Paginator;
Paginator.currentPageKey = 'current_page';
Paginator.perPageKey = 'per_page';
Paginator.totalkey = 'total';
Paginator.dataKey = 'data';
//# sourceMappingURL=paginator.js.map