Skip to content
Snippets Groups Projects
Commit 926c0e39 authored by Christian Knecht's avatar Christian Knecht
Browse files

feature: add pagination filter utility

parent d38a662f
No related branches found
No related tags found
No related merge requests found
{
"name": "value-converters",
"version": "1.0.0",
"version": "1.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0.0",
"version": "1.1.0",
"license": "BSD-3-Clause-Clear",
"dependencies": {
"lodash": "^4.17.21",
......@@ -17,11 +17,11 @@
"@types/traverse": "^0.6.32",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint": "^7.24.0",
"jest": "^26.6.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
"typescript": "^4.2.4"
}
},
"node_modules/@babel/code-frame": {
......@@ -2408,9 +2408,9 @@
}
},
"node_modules/eslint": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.23.0.tgz",
"integrity": "sha512-kqvNVbdkjzpFy0XOszNwjkKzZ+6TcwCQ/h+ozlcIWwaimBBuhlQ4nN6kbiM2L+OjDcznkTJxzYfRFH92sx4a0Q==",
"version": "7.24.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.24.0.tgz",
"integrity": "sha512-k9gaHeHiFmGCDQ2rEfvULlSLruz6tgfA8DEn+rY9/oYPFFTlz55mM/Q/Rij1b2Y42jwZiK3lXvNTw6w6TXzcKQ==",
"dev": true,
"dependencies": {
"@babel/code-frame": "7.12.11",
......@@ -6963,9 +6963,9 @@
}
},
"node_modules/typescript": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==",
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
......@@ -9280,9 +9280,9 @@
}
},
"eslint": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.23.0.tgz",
"integrity": "sha512-kqvNVbdkjzpFy0XOszNwjkKzZ+6TcwCQ/h+ozlcIWwaimBBuhlQ4nN6kbiM2L+OjDcznkTJxzYfRFH92sx4a0Q==",
"version": "7.24.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.24.0.tgz",
"integrity": "sha512-k9gaHeHiFmGCDQ2rEfvULlSLruz6tgfA8DEn+rY9/oYPFFTlz55mM/Q/Rij1b2Y42jwZiK3lXvNTw6w6TXzcKQ==",
"dev": true,
"requires": {
"@babel/code-frame": "7.12.11",
......@@ -12816,9 +12816,9 @@
}
},
"typescript": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==",
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
"dev": true
},
"union-value": {
......
{
"name": "value-converters",
"version": "1.0.0",
"version": "1.1.0",
"description": "extended filtering function, sorting, localization, dissolving urls and reusable validators",
"main": "dist/index.js",
"scripts": {
......@@ -28,11 +28,11 @@
"@types/traverse": "^0.6.32",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint": "^7.24.0",
"jest": "^26.6.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
"typescript": "^4.2.4"
},
"dependencies": {
"lodash": "^4.17.21",
......
......@@ -9,6 +9,7 @@ export * as utilities from './utilities';
export {dissolveUrl} from './utilities/dissolveUrl';
export {filter} from './utilities/filter';
export {localize} from './utilities/localize';
export {pagination} from './utilities/pagination';
export {sort} from './utilities/sort';
export * as validators from './validators';
export * as arrayValidators from './validators/arrayValidators';
......
export {dissolveUrl} from './dissolveUrl';
export {filter} from './filter';
export {localize} from './localize';
export {pagination} from './pagination';
export {sort} from './sort';
'use strict';
export function pagination(array: any[], skip: number, limit: number): any[] {
if (!array || !limit || limit > array.length || skip * limit > array.length) {
return array;
}
return array.slice(skip * limit, (skip * limit) + limit);
}
import {pagination} from '../../../src/utilities/pagination';
const array1 = [...Array(56).keys()].slice(1);
test.each([
[array1, 0, 10, [...Array(11).keys()].slice(1)],
[array1, 1, 10, [...Array(21).keys()].slice(11)],
[array1, 2, 10, [...Array(31).keys()].slice(21)],
[array1, 3, 10, [...Array(41).keys()].slice(31)],
[array1, 4, 10, [...Array(51).keys()].slice(41)],
[array1, 5, 10, [...Array(56).keys()].slice(51)],
[array1, 0, 20, [...Array(21).keys()].slice(1)],
[array1, 1, 20, [...Array(41).keys()].slice(21)],
[array1, 2, 20, [...Array(56).keys()].slice(41)],
[array1, 3, 20, array1]
])(
'filter pagination %p, skip %d and limit %d = %p',
(array:any[], skip, limit, expected) => {
expect(pagination(array, skip, limit)).toEqual(expected);
}
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment