@teli-lab/sort-nth-page 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# sort-nth-page
|
|
2
|
+
|
|
3
|
+
Efficient in-memory pagination using quickselect. Returns the sorted items for a single page in **O(n)** average time to isolate the slice + **O(p log p)** to sort it — no full sort required.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @teli-lab/sort-nth-page
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { paginate } from "sort-nth-page";
|
|
15
|
+
|
|
16
|
+
const items = [5, 3, 8, 1, 9, 2, 7, 4, 6, 10];
|
|
17
|
+
|
|
18
|
+
paginate(items, 0, 3, (a, b) => a - b); // [1, 2, 3]
|
|
19
|
+
paginate(items, 1, 3, (a, b) => a - b); // [4, 5, 6]
|
|
20
|
+
paginate(items, 2, 3, (a, b) => a - b); // [7, 8, 9]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
paginate<T>(
|
|
27
|
+
items: readonly T[],
|
|
28
|
+
pageNumber: number, // 0-indexed
|
|
29
|
+
pageSize: number,
|
|
30
|
+
comparator: (a: T, b: T) => number
|
|
31
|
+
): T[]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Returns the sorted items for the requested page, or `[]` if the page is out of range. The original array is not mutated.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@teli-lab/sort-nth-page",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Efficient in-memory pagination using quickselect — O(n) isolation + O(p log p) sort, no full sort required",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/teli-lab/sort-nth-page.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/teli-lab/sort-nth-page#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/teli-lab/sort-nth-page/issues"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist"],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json",
|
|
25
|
+
"test": "node --experimental-strip-types --test src/*.test.ts"
|
|
26
|
+
},
|
|
27
|
+
"keywords": ["pagination", "quickselect", "sorting", "algorithm"],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.0.0",
|
|
31
|
+
"typescript": "^5.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|