Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@matrixai/pagination

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@matrixai/pagination - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

dist/cursor.d.ts

2

dist/Cursor.d.ts

@@ -62,2 +62,2 @@ /**

declare function pageNextA<I extends Iterable<[S, any]>, S>(page: Pagination<I, S>, action: ActionSync<I, S>, limit?: number): Pagination<I, S>;
export { Pagination, PatchSeekLimit, PatchSeekAfterBefore, ActionAsync, ActionSync, ActionResult, pageCurr, pageCurrA, pagePrev, pagePrevA, pageNext, pageNextA };
export { Pagination, PatchSeekLimit, PatchSeekAfterBefore, ActionAsync, ActionSync, ActionResult, pageCurr, pageCurrA, pagePrev, pagePrevA, pageNext, pageNextA, };

@@ -1,119 +0,22 @@

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurr", function() { return pageCurr; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrA", function() { return pageCurrA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrev", function() { return pagePrev; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevA", function() { return pagePrevA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNext", function() { return pageNext; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextA", function() { return pageNextA; });
/**
* Cursor pagination
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.pageNextA = exports.pageNext = exports.pagePrevA = exports.pagePrev = exports.pageCurrA = exports.pageCurr = void 0;
function pageCurr(page, limit) {
if (page.order === true) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
return {
order: true,
seek: page.seek,
limit: limitNew
limit: limitNew,
};
}
else if (page.order === false) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
return {
order: false,
seek: page.seek,
limit: limitNew
limit: limitNew,
};

@@ -125,6 +28,7 @@ }

seekAfter: page.seekAfter,
seekBefore: page.seekBefore
seekBefore: page.seekBefore,
};
}
}
exports.pageCurr = pageCurr;
function pageCurrA(page, action, limit) {

@@ -134,9 +38,10 @@ const patch = pageCurr(page, limit);

}
exports.pageCurrA = pageCurrA;
function pagePrev(page, limit) {
let limitNew;
if (page.order === null) {
limitNew = (limit != null) ? limit : page.length;
limitNew = limit != null ? limit : page.length;
}
else {
limitNew = (limit != null) ? limit : page.limit;
limitNew = limit != null ? limit : page.limit;
}

@@ -146,5 +51,6 @@ return {

seek: page.seekFirst,
limit: limitNew
limit: limitNew,
};
}
exports.pagePrev = pagePrev;
function pagePrevA(page, action, limit) {

@@ -154,9 +60,10 @@ const patch = pagePrev(page, limit);

}
exports.pagePrevA = pagePrevA;
function pageNext(page, limit) {
let limitNew;
if (page.order === null) {
limitNew = (limit != null) ? limit : page.length;
limitNew = limit != null ? limit : page.length;
}
else {
limitNew = (limit != null) ? limit : page.limit;
limitNew = limit != null ? limit : page.limit;
}

@@ -166,5 +73,6 @@ return {

seek: page.seekLast,
limit: limitNew
limit: limitNew,
};
}
exports.pageNext = pageNext;
function pageNextA(page, action, limit) {

@@ -174,2 +82,3 @@ const patch = pageNext(page, limit);

}
exports.pageNextA = pageNextA;
function processAction(action, patch) {

@@ -190,7 +99,2 @@ let result;

}
/***/ })
/******/ ]);
//# sourceMappingURL=Cursor.js.map

@@ -1,3 +0,3 @@

import * as Offset from './Offset';
import * as Cursor from './Cursor';
export { Offset, Cursor };
import * as offset from './offset';
import * as cursor from './cursor';
export { offset, cursor };

