@react-pakistan/util-functions 1.24.5 → 1.24.7

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.
@@ -1,6 +1,5 @@
1
1
  export * from './api-methods';
2
2
  export * from './layout-direction';
3
- export * from './page-limit';
4
3
  export * from './react-pakistan';
5
4
  export * from './react-pakistan-meta';
6
5
  export * from './select-value-delimiter';
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api-methods"), exports);
18
18
  __exportStar(require("./layout-direction"), exports);
19
- __exportStar(require("./page-limit"), exports);
20
19
  __exportStar(require("./react-pakistan"), exports);
21
20
  __exportStar(require("./react-pakistan-meta"), exports);
22
21
  __exportStar(require("./select-value-delimiter"), exports);
@@ -0,0 +1 @@
1
+ export declare const calculatePages: (count: number, pageLimit: number) => number;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculatePages = void 0;
4
+ var calculatePages = function (count, pageLimit) { return Math.ceil(count / pageLimit); };
5
+ exports.calculatePages = calculatePages;
@@ -1,2 +1,6 @@
1
- import { PageLimit } from '../constants';
2
- export declare const dynamicPageLimit: (totalRecordCount: number) => PageLimit;
1
+ export type PageLimitOption = 5 | 10 | 15 | 25 | 100;
2
+ interface Return {
3
+ label: string;
4
+ }
5
+ export declare const dynamicPageLimit: (availableOptions: Array<PageLimitOption>) => Array<Return>;
6
+ export {};
@@ -1,58 +1,6 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.dynamicPageLimit = void 0;
15
- var constants_1 = require("../constants");
16
- var dynamicPageLimit = function (totalRecordCount) {
17
- var adjustedPageLimit = __assign({}, constants_1.PAGE_LIMIT);
18
- if (totalRecordCount <= 5) {
19
- adjustedPageLimit = {
20
- 5: 5,
21
- };
22
- }
23
- else if (totalRecordCount <= 10) {
24
- adjustedPageLimit = {
25
- 5: 5,
26
- 10: 10,
27
- };
28
- }
29
- else if (totalRecordCount <= 15) {
30
- adjustedPageLimit = {
31
- 5: 5,
32
- 10: 10,
33
- 15: 15,
34
- };
35
- }
36
- else if (totalRecordCount <= 25) {
37
- adjustedPageLimit = {
38
- 5: 5,
39
- 10: 10,
40
- 15: 15,
41
- 25: 25,
42
- };
43
- }
44
- else if (totalRecordCount <= 50) {
45
- adjustedPageLimit = {
46
- 5: 5,
47
- 10: 10,
48
- 15: 15,
49
- 25: 25,
50
- 50: 50,
51
- };
52
- }
53
- else if (totalRecordCount > 150) {
54
- adjustedPageLimit = __assign(__assign({}, constants_1.PAGE_LIMIT), { 150: 150 });
55
- }
56
- return adjustedPageLimit;
57
- };
4
+ var dynamicPageLimit = function (availableOptions) { return availableOptions
5
+ .map(function (txt) { return ({ label: String(txt) }); }); };
58
6
  exports.dynamicPageLimit = dynamicPageLimit;
@@ -0,0 +1,5 @@
1
+ interface Return {
2
+ label: string;
3
+ }
4
+ export declare const getAvailablePageLimits: (totalRecords: number) => Array<Return>;
5
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAvailablePageLimits = void 0;
13
+ var dynamic_page_limit_1 = require("./dynamic-page-limit");
14
+ var getAvailablePageLimits = function (totalRecords) {
15
+ var allOptions = [5, 10, 15, 25, 100];
16
+ // Get options less than or equal to totalRecords
17
+ var lowerOptions = allOptions.filter(function (opt) { return (opt < totalRecords); });
18
+ // Find the next higher option
19
+ var nextHigherOption = allOptions.find(function (opt) { return (opt >= totalRecords); });
20
+ // Combine lower options and next higher (if it exists)
21
+ var availableOptions = __spreadArray([], lowerOptions, true);
22
+ if (nextHigherOption && !availableOptions.includes(nextHigherOption)) {
23
+ availableOptions.push(nextHigherOption);
24
+ }
25
+ return (0, dynamic_page_limit_1.dynamicPageLimit)(availableOptions);
26
+ };
27
+ exports.getAvailablePageLimits = getAvailablePageLimits;
@@ -1,5 +1,6 @@
1
1
  export * from './basic-get';
2
2
  export * from './basic-post';
3
+ export * from './calculate-pages';
3
4
  export * from './camel-to-sentence-case';
4
5
  export * from './check-even-odd-length';
5
6
  export * from './countries';
@@ -16,6 +17,7 @@ export * from './generate-breadcrumb-schema';
16
17
  export * from './generate-faq-schema';
17
18
  export * from './generate-grid';
18
19
  export * from './generate-organization-schema';
20
+ export * from './get-available-page-limit';
19
21
  export * from './get-calendar-current-month';
20
22
  export * from './get-calendar-dates';
21
23
  export * from './get-calendar-next-month';
package/general/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // export * from './time-out';
18
18
  __exportStar(require("./basic-get"), exports);
19
19
  __exportStar(require("./basic-post"), exports);
20
+ __exportStar(require("./calculate-pages"), exports);
20
21
  __exportStar(require("./camel-to-sentence-case"), exports);
21
22
  __exportStar(require("./check-even-odd-length"), exports);
22
23
  __exportStar(require("./countries"), exports);
@@ -33,6 +34,7 @@ __exportStar(require("./generate-breadcrumb-schema"), exports);
33
34
  __exportStar(require("./generate-faq-schema"), exports);
34
35
  __exportStar(require("./generate-grid"), exports);
35
36
  __exportStar(require("./generate-organization-schema"), exports);
37
+ __exportStar(require("./get-available-page-limit"), exports);
36
38
  __exportStar(require("./get-calendar-current-month"), exports);
37
39
  __exportStar(require("./get-calendar-dates"), exports);
38
40
  __exportStar(require("./get-calendar-next-month"), exports);
@@ -27,7 +27,7 @@ interface Return {
27
27
  byIdLoading: boolean;
28
28
  deleteError?: Error;
29
29
  deleteFetchNow?: (url?: string, config?: FetchConfig) => void;
30
- deleteLoading?: boolean;
30
+ deleteLoading: boolean;
31
31
  listError?: Error;
32
32
  listFetchNow: () => void;
33
33
  listLoading: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.24.5",
3
+ "version": "1.24.7",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +0,0 @@
1
- export interface PageLimit {
2
- [key: string]: number;
3
- }
4
- export declare const PAGE_LIMIT: PageLimit;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PAGE_LIMIT = void 0;
4
- exports.PAGE_LIMIT = {
5
- 5: 5,
6
- 10: 10,
7
- 15: 15,
8
- 25: 25,
9
- 50: 50,
10
- 100: 100,
11
- };