api-paginate 1.0.2 → 1.0.4

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 CHANGED
@@ -4,6 +4,16 @@ Paginate arrays in **Node** (and browsers). In-memory pagination for arrays. Use
4
4
 
5
5
  Returns JSON with `data`, `meta`, and `links`—ready to send. Configure once, pass only `route`.
6
6
 
7
+ ### Why api-paginate?
8
+
9
+ - **One place to configure** — Set `baseUrl` in your entry file; in every route you only pass `route` and `per_page`. No repeating yourself.
10
+ - **Any array, any stack** — Mongoose, Prisma, Sequelize, raw SQL, or a plain `[]`. Pagination happens in memory after you fetch; no ORM magic or query hooks.
11
+ - **Familiar JSON shape** — `data`, `meta`, and `links` (first/prev/next/last) match what many APIs and frontends expect. No custom envelope.
12
+ - **Small and predictable** — No database layer, no heavy deps. Just slicing arrays and building links. Easy to reason about and safe to upgrade.
13
+ - **Works in Node and browsers** — Use it in API routes or in the client; in the browser it uses `window.location.origin` when you don’t call `configure`.
14
+
15
+ If you’ve ever copy-pasted pagination logic or built `meta`/`links` by hand, this package replaces that with a single call in your return.
16
+
7
17
  ### Features
8
18
 
9
19
  - **Framework-agnostic** — Use with Express, Next.js, Fastify, or plain Node
package/dist/index.d.mts CHANGED
@@ -1,15 +1,8 @@
1
1
  interface PaginateOptions {
2
- /** Current page (1-based); use this instead of deprecated page */
3
2
  current_page?: number;
4
- /** Items per page; use this instead of deprecated perPage */
5
3
  per_page?: number;
6
- /** Base URL for link generation; if omitted, uses configured baseUrl or auto-detects in browser */
7
4
  baseUrl?: string;
8
- /** Route/path for links (e.g. '/api/users'). Combines with configured baseUrl or window.origin. */
9
5
  route?: string;
10
- /** @deprecated Use route instead. Path for link generation. */
11
- path?: string;
12
- /** Query param name for page (default: 'page') */
13
6
  pageParam?: string;
14
7
  }
15
8
  interface PaginateMeta {
@@ -43,18 +36,10 @@ interface PaginateRequest {
43
36
  }
44
37
 
45
38
  interface PaginatorConfig {
46
- /** Application base URL (origin), e.g. https://myserver.com or http://localhost:3000 */
47
39
  baseUrl?: string;
48
- /** Default route, e.g. /api (used when paginate is called without route) */
49
40
  route?: string;
50
- /** @deprecated Use route instead */
51
- path?: string;
52
- /** Default page param name */
53
41
  pageParam?: string;
54
- /** Default per_page */
55
42
  per_page?: number;
56
- /** @deprecated Use per_page instead */
57
- perPage?: number;
58
43
  }
59
44
  /**
60
45
  * Configure default options once. These are used when not overridden per-call.
package/dist/index.d.ts CHANGED
@@ -1,15 +1,8 @@
1
1
  interface PaginateOptions {
2
- /** Current page (1-based); use this instead of deprecated page */
3
2
  current_page?: number;
4
- /** Items per page; use this instead of deprecated perPage */
5
3
  per_page?: number;
6
- /** Base URL for link generation; if omitted, uses configured baseUrl or auto-detects in browser */
7
4
  baseUrl?: string;
8
- /** Route/path for links (e.g. '/api/users'). Combines with configured baseUrl or window.origin. */
9
5
  route?: string;
10
- /** @deprecated Use route instead. Path for link generation. */
11
- path?: string;
12
- /** Query param name for page (default: 'page') */
13
6
  pageParam?: string;
14
7
  }