@@ -1,409 +0,27 @@

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageIndex", function() { return pageIndex; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCount", function() { return pageCount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageFirst", function() { return pageFirst; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageLast", function() { return pageLast; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pages", function() { return pages; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagesI", function() { return pagesI; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagesT", function() { return pagesT; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurr", function() { return pageCurr; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrA", function() { return pageCurrA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrRaw", function() { return pageCurrRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrRawA", function() { return pageCurrRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrev", function() { return pagePrev; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevA", function() { return pagePrevA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevRaw", function() { return pagePrevRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevRawA", function() { return pagePrevRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNext", function() { return pageNext; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextA", function() { return pageNextA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextRaw", function() { return pageNextRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextRawA", function() { return pageNextRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeek", function() { return pageSeek; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekA", function() { return pageSeekA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekRaw", function() { return pageSeekRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekRawA", function() { return pageSeekRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJump", function() { return pageJump; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpA", function() { return pageJumpA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpRaw", function() { return pageJumpRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpRawA", function() { return pageJumpRawA; });
/**
* Offset pagination
*/
function range(start, end) {
return Array.from({ length: end - start }, (_, i) => i + start);
}
function pageIndex(seek, limit) {
return Math.floor(seek / limit);
}
function pageCount(total, limit) {
return Math.ceil(total / limit);
}
function pageFirst(index) {
return index === 0;
}
function pageLast(index, count) {
return index === (count - 1);
}
function pages(count) {
return range(1, count + 1);
}
function* pagesI(count) {
for (let i = 1; i <= count; ++i) {
yield i;
}
}
function pagesT(count, index, countLeft, countIndex, countRight) {
const countSlots = countLeft + 1 + countIndex + 1 + countRight;
if (count <= countSlots) {
return [pages(count)];
}
const leftStart = 1;
const leftEnd = countLeft;
const indexStart = index - Math.floor(countIndex / 2) + 1;
const indexEnd = index + Math.floor(countIndex / 2) + 1;
const rightStart = count - countRight + 1;
const rightEnd = count;
if (indexStart <= leftEnd + 1) {
const countLeftNew = countSlots - countRight;
return [
range(leftStart, countLeftNew),
range(rightStart, rightEnd + 1)
];
}
else if (indexEnd >= rightStart - 1) {
const countRightNew = countSlots - countLeft - 2;
return [
range(leftStart, leftEnd + 1),
range(count - countRightNew, rightEnd + 1)
];
}
else {
return [
range(leftStart, leftEnd + 1),
range(indexStart, indexEnd + 1),
range(rightStart, rightEnd + 1)
];
}
}
function pageCurr(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const indexNew = pageIndex(page.seek, limitNew);
const seekNew = indexNew * limitNew;
return { seek: seekNew, limit: limitNew };
}
;
function pageCurrA(page, action, limit) {
const patch = pageCurr(page, limit);
return processAction(action, patch);
}
function pageCurrRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const seekNew = page.seek;
return { seek: seekNew, limit: limitNew };
}
;
function pageCurrRawA(page, action, limit) {
const patch = pageCurrRaw(page, limit);
return processAction(action, patch);
}
function pagePrev(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
let indexNew = pageIndex(page.seek, limitNew);
indexNew = Math.max(indexNew - 1, 0);
const seekNew = indexNew * limitNew;
return { seek: seekNew, limit: limitNew };
}
function pagePrevA(page, action, limit) {
const patch = pagePrev(page, limit);
return processAction(action, patch);
}
function pagePrevRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const seekNew = page.seek - limitNew;
return { seek: seekNew, limit: limitNew };
}
function pagePrevRawA(page, action, limit) {
const patch = pagePrevRaw(page, limit);
return processAction(action, patch);
}
function pageNext(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
let indexNew = pageIndex(page.seek, limitNew);
indexNew = indexNew + 1;
const seekNew = indexNew * limitNew;
return { seek: seekNew, limit: limitNew };
}
function pageNextA(page, action, limit) {
const patch = pageNext(page, limit);
return processAction(action, patch);
}
function pageNextRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const seekNew = page.seek + limitNew;
return { seek: seekNew, limit: limitNew };
}
function pageNextRawA(page, action, limit) {
const patch = pageNextRaw(page, limit);
return processAction(action, patch);
}
function pageSeek(page, seek, limit) {
const limitNew = (limit != null) ? limit : page.limit;
let indexNew = pageIndex(seek, limitNew);
indexNew = Math.max(indexNew, 0);
const seekNew = indexNew * limitNew;
return { seek: seekNew, limit: limitNew };
}
function pageSeekA(page, action, seek, limit) {
const patch = pageSeek(page, seek, limit);
return processAction(action, patch);
}
function pageSeekRaw(page, seek, limit) {
const limitNew = (limit != null) ? limit : page.limit;
return { seek: seek, limit: limitNew };
}
function pageSeekRawA(page, action, seek, limit) {
const patch = pageSeekRaw(page, seek, limit);
return processAction(action, patch);
}
function pageJump(page, index, limit) {
const limitNew = (limit != null) ? limit : page.limit;
let indexNew = Math.max(index, 0);
const seekNew = indexNew * limitNew;
return { seek: seekNew, limit: limitNew };
}
function pageJumpA(page, action, index, limit) {
const patch = pageJump(page, index, limit);
return processAction(action, patch);
}
function pageJumpRaw(page, index, limit) {
const limitNew = (limit != null) ? limit : page.limit;
let indexNew = Math.max(index, 0);
const seekNew = indexNew * page.limit;
return { seek: seekNew, limit: limitNew };
}
function pageJumpRawA(page, action, index, limit) {
const patch = pageJumpRaw(page, index, limit);
return processAction(action, patch);
}
function processAction(action, patch) {
const result = action(patch.seek, patch.limit);
if (result instanceof Promise) {
return result.then((result_) => {
return Object.assign(Object.assign({}, patch), { total: result_.total, length: result_.length, items: result_.items });
});
}
else {
return Object.assign(Object.assign({}, patch), { total: result.total, length: result.length, items: result.items });
}
}
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurr", function() { return pageCurr; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrA", function() { return pageCurrA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrev", function() { return pagePrev; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevA", function() { return pagePrevA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNext", function() { return pageNext; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextA", function() { return pageNextA; });
/**
* Cursor pagination
*/
function pageCurr(page, limit) {
if (page.order === true) {
const limitNew = (limit != null) ? limit : page.limit;
return {
order: true,
seek: page.seek,
limit: limitNew
};
}
else if (page.order === false) {
const limitNew = (limit != null) ? limit : page.limit;
return {
order: false,
seek: page.seek,
limit: limitNew
};
}
else {
return {
order: null,
seekAfter: page.seekAfter,
seekBefore: page.seekBefore
};
}
}
function pageCurrA(page, action, limit) {
const patch = pageCurr(page, limit);
return processAction(action, patch);
}
function pagePrev(page, limit) {
let limitNew;
if (page.order === null) {
limitNew = (limit != null) ? limit : page.length;
}
else {
limitNew = (limit != null) ? limit : page.limit;
}
return {
order: false,
seek: page.seekFirst,
limit: limitNew
};
}
function pagePrevA(page, action, limit) {
const patch = pagePrev(page, limit);
return processAction(action, patch);
}
function pageNext(page, limit) {
let limitNew;
if (page.order === null) {
limitNew = (limit != null) ? limit : page.length;
}
else {
limitNew = (limit != null) ? limit : page.limit;
}
return {
order: true,
seek: page.seekLast,
limit: limitNew
};
}
function pageNextA(page, action, limit) {
const patch = pageNext(page, limit);
return processAction(action, patch);
}
function processAction(action, patch) {
let result;
if (patch.order === null) {
result = action(patch.order, patch.seekAfter, patch.seekBefore);
}
else {
result = action(patch.order, patch.seek, patch.limit);
}
if (result instanceof Promise) {
return result.then((result_) => (Object.assign(Object.assign({}, patch), { length: result_.length, seekFirst: result_.seekFirst, seekLast: result_.seekLast, items: result_.items })));
}
else {
return Object.assign(Object.assign({}, patch), { length: result.length, seekFirst: result.seekFirst, seekLast: result.seekLast, items: result.items });
}
}
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _Offset__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "Offset", function() { return _Offset__WEBPACK_IMPORTED_MODULE_0__; });
/* harmony import */ var _Cursor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "Cursor", function() { return _Cursor__WEBPACK_IMPORTED_MODULE_1__; });
/***/ })
/******/ ]);
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cursor = exports.offset = void 0;
const offset = __importStar(require("./offset"));
exports.offset = offset;
const cursor = __importStar(require("./cursor"));
exports.cursor = cursor;
//# sourceMappingURL=index.js.map

@@ -28,3 +28,3 @@ /**

declare function pagesI(count: number): IterableIterator<number>;
declare function pagesT(count: number, index: number, countLeft: number, countIndex: number, countRight: number): ([Array<number>] | [Array<number>, Array<number>] | [Array<number>, Array<number>, Array<number>]);
declare function pagesT(count: number, index: number, countLeft: number, countIndex: number, countRight: number): [Array<number>] | [Array<number>, Array<number>] | [Array<number>, Array<number>, Array<number>];
declare function pageCurr<I extends Iterable<any>>(page: Pagination<I>, limit?: number): Patch;

@@ -60,2 +60,2 @@ declare function pageCurrA<I extends Iterable<any>>(page: Pagination<I>, action: ActionAsync<I>, limit?: number): Promise<Pagination<I>>;

declare function pageJumpRawA<I extends Iterable<any>>(page: Pagination<I>, action: ActionSync<I>, seek: number, limit?: number): Pagination<I>;
export { Pagination, Patch, ActionAsync, ActionSync, ActionResult, pageIndex, pageCount, pageFirst, pageLast, pages, pagesI, pagesT, pageCurr, pageCurrA, pageCurrRaw, pageCurrRawA, pagePrev, pagePrevA, pagePrevRaw, pagePrevRawA, pageNext, pageNextA, pageNextRaw, pageNextRawA, pageSeek, pageSeekA, pageSeekRaw, pageSeekRawA, pageJump, pageJumpA, pageJumpRaw, pageJumpRawA };
export { Pagination, Patch, ActionAsync, ActionSync, ActionResult, pageIndex, pageCount, pageFirst, pageLast, pages, pagesI, pagesT, pageCurr, pageCurrA, pageCurrRaw, pageCurrRawA, pagePrev, pagePrevA, pagePrevRaw, pagePrevRawA, pageNext, pageNextA, pageNextRaw, pageNextRawA, pageSeek, pageSeekA, pageSeekRaw, pageSeekRawA, pageJump, pageJumpA, pageJumpRaw, pageJumpRawA, };

@@ -1,124 +0,7 @@

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageIndex", function() { return pageIndex; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCount", function() { return pageCount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageFirst", function() { return pageFirst; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageLast", function() { return pageLast; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pages", function() { return pages; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagesI", function() { return pagesI; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagesT", function() { return pagesT; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurr", function() { return pageCurr; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrA", function() { return pageCurrA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrRaw", function() { return pageCurrRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageCurrRawA", function() { return pageCurrRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrev", function() { return pagePrev; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevA", function() { return pagePrevA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevRaw", function() { return pagePrevRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pagePrevRawA", function() { return pagePrevRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNext", function() { return pageNext; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextA", function() { return pageNextA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextRaw", function() { return pageNextRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageNextRawA", function() { return pageNextRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeek", function() { return pageSeek; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekA", function() { return pageSeekA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekRaw", function() { return pageSeekRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageSeekRawA", function() { return pageSeekRawA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJump", function() { return pageJump; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpA", function() { return pageJumpA; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpRaw", function() { return pageJumpRaw; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pageJumpRawA", function() { return pageJumpRawA; });
/**
* Offset pagination
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.pageJumpRawA = exports.pageJumpRaw = exports.pageJumpA = exports.pageJump = exports.pageSeekRawA = exports.pageSeekRaw = exports.pageSeekA = exports.pageSeek = exports.pageNextRawA = exports.pageNextRaw = exports.pageNextA = exports.pageNext = exports.pagePrevRawA = exports.pagePrevRaw = exports.pagePrevA = exports.pagePrev = exports.pageCurrRawA = exports.pageCurrRaw = exports.pageCurrA = exports.pageCurr = exports.pagesT = exports.pagesI = exports.pages = exports.pageLast = exports.pageFirst = exports.pageCount = exports.pageIndex = void 0;
function range(start, end) {

@@ -130,14 +13,19 @@ return Array.from({ length: end - start }, (_, i) => i + start);

}
exports.pageIndex = pageIndex;
function pageCount(total, limit) {
return Math.ceil(total / limit);
}
exports.pageCount = pageCount;
function pageFirst(index) {
return index === 0;
}
exports.pageFirst = pageFirst;
function pageLast(index, count) {
return index === (count - 1);
return index === count - 1;
}
exports.pageLast = pageLast;
function pages(count) {
return range(1, count + 1);
}
exports.pages = pages;
function* pagesI(count) {

@@ -148,2 +36,3 @@ for (let i = 1; i <= count; ++i) {

}
exports.pagesI = pagesI;
function pagesT(count, index, countLeft, countIndex, countRight) {

@@ -162,24 +51,15 @@ const countSlots = countLeft + 1 + countIndex + 1 + countRight;

const countLeftNew = countSlots - countRight;
return [
range(leftStart, countLeftNew),
range(rightStart, rightEnd + 1)
];
return [range(leftStart, countLeftNew), range(rightStart, rightEnd + 1)];
}
else if (indexEnd >= rightStart - 1) {
const countRightNew = countSlots - countLeft - 2;
return [
range(leftStart, leftEnd + 1),
range(count - countRightNew, rightEnd + 1)
];
return [range(leftStart, leftEnd + 1), range(count - countRightNew, rightEnd + 1)];
}
else {
return [
range(leftStart, leftEnd + 1),
range(indexStart, indexEnd + 1),
range(rightStart, rightEnd + 1)
];
return [range(leftStart, leftEnd + 1), range(indexStart, indexEnd + 1), range(rightStart, rightEnd + 1)];
}
}
exports.pagesT = pagesT;
function pageCurr(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
const indexNew = pageIndex(page.seek, limitNew);

@@ -189,3 +69,3 @@ const seekNew = indexNew * limitNew;

}
;
exports.pageCurr = pageCurr;
function pageCurrA(page, action, limit) {

@@ -195,8 +75,9 @@ const patch = pageCurr(page, limit);

}
exports.pageCurrA = pageCurrA;
function pageCurrRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
const seekNew = page.seek;
return { seek: seekNew, limit: limitNew };
}
;
exports.pageCurrRaw = pageCurrRaw;
function pageCurrRawA(page, action, limit) {

@@ -206,4 +87,5 @@ const patch = pageCurrRaw(page, limit);

}
exports.pageCurrRawA = pageCurrRawA;
function pagePrev(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
let indexNew = pageIndex(page.seek, limitNew);

@@ -214,2 +96,3 @@ indexNew = Math.max(indexNew - 1, 0);

}
exports.pagePrev = pagePrev;
function pagePrevA(page, action, limit) {

@@ -219,7 +102,9 @@ const patch = pagePrev(page, limit);

}
exports.pagePrevA = pagePrevA;
function pagePrevRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
const seekNew = page.seek - limitNew;
return { seek: seekNew, limit: limitNew };
}
exports.pagePrevRaw = pagePrevRaw;
function pagePrevRawA(page, action, limit) {

@@ -229,4 +114,5 @@ const patch = pagePrevRaw(page, limit);

}
exports.pagePrevRawA = pagePrevRawA;
function pageNext(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
let indexNew = pageIndex(page.seek, limitNew);

@@ -237,2 +123,3 @@ indexNew = indexNew + 1;

}
exports.pageNext = pageNext;
function pageNextA(page, action, limit) {

@@ -242,7 +129,9 @@ const patch = pageNext(page, limit);

}
exports.pageNextA = pageNextA;
function pageNextRaw(page, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
const seekNew = page.seek + limitNew;
return { seek: seekNew, limit: limitNew };
}
exports.pageNextRaw = pageNextRaw;
function pageNextRawA(page, action, limit) {

@@ -252,4 +141,5 @@ const patch = pageNextRaw(page, limit);

}
exports.pageNextRawA = pageNextRawA;
function pageSeek(page, seek, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
let indexNew = pageIndex(seek, limitNew);

@@ -260,2 +150,3 @@ indexNew = Math.max(indexNew, 0);

}
exports.pageSeek = pageSeek;
function pageSeekA(page, action, seek, limit) {

@@ -265,6 +156,8 @@ const patch = pageSeek(page, seek, limit);

}
exports.pageSeekA = pageSeekA;
function pageSeekRaw(page, seek, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
return { seek: seek, limit: limitNew };
}
exports.pageSeekRaw = pageSeekRaw;
function pageSeekRawA(page, action, seek, limit) {

@@ -274,4 +167,5 @@ const patch = pageSeekRaw(page, seek, limit);

}
exports.pageSeekRawA = pageSeekRawA;
function pageJump(page, index, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
let indexNew = Math.max(index, 0);

@@ -281,2 +175,3 @@ const seekNew = indexNew * limitNew;

}
exports.pageJump = pageJump;
function pageJumpA(page, action, index, limit) {

@@ -286,4 +181,5 @@ const patch = pageJump(page, index, limit);

}
exports.pageJumpA = pageJumpA;
function pageJumpRaw(page, index, limit) {
const limitNew = (limit != null) ? limit : page.limit;
const limitNew = limit != null ? limit : page.limit;
let indexNew = Math.max(index, 0);

@@ -293,2 +189,3 @@ const seekNew = indexNew * page.limit;

}
exports.pageJumpRaw = pageJumpRaw;
function pageJumpRawA(page, action, index, limit) {

@@ -298,2 +195,3 @@ const patch = pageJumpRaw(page, index, limit);

}
exports.pageJumpRawA = pageJumpRawA;
function processAction(action, patch) {

@@ -310,7 +208,2 @@ const result = action(patch.seek, patch.limit);

}
/***/ })
/******/ ]);
//# sourceMappingURL=Offset.js.map
{
"name": "@matrixai/pagination",
"version": "0.1.0",
"version": "1.0.0",
"description": "Offset-based and cursor-based pagination utilities",

@@ -17,16 +17,27 @@ "keywords": [

"main": "dist/index.js",
"browser": "dist/browser/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "webpack --mode=production",
"dev": "webpack --mode=development --watch"
"build": "tsc",
"ts-node": "ts-node -r tsconfig-paths/register",
"test": "jest",
"lint": "eslint '{src,tests}/**/*.{js,ts}'",
"lintfix": "eslint '{src,tests}/**/*.{js,ts}' --fix"
},
"devDependencies": {
"awesome-typescript-loader": "^5.2.1",
"source-map-loader": "^0.2.4",
"ts-node": "^8.1.0",
"typescript": "^3.6.3",
"webpack": "^4.40.2",
"webpack-cli": "^3.3.9"
"@types/jest": "^25.0.0",
"@types/node": "^13.13.1",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^25.0.0",
"prettier": "^2.0.5",
"ts-custom-error": "^3.2.0",
"ts-jest": "^25.0.0",
"ts-node": "^8.8.2",
"tsconfig-paths": "^3.9.0",
"typedoc": "^0.17.8",
"typescript": "^3.8.3"
}
}

@@ -13,3 +13,3 @@ # Pagination

The seek index starts at 0.
The seek index starts at 0 and it is inclusive.

@@ -40,2 +40,10 @@ The limit is the desired length of the returned pagination view.

Notice that the `seek`, `seekStart` and `seekEnd` are all exclusive. This is required so that paging doesn't show results that overlap with existing results. This is because the next or previous page is fetched by using the seek key of the first or last item.
Therefore to get the `['A']`, you would need to seek with `0 - 1`. Or at least some way of subtracting the seek key.
Valid seek keys include integers and dates.
There can be an extra parameter called `sort` that would sort the results according the seek key in descending or ascending manner. Here we assume ascending sort. This is however not a concern of pagination, but a concern of how results should be displayed. Therefore the `order` parameter controls the order of the seek, but not the order of the results.
Cursor pagination does not allow random access of the pages. You can however randomly access if you know the seek key you want.

@@ -42,0 +50,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc