astro-accelerator-utils 0.0.31 → 0.0.32

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/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as PostQueries from "./lib/postQueries.mjs";
2
2
  import * as PostFiltering from "./lib/postFiltering.mjs";
3
3
  import * as PostOrdering from "./lib/postOrdering.mjs";
4
+ import * as PostPaging from "./lib/postPaging.mjs";
4
5
  import * as Cache from "./lib/cache.mjs";
5
6
  import * as Dates from "./lib/dates.mjs";
6
7
  import * as Urls from "./lib/urls.mjs";
7
- export { PostQueries, PostFiltering, PostOrdering, Cache, Dates, Urls };
8
+ export { PostQueries, PostFiltering, PostOrdering, PostPaging, Cache, Dates, Urls };
package/index.mjs CHANGED
@@ -1,14 +1,16 @@
1
- import * as PostQueries from "./lib/postQueries.mjs";
2
- import * as PostFiltering from "./lib/postFiltering.mjs";
3
- import * as PostOrdering from "./lib/postOrdering.mjs";
4
- import * as Cache from "./lib/cache.mjs";
5
- import * as Dates from "./lib/dates.mjs";
6
- import * as Urls from "./lib/urls.mjs";
1
+ import * as PostQueries from './lib/postQueries.mjs';
2
+ import * as PostFiltering from './lib/postFiltering.mjs';
3
+ import * as PostOrdering from './lib/postOrdering.mjs';
4
+ import * as PostPaging from './lib/postPaging.mjs';
5
+ import * as Cache from './lib/cache.mjs';
6
+ import * as Dates from './lib/dates.mjs';
7
+ import * as Urls from './lib/urls.mjs';
7
8
 
8
9
  export {
9
10
  PostQueries,
10
11
  PostFiltering,
11
12
  PostOrdering,
13
+ PostPaging,
12
14
  Cache,
13
15
  Dates,
14
16
  Urls
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @typedef { import("../types/Link").Link } Link
3
+ */
4
+ /**
5
+ * Provides a list of paging links, 1 ... 3 4 5 ... 7
6
+ * @param {number} limit
7
+ * @param {number} numberOfPages
8
+ * @param {number} currentPage
9
+ * @param {string} url
10
+ * @returns {Link[]}
11
+ */
12
+ export function getPageLinks(limit: number, numberOfPages: number, currentPage: number, url: string): Link[];
13
+ export type Link = import("../types/Link").Link;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @typedef { import("../types/Link").Link } Link
3
+ */
4
+
5
+ /**
6
+ * Provides a list of paging links, 1 ... 3 4 5 ... 7
7
+ * @param {number} limit
8
+ * @param {number} numberOfPages
9
+ * @param {number} currentPage
10
+ * @param {string} url
11
+ * @returns {Link[]}
12
+ */
13
+ export function getPageLinks(limit, numberOfPages, currentPage, url) {
14
+ /** @type {Link[]} */
15
+ const pageLinks = [];
16
+
17
+ let start = 0;
18
+ let end = numberOfPages;
19
+
20
+ if (numberOfPages > limit) {
21
+ start = (currentPage - (limit - 1) / 2) - 1;
22
+ if (start < 0) {
23
+ start = 0;
24
+ }
25
+
26
+ end = (start + limit);
27
+ if (end > numberOfPages) {
28
+ end = numberOfPages;
29
+ start = numberOfPages - limit;
30
+ }
31
+ }
32
+
33
+ if (start == 1) {
34
+ pageLinks.push({
35
+ title: '1',
36
+ url: url.replace('/' + currentPage, '/' + 1),
37
+ ariaCurrent: false,
38
+ class: ''
39
+ });
40
+ } else if (start > 1) {
41
+ pageLinks.push({
42
+ title: '1',
43
+ url: url.replace('/' + currentPage, '/' + 1),
44
+ ariaCurrent: false,
45
+ class: 'paging-collapse-after'
46
+ });
47
+ }
48
+
49
+ for (let i = start; i < end; i++) {
50
+ const userPage = i + 1;
51
+ pageLinks.push({
52
+ title: userPage.toString(),
53
+ url: url.replace('/' + currentPage, '/' + userPage),
54
+ ariaCurrent: userPage == currentPage ? 'page' : false,
55
+ class: ''
56
+ });
57
+ }
58
+
59
+ if (end < (numberOfPages - 1)) {
60
+ pageLinks.push({
61
+ title: numberOfPages.toString(),
62
+ url: url.replace('/' + currentPage, '/' + numberOfPages),
63
+ ariaCurrent: false,
64
+ class: 'paging-collapse-before'
65
+ });
66
+ } else if (end < numberOfPages) {
67
+ pageLinks.push({
68
+ title: numberOfPages.toString(),
69
+ url: url.replace('/' + currentPage, '/' + numberOfPages),
70
+ ariaCurrent: false,
71
+ class: ''
72
+ });
73
+ }
74
+
75
+ return pageLinks;
76
+ }
77
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -0,0 +1,6 @@
1
+ export interface Link {
2
+ title: string;
3
+ url: string;
4
+ ariaCurrent: 'page' | false;
5
+ class: string;
6
+ }