15
8
  interface PaginateMeta {
@@ -43,18 +36,10 @@ interface PaginateRequest {
43
36
  }
44
37
 
45
38
  interface PaginatorConfig {
46
- /** Application base URL (origin), e.g. https://myserver.com or http://localhost:3000 */
47
39
  baseUrl?: string;
48
- /** Default route, e.g. /api (used when paginate is called without route) */
49
40
  route?: string;
50
- /** @deprecated Use route instead */
51
- path?: string;
52
- /** Default page param name */
53
41
  pageParam?: string;
54
- /** Default per_page */
55
42
  per_page?: number;
56
- /** @deprecated Use per_page instead */
57
- perPage?: number;
58
43
  }
59
44
  /**
60
45
  * Configure default options once. These are used when not overridden per-call.
package/dist/index.js CHANGED
@@ -50,7 +50,7 @@ function resolveBaseUrl(options) {
50
50
  if (typeof opts.baseUrl === "string" && opts.baseUrl.trim()) {
51
51
  return opts.baseUrl.trim();
52
52
  }
53
- const path = (typeof opts.route === "string" ? opts.route : opts.path) ?? "";
53
+ const path = typeof opts.route === "string" ? opts.route : "";
54
54
  const pathTrimmed = typeof path === "string" ? path.trim() : "";
55
55
  if (pathTrimmed && config.baseUrl) {
56
56
  return joinBaseAndPath(config.baseUrl.trim(), pathTrimmed);
@@ -59,7 +59,7 @@ function resolveBaseUrl(options) {
59
59
  return joinBaseAndPath(window.location.origin, pathTrimmed);
60
60
  }
61
61
  if (pathTrimmed) return pathTrimmed;
62
- const configRoute = config.route ?? config.path;
62
+ const configRoute = config.route;
63
63
  if (config.baseUrl && configRoute) {
64
64
  return joinBaseAndPath(config.baseUrl.trim(), configRoute.trim());
65
65
  }
package/dist/index.mjs CHANGED
@@ -19,7 +19,7 @@ function resolveBaseUrl(options) {
19
19
  if (typeof opts.baseUrl === "string" && opts.baseUrl.trim()) {
20
20
  return opts.baseUrl.trim();
21
21
  }
22
- const path = (typeof opts.route === "string" ? opts.route : opts.path) ?? "";
22
+ const path = typeof opts.route === "string" ? opts.route : "";
23
23
  const pathTrimmed = typeof path === "string" ? path.trim() : "";
24
24
  if (pathTrimmed && config.baseUrl) {
25
25
  return joinBaseAndPath(config.baseUrl.trim(), pathTrimmed);
@@ -28,7 +28,7 @@ function resolveBaseUrl(options) {
28
28
  return joinBaseAndPath(window.location.origin, pathTrimmed);
29
29
  }
30
30
  if (pathTrimmed) return pathTrimmed;
31
- const configRoute = config.route ?? config.path;
31
+ const configRoute = config.route;
32
32
  if (config.baseUrl && configRoute) {
33
33
  return joinBaseAndPath(config.baseUrl.trim(), configRoute.trim());
34
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-paginate",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Paginate arrays for Node and browsers. Configure once at app entry (app.ts/server.ts); use paginate/paginateFromRequest in routes. Returns JSON with data, meta, and links.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -12,8 +12,27 @@
12
12
  "require": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": ["dist", "README.md"],
16
- "keywords": ["pagination", "array", "node", "nodejs", "api", "express", "nextjs", "react", "angular", "json", "res.json", "meta", "links", "configure", "baseUrl"],
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "keywords": [
20
+ "pagination",
21
+ "array",
22
+ "node",
23
+ "nodejs",
24
+ "api",
25
+ "express",
26
+ "nextjs",
27
+ "react",
28
+ "angular",
29
+ "json",
30
+ "res.json",
31
+ "meta",
32
+ "links",
33
+ "configure",
34
+ "baseUrl"
35
+ ],
17
36
  "license": "MIT",
18
37
  "author": "Kabanda Kpanti Michael <michaelkpantiramp@gmail.com> (https://github.com/Michael-Builds)",
19
38
  "repository": {
@@ -21,6 +40,7 @@
21
40
  "url": "git+https://github.com/Michael-Builds/api-paginate.git"
22
41
  },
23
42
  "homepage": "https://api-paginate.vercel.app",
43
+ "docs": "https://api-paginate.vercel.app/docs",
24
44
  "bugs": {
25
45
  "url": "https://github.com/Michael-Builds/api-paginate/issues"
26
46
  },
@@ -37,6 +57,6 @@
37
57
  "tailwindcss": "^4",
38
58
  "tsup": "^8.0.0",
39
59
  "typescript": "^5.0.0",
40
- "vitest": "^1.0.0"
60
+ "vitest": "^4.1.0"
41
61
  }
42
62
  }