@visulima/pagination 3.0.24 → 3.0.25

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## @visulima/pagination [3.0.25](https://github.com/visulima/visulima/compare/@visulima/pagination@3.0.24...@visulima/pagination@3.0.25) (2025-01-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ * updated @visulima/packem, and all other dev dependencies ([7797a1c](https://github.com/visulima/visulima/commit/7797a1c3e6f1fc532895247bd88285a8a9883c40))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * updated dev dependencies ([9de2eab](https://github.com/visulima/visulima/commit/9de2eab91e95c8b9289d12f863a5167218770650))
10
+
1
11
  ## @visulima/pagination [3.0.24](https://github.com/visulima/visulima/compare/@visulima/pagination@3.0.23...@visulima/pagination@3.0.24) (2024-12-12)
2
12
 
3
13
  ### Bug Fixes
package/dist/index.cjs CHANGED
@@ -1 +1,15 @@
1
- "use strict";var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./packem_shared/Paginator-dO9FtCU3.cjs"),i=require("./packem_shared/createPaginationMetaSchemaObject-D-0GFE4M.cjs");var g=Object.defineProperty,b=t((e,a)=>g(e,"name",{value:a,configurable:!0}),"e");const m=b((e,a,r,c)=>new n(r,Number(a),Number(e),...c),"paginate");exports.Paginator=n;exports.createPaginationMetaSchemaObject=i.createPaginationMetaSchemaObject;exports.createPaginationSchemaObject=i.createPaginationSchemaObject;exports.paginate=m;
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ const Paginator = require('./packem_shared/Paginator-Bzp4q-CL.cjs');
6
+ const createPaginationMetaSchemaObject = require('./packem_shared/createPaginationMetaSchemaObject-B2_MNxET.cjs');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const paginate = /* @__PURE__ */ __name((page, perPage, total, rows) => new Paginator(total, Number(perPage), Number(page), ...rows), "paginate");
11
+
12
+ exports.Paginator = Paginator;
13
+ exports.createPaginationMetaSchemaObject = createPaginationMetaSchemaObject.createPaginationMetaSchemaObject;
14
+ exports.createPaginationSchemaObject = createPaginationMetaSchemaObject.createPaginationSchemaObject;
15
+ exports.paginate = paginate;
package/dist/index.mjs CHANGED
@@ -1 +1,8 @@
1
- var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});import i from"./packem_shared/Paginator-DI6QB_Ve.mjs";import{createPaginationMetaSchemaObject as P,createPaginationSchemaObject as j}from"./packem_shared/createPaginationMetaSchemaObject-6bBOLPmK.mjs";var c=Object.defineProperty,m=t((e,a)=>c(e,"name",{value:a,configurable:!0}),"e");const p=m((e,a,r,n)=>new i(r,Number(a),Number(e),...n),"paginate");export{i as Paginator,P as createPaginationMetaSchemaObject,j as createPaginationSchemaObject,p as paginate};
1
+ import Paginator from './packem_shared/Paginator-Cn8d66Nq.mjs';
2
+ export { createPaginationMetaSchemaObject, createPaginationSchemaObject } from './packem_shared/createPaginationMetaSchemaObject-fEupXBbv.mjs';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ const paginate = /* @__PURE__ */ __name((page, perPage, total, rows) => new Paginator(total, Number(perPage), Number(page), ...rows), "paginate");
7
+
8
+ export { Paginator, paginate };
@@ -0,0 +1,529 @@
1
+ 'use strict';
2
+
3
+ var __defProp$3 = Object.defineProperty;
4
+ var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
5
+ const replace = String.prototype.replace;
6
+ const percentTwenties = /%20/g;
7
+ const Format = {
8
+ RFC1738: "RFC1738",
9
+ RFC3986: "RFC3986"
10
+ };
11
+ const formatters = {
12
+ RFC1738: /* @__PURE__ */ __name$3(function(value) {
13
+ return replace.call(value, percentTwenties, "+");
14
+ }, "RFC1738"),
15
+ RFC3986: /* @__PURE__ */ __name$3(function(value) {
16
+ return String(value);
17
+ }, "RFC3986")
18
+ };
19
+ const RFC1738 = Format.RFC1738;
20
+ const formats = Format.RFC3986;
21
+
22
+ var __defProp$2 = Object.defineProperty;
23
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
24
+ const isArray$1 = Array.isArray;
25
+ const hexTable = function() {
26
+ const array = [];
27
+ for (let i = 0; i < 256; ++i) {
28
+ array.push("%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase());
29
+ }
30
+ return array;
31
+ }();
32
+ const limit = 1024;
33
+ const encode = /* @__PURE__ */ __name$2(function encode2(str, defaultEncoder, charset, kind, format) {
34
+ if (str.length === 0) {
35
+ return str;
36
+ }
37
+ let string = str;
38
+ if (typeof str === "symbol") {
39
+ string = Symbol.prototype.toString.call(str);
40
+ } else if (typeof str !== "string") {
41
+ string = String(str);
42
+ }
43
+ if (charset === "iso-8859-1") {
44
+ return escape(string).replace(/%u[0-9a-f]{4}/gi, function($0) {
45
+ return "%26%23" + parseInt($0.slice(2), 16) + "%3B";
46
+ });
47
+ }
48
+ let out = "";
49
+ for (let j = 0; j < string.length; j += limit) {
50
+ const segment = string.length >= limit ? string.slice(j, j + limit) : string;
51
+ const arr = [];
52
+ for (let i = 0; i < segment.length; ++i) {
53
+ let c = segment.charCodeAt(i);
54
+ if (c === 45 || // -
55
+ c === 46 || // .
56
+ c === 95 || // _
57
+ c === 126 || // ~
58
+ c >= 48 && c <= 57 || // 0-9
59
+ c >= 65 && c <= 90 || // a-z
60
+ c >= 97 && c <= 122 || // A-Z
61
+ format === RFC1738 && (c === 40 || c === 41)) {
62
+ arr[arr.length] = segment.charAt(i);
63
+ continue;
64
+ }
65
+ if (c < 128) {
66
+ arr[arr.length] = hexTable[c];
67
+ continue;
68
+ }
69
+ if (c < 2048) {
70
+ arr[arr.length] = hexTable[192 | c >> 6] + hexTable[128 | c & 63];
71
+ continue;
72
+ }
73
+ if (c < 55296 || c >= 57344) {
74
+ arr[arr.length] = hexTable[224 | c >> 12] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
75
+ continue;
76
+ }
77
+ i += 1;
78
+ c = 65536 + ((c & 1023) << 10 | segment.charCodeAt(i) & 1023);
79
+ arr[arr.length] = hexTable[240 | c >> 18] + hexTable[128 | c >> 12 & 63] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
80
+ }
81
+ out += arr.join("");
82
+ }
83
+ return out;
84
+ }, "encode");
85
+ const isBuffer = /* @__PURE__ */ __name$2(function isBuffer2(obj) {
86
+ if (!obj || typeof obj !== "object") {
87
+ return false;
88
+ }
89
+ return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
90
+ }, "isBuffer");
91
+ const maybeMap = /* @__PURE__ */ __name$2(function maybeMap2(val, fn) {
92
+ if (isArray$1(val)) {
93
+ const mapped = [];
94
+ for (let i = 0; i < val.length; i += 1) {
95
+ mapped.push(fn(val[i]));
96
+ }
97
+ return mapped;
98
+ }
99
+ return fn(val);
100
+ }, "maybeMap");
101
+
102
+ var __defProp$1 = Object.defineProperty;
103
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
104
+ const has = Object.prototype.hasOwnProperty;
105
+ const arrayPrefixGenerators = {
106
+ brackets: /* @__PURE__ */ __name$1(function brackets(prefix) {
107
+ return prefix + "[]";
108
+ }, "brackets"),
109
+ comma: "comma",
110
+ indices: /* @__PURE__ */ __name$1(function indices(prefix, key) {
111
+ return prefix + "[" + key + "]";
112
+ }, "indices"),
113
+ repeat: /* @__PURE__ */ __name$1(function repeat(prefix) {
114
+ return prefix;
115
+ }, "repeat")
116
+ };
117
+ const isArray = Array.isArray;
118
+ const push = Array.prototype.push;
119
+ const pushToArray = /* @__PURE__ */ __name$1(function(arr, valueOrArray) {
120
+ push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
121
+ }, "pushToArray");
122
+ const toISO = Date.prototype.toISOString;
123
+ const defaultFormat = formats;
124
+ const defaults = {
125
+ addQueryPrefix: false,
126
+ allowDots: false,
127
+ allowEmptyArrays: false,
128
+ arrayFormat: "indices",
129
+ charset: "utf-8",
130
+ charsetSentinel: false,
131
+ delimiter: "&",
132
+ encode: true,
133
+ encodeDotInKeys: false,
134
+ encoder: encode,
135
+ encodeValuesOnly: false,
136
+ format: defaultFormat,
137
+ formatter: formatters[defaultFormat],
138
+ // deprecated
139
+ indices: false,
140
+ serializeDate: /* @__PURE__ */ __name$1(function serializeDate(date) {
141
+ return toISO.call(date);
142
+ }, "serializeDate"),
143
+ skipNulls: false,
144
+ strictNullHandling: false
145
+ };
146
+ const isNonNullishPrimitive = /* @__PURE__ */ __name$1(function isNonNullishPrimitive2(v) {
147
+ return typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "bigint";
148
+ }, "isNonNullishPrimitive");
149
+ const sentinel = {};
150
+ const _stringify = /* @__PURE__ */ __name$1(function stringify2(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate2, format, formatter, encodeValuesOnly, charset, sideChannel) {
151
+ let obj = object;
152
+ let tmpSc = sideChannel;
153
+ let step = 0;
154
+ let findFlag = false;
155
+ while ((tmpSc = tmpSc.get(sentinel)) !== undefined && !findFlag) {
156
+ const pos = tmpSc.get(object);
157
+ step += 1;
158
+ if (typeof pos !== "undefined") {
159
+ if (pos === step) {
160
+ throw new RangeError("Cyclic object value");
161
+ } else {
162
+ findFlag = true;
163
+ }
164
+ }
165
+ if (typeof tmpSc.get(sentinel) === "undefined") {
166
+ step = 0;
167
+ }
168
+ }
169
+ if (typeof filter === "function") {
170
+ obj = filter(prefix, obj);
171
+ } else if (obj instanceof Date) {
172
+ obj = serializeDate2(obj);
173
+ } else if (generateArrayPrefix === "comma" && isArray(obj)) {
174
+ obj = maybeMap(obj, function(value) {
175
+ if (value instanceof Date) {
176
+ return serializeDate2(value);
177
+ }
178
+ return value;
179
+ });
180
+ }
181
+ if (obj === null) {
182
+ if (strictNullHandling) {
183
+ return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, "key", format) : prefix;
184
+ }
185
+ obj = "";
186
+ }
187
+ if (isNonNullishPrimitive(obj) || isBuffer(obj)) {
188
+ if (encoder) {
189
+ const keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, "key", format);
190
+ return [
191
+ formatter(keyValue) + "=" + formatter(encoder(obj, defaults.encoder, charset, "value", format))
192
+ ];
193
+ }
194
+ return [formatter(prefix) + "=" + formatter(String(obj))];
195
+ }
196
+ const values = [];
197
+ if (typeof obj === "undefined") {
198
+ return values;
199
+ }
200
+ let objKeys;
201
+ if (generateArrayPrefix === "comma" && isArray(obj)) {
202
+ if (encodeValuesOnly && encoder) {
203
+ obj = maybeMap(obj, encoder);
204
+ }
205
+ objKeys = [{ value: obj.length > 0 ? obj.join(",") || null : undefined }];
206
+ } else if (isArray(filter)) {
207
+ objKeys = filter;
208
+ } else {
209
+ const keys = Object.keys(obj);
210
+ objKeys = sort ? keys.sort(sort) : keys;
211
+ }
212
+ const encodedPrefix = encodeDotInKeys ? prefix.replace(/\./g, "%2E") : prefix;
213
+ const adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + "[]" : encodedPrefix;
214
+ if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
215
+ return adjustedPrefix + "[]";
216
+ }
217
+ for (let j = 0; j < objKeys.length; ++j) {
218
+ const key = objKeys[j];
219
+ const value = typeof key === "object" && typeof key.value !== "undefined" ? key.value : obj[key];
220
+ if (skipNulls && value === null) {
221
+ continue;
222
+ }
223
+ const encodedKey = allowDots && encodeDotInKeys ? key.replace(/\./g, "%2E") : key;
224
+ const keyPrefix = isArray(obj) ? typeof generateArrayPrefix === "function" ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix : adjustedPrefix + (allowDots ? "." + encodedKey : "[" + encodedKey + "]");
225
+ sideChannel.set(object, step);
226
+ const valueSideChannel = /* @__PURE__ */ new WeakMap();
227
+ valueSideChannel.set(sentinel, sideChannel);
228
+ pushToArray(
229
+ values,
230
+ _stringify(
231
+ value,
232
+ keyPrefix,
233
+ generateArrayPrefix,
234
+ commaRoundTrip,
235
+ allowEmptyArrays,
236
+ strictNullHandling,
237
+ skipNulls,
238
+ encodeDotInKeys,
239
+ generateArrayPrefix === "comma" && encodeValuesOnly && isArray(obj) ? null : encoder,
240
+ filter,
241
+ sort,
242
+ allowDots,
243
+ serializeDate2,
244
+ format,
245
+ formatter,
246
+ encodeValuesOnly,
247
+ charset,
248
+ valueSideChannel
249
+ )
250
+ );
251
+ }
252
+ return values;
253
+ }, "stringify");
254
+ const normalizeStringifyOptions = /* @__PURE__ */ __name$1(function normalizeStringifyOptions2(opts) {
255
+ if (!opts) {
256
+ return defaults;
257
+ }
258
+ if (typeof opts.allowEmptyArrays !== "undefined" && typeof opts.allowEmptyArrays !== "boolean") {
259
+ throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");
260
+ }
261
+ if (typeof opts.encodeDotInKeys !== "undefined" && typeof opts.encodeDotInKeys !== "boolean") {
262
+ throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");
263
+ }
264
+ if (opts.encoder !== null && typeof opts.encoder !== "undefined" && typeof opts.encoder !== "function") {
265
+ throw new TypeError("Encoder has to be a function.");
266
+ }
267
+ const charset = opts.charset || defaults.charset;
268
+ if (typeof opts.charset !== "undefined" && opts.charset !== "utf-8" && opts.charset !== "iso-8859-1") {
269
+ throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");
270
+ }
271
+ let format = formats;
272
+ if (typeof opts.format !== "undefined") {
273
+ if (!has.call(formatters, opts.format)) {
274
+ throw new TypeError("Unknown format option provided.");
275
+ }
276
+ format = opts.format;
277
+ }
278
+ const formatter = formatters[format];
279
+ let filter = defaults.filter;
280
+ if (typeof opts.filter === "function" || isArray(opts.filter)) {
281
+ filter = opts.filter;
282
+ }
283
+ let arrayFormat;
284
+ if (opts.arrayFormat in arrayPrefixGenerators) {
285
+ arrayFormat = opts.arrayFormat;
286
+ } else if ("indices" in opts) {
287
+ arrayFormat = opts.indices ? "indices" : "repeat";
288
+ } else {
289
+ arrayFormat = defaults.arrayFormat;
290
+ }
291
+ if ("commaRoundTrip" in opts && typeof opts.commaRoundTrip !== "boolean") {
292
+ throw new TypeError("`commaRoundTrip` must be a boolean, or absent");
293
+ }
294
+ const allowDots = typeof opts.allowDots === "undefined" ? opts.encodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
295
+ return {
296
+ addQueryPrefix: typeof opts.addQueryPrefix === "boolean" ? opts.addQueryPrefix : defaults.addQueryPrefix,
297
+ allowDots,
298
+ allowEmptyArrays: typeof opts.allowEmptyArrays === "boolean" ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
299
+ arrayFormat,
300
+ charset,
301
+ charsetSentinel: typeof opts.charsetSentinel === "boolean" ? opts.charsetSentinel : defaults.charsetSentinel,
302
+ commaRoundTrip: opts.commaRoundTrip,
303
+ delimiter: typeof opts.delimiter === "undefined" ? defaults.delimiter : opts.delimiter,
304
+ encode: typeof opts.encode === "boolean" ? opts.encode : defaults.encode,
305
+ encodeDotInKeys: typeof opts.encodeDotInKeys === "boolean" ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
306
+ encoder: typeof opts.encoder === "function" ? opts.encoder : defaults.encoder,
307
+ encodeValuesOnly: typeof opts.encodeValuesOnly === "boolean" ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
308
+ filter,
309
+ format,
310
+ formatter,
311
+ serializeDate: typeof opts.serializeDate === "function" ? opts.serializeDate : defaults.serializeDate,
312
+ skipNulls: typeof opts.skipNulls === "boolean" ? opts.skipNulls : defaults.skipNulls,
313
+ sort: typeof opts.sort === "function" ? opts.sort : null,
314
+ strictNullHandling: typeof opts.strictNullHandling === "boolean" ? opts.strictNullHandling : defaults.strictNullHandling
315
+ };
316
+ }, "normalizeStringifyOptions");
317
+ function stringify(object, opts) {
318
+ let obj = object;
319
+ const options = normalizeStringifyOptions(opts);
320
+ let objKeys;
321
+ let filter;
322
+ if (typeof options.filter === "function") {
323
+ filter = options.filter;
324
+ obj = filter("", obj);
325
+ } else if (isArray(options.filter)) {
326
+ filter = options.filter;
327
+ objKeys = filter;
328
+ }
329
+ const keys = [];
330
+ if (typeof obj !== "object" || obj === null) {
331
+ return "";
332
+ }
333
+ const generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
334
+ const commaRoundTrip = generateArrayPrefix === "comma" && options.commaRoundTrip;
335
+ if (!objKeys) {
336
+ objKeys = Object.keys(obj);
337
+ }
338
+ if (options.sort) {
339
+ objKeys.sort(options.sort);
340
+ }
341
+ const sideChannel = /* @__PURE__ */ new WeakMap();
342
+ for (let i = 0; i < objKeys.length; ++i) {
343
+ const key = objKeys[i];
344
+ if (options.skipNulls && obj[key] === null) {
345
+ continue;
346
+ }
347
+ pushToArray(
348
+ keys,
349
+ _stringify(
350
+ obj[key],
351
+ key,
352
+ generateArrayPrefix,
353
+ commaRoundTrip,
354
+ options.allowEmptyArrays,
355
+ options.strictNullHandling,
356
+ options.skipNulls,
357
+ options.encodeDotInKeys,
358
+ options.encode ? options.encoder : null,
359
+ options.filter,
360
+ options.sort,
361
+ options.allowDots,
362
+ options.serializeDate,
363
+ options.format,
364
+ options.formatter,
365
+ options.encodeValuesOnly,
366
+ options.charset,
367
+ sideChannel
368
+ )
369
+ );
370
+ }
371
+ const joined = keys.join(options.delimiter);
372
+ let prefix = options.addQueryPrefix === true ? "?" : "";
373
+ if (options.charsetSentinel) {
374
+ if (options.charset === "iso-8859-1") {
375
+ prefix += "utf8=%26%2310003%3B&";
376
+ } else {
377
+ prefix += "utf8=%E2%9C%93&";
378
+ }
379
+ }
380
+ return joined.length > 0 ? prefix + joined : "";
381
+ }
382
+ __name$1(stringify, "stringify");
383
+
384
+ var __defProp = Object.defineProperty;
385
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
386
+ class Paginator extends Array {
387
+ constructor(totalNumber, perPage, currentPage, ...rows) {
388
+ super(...rows);
389
+ this.totalNumber = totalNumber;
390
+ this.perPage = perPage;
391
+ this.currentPage = currentPage;
392
+ this.totalNumber = Number(totalNumber);
393
+ this.rows = rows;
394
+ this.isEmpty = this.rows.length === 0;
395
+ }
396
+ static {
397
+ __name(this, "Paginator");
398
+ }
399
+ /**
400
+ * The first page is always 1
401
+ */
402
+ firstPage = 1;
403
+ /**
404
+ * Find if results set is empty or not
405
+ */
406
+ isEmpty;
407
+ qs = {};
408
+ rows;
409
+ url = "/";
410
+ /**
411
+ * A reference to the result rows
412
+ */
413
+ all() {
414
+ return this.rows;
415
+ }
416
+ /**
417
+ * Define base url for making the pagination links
418
+ */
419
+ baseUrl(url) {
420
+ this.url = url;
421
+ return this;
422
+ }
423
+ /**
424
+ * Returns JSON meta data
425
+ */
426
+ getMeta() {
427
+ return {
428
+ firstPage: this.firstPage,
429
+ firstPageUrl: this.getUrl(1),
430
+ lastPage: this.lastPage,
431
+ lastPageUrl: this.getUrl(this.lastPage),
432
+ nextPageUrl: this.getNextPageUrl(),
433
+ page: this.currentPage,
434
+ perPage: this.perPage,
435
+ previousPageUrl: this.getPreviousPageUrl(),
436
+ total: this.total
437
+ };
438
+ }
439
+ /**
440
+ * Returns url for the next page
441
+ */
442
+ getNextPageUrl() {
443
+ if (this.hasMorePages) {
444
+ return this.getUrl(this.currentPage + 1);
445
+ }
446
+ return null;
447
+ }
448
+ /**
449
+ * Returns URL for the previous page
450
+ */
451
+ getPreviousPageUrl() {
452
+ if (this.currentPage > 1) {
453
+ return this.getUrl(this.currentPage - 1);
454
+ }
455
+ return null;
456
+ }
457
+ /**
458
+ * Returns url for a given page. Doesn't validate the integrity of the
459
+ * page
460
+ */
461
+ getUrl(page) {
462
+ const qstring = stringify({ ...this.qs, page: page < 1 ? 1 : page });
463
+ return `${this.url}?${qstring}`;
464
+ }
465
+ /**
466
+ * Returns an array of urls under a given range
467
+ */
468
+ getUrlsForRange(start, end) {
469
+ const urls = [];
470
+ for (let index = start; index <= end; index++) {
471
+ urls.push({ isActive: index === this.currentPage, page: index, url: this.getUrl(index) });
472
+ }
473
+ return urls;
474
+ }
475
+ /**
476
+ * Define query string to be appended to the pagination links
477
+ */
478
+ queryString(values) {
479
+ this.qs = values;
480
+ return this;
481
+ }
482
+ /**
483
+ * Returns JSON representation of the paginated
484
+ * data
485
+ */
486
+ toJSON() {
487
+ return {
488
+ data: this.all(),
489
+ meta: this.getMeta()
490
+ };
491
+ }
492
+ /**
493
+ * Find if there are more pages to come
494
+ */
495
+ get hasMorePages() {
496
+ return this.lastPage > this.currentPage;
497
+ }
498
+ /**
499
+ * Find if there are enough results to be paginated or not
500
+ */
501
+ get hasPages() {
502
+ return this.lastPage !== 1;
503
+ }
504
+ /**
505
+ * Find if there are total records or not. This is not same as
506
+ * `isEmpty`.
507
+ *
508
+ * The `isEmpty` reports about the current set of results. However, `hasTotal`
509
+ * reports about the total number of records, regardless of the current.
510
+ */
511
+ get hasTotal() {
512
+ return this.total > 0;
513
+ }
514
+ /**
515
+ * The Last page number
516
+ */
517
+ get lastPage() {
518
+ return Math.max(Math.ceil(this.total / this.perPage), 1);
519
+ }
520
+ /**
521
+ * Casting `total` to a number. Later, we can think of situations
522
+ * to cast it to a bigint
523
+ */
524
+ get total() {
525
+ return Number(this.totalNumber);
526
+ }
527
+ }
528
+
529
+ module.exports = Paginator;