@capsitech/react-utilities 0.1.10 → 0.1.12

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.
Files changed (103) hide show
  1. package/lib/Components/SuspenseRoute.js +29 -0
  2. package/lib/Components/index.js +1 -0
  3. package/lib/Hooks/index.d.ts +2 -2
  4. package/lib/Hooks/index.js +98 -0
  5. package/lib/Hooks/useInfiniteScroll.d.ts +1 -1
  6. package/lib/Hooks/useInfiniteScroll.js +22 -0
  7. package/lib/Hooks/useNetworkState.js +41 -0
  8. package/lib/Hooks/useShortcuts.js +91 -0
  9. package/lib/Utilities/ApiUtility.axios.js +326 -0
  10. package/lib/Utilities/BrowserInfo.d.ts +1 -1
  11. package/lib/Utilities/BrowserInfo.js +159 -0
  12. package/lib/Utilities/Countries.js +290 -0
  13. package/lib/Utilities/CustomEventEmitter.js +30 -0
  14. package/lib/Utilities/FastCompare.js +128 -0
  15. package/lib/Utilities/HideablePromise.js +10 -0
  16. package/lib/Utilities/LoadScripts.js +51 -0
  17. package/lib/Utilities/MTDFraudPrevention.js +157 -0
  18. package/lib/Utilities/Nationalities.js +245 -0
  19. package/lib/Utilities/RouteUtils.d.ts +1 -1
  20. package/lib/Utilities/RouteUtils.js +223 -0
  21. package/lib/Utilities/TimeZones.js +1069 -0
  22. package/lib/Utilities/Types.js +1 -0
  23. package/lib/Utilities/Utils.d.ts +1 -1
  24. package/lib/Utilities/Utils.js +331 -0
  25. package/lib/Utilities/dayjs.d.ts +11 -10
  26. package/lib/Utilities/dayjs.js +57 -0
  27. package/lib/Utilities/index.js +14 -0
  28. package/lib/index.js +3 -72
  29. package/package.json +17 -61
  30. package/lib/Components.d.ts +0 -2
  31. package/lib/Components.js +0 -5
  32. package/lib/Components.js.map +0 -1
  33. package/lib/Hooks.d.ts +0 -2
  34. package/lib/Hooks.js +0 -72
  35. package/lib/Hooks.js.map +0 -1
  36. package/lib/Utilities.d.ts +0 -2
  37. package/lib/Utilities.js +0 -54
  38. package/lib/Utilities.js.map +0 -1
  39. package/lib/index.js.map +0 -1
  40. package/lib/logo.png +0 -0
  41. package/lib/src/Components/SuspenseRoute.d.ts +0 -2
  42. package/lib/src/Components/SuspenseRoute.js +0 -22
  43. package/lib/src/Components/SuspenseRoute.js.map +0 -1
  44. package/lib/src/Components/index.d.ts +0 -2
  45. package/lib/src/Components/index.js +0 -5
  46. package/lib/src/Components/index.js.map +0 -1
  47. package/lib/src/Hooks/index.d.ts +0 -2
  48. package/lib/src/Hooks/index.js +0 -20
  49. package/lib/src/Hooks/index.js.map +0 -1
  50. package/lib/src/Hooks/useInfiniteScroll.d.ts +0 -2
  51. package/lib/src/Hooks/useInfiniteScroll.js +0 -20
  52. package/lib/src/Hooks/useInfiniteScroll.js.map +0 -1
  53. package/lib/src/Hooks/useNetworkState.d.ts +0 -2
  54. package/lib/src/Hooks/useNetworkState.js +0 -33
  55. package/lib/src/Hooks/useNetworkState.js.map +0 -1
  56. package/lib/src/Hooks/useShortcuts.d.ts +0 -2
  57. package/lib/src/Hooks/useShortcuts.js +0 -43
  58. package/lib/src/Hooks/useShortcuts.js.map +0 -1
  59. package/lib/src/Utilities/ApiUtility.axios.d.ts +0 -2
  60. package/lib/src/Utilities/ApiUtility.axios.js +0 -228
  61. package/lib/src/Utilities/ApiUtility.axios.js.map +0 -1
  62. package/lib/src/Utilities/BrowserInfo.d.ts +0 -2
  63. package/lib/src/Utilities/BrowserInfo.js +0 -51
  64. package/lib/src/Utilities/BrowserInfo.js.map +0 -1
  65. package/lib/src/Utilities/Countries.d.ts +0 -2
  66. package/lib/src/Utilities/Countries.js +0 -518
  67. package/lib/src/Utilities/Countries.js.map +0 -1
  68. package/lib/src/Utilities/CustomEventEmitter.d.ts +0 -2
  69. package/lib/src/Utilities/CustomEventEmitter.js +0 -27
  70. package/lib/src/Utilities/CustomEventEmitter.js.map +0 -1
  71. package/lib/src/Utilities/FastCompare.d.ts +0 -2
  72. package/lib/src/Utilities/FastCompare.js +0 -56
  73. package/lib/src/Utilities/FastCompare.js.map +0 -1
  74. package/lib/src/Utilities/HideablePromise.d.ts +0 -2
  75. package/lib/src/Utilities/HideablePromise.js +0 -18
  76. package/lib/src/Utilities/HideablePromise.js.map +0 -1
  77. package/lib/src/Utilities/LoadScripts.d.ts +0 -2
  78. package/lib/src/Utilities/LoadScripts.js +0 -26
  79. package/lib/src/Utilities/LoadScripts.js.map +0 -1
  80. package/lib/src/Utilities/MTDFraudPrevention.d.ts +0 -2
  81. package/lib/src/Utilities/MTDFraudPrevention.js +0 -60
  82. package/lib/src/Utilities/MTDFraudPrevention.js.map +0 -1
  83. package/lib/src/Utilities/Nationalities.d.ts +0 -2
  84. package/lib/src/Utilities/Nationalities.js +0 -250
  85. package/lib/src/Utilities/Nationalities.js.map +0 -1
  86. package/lib/src/Utilities/RouteUtils.d.ts +0 -2
  87. package/lib/src/Utilities/RouteUtils.js +0 -200
  88. package/lib/src/Utilities/RouteUtils.js.map +0 -1
  89. package/lib/src/Utilities/TimeZones.d.ts +0 -2
  90. package/lib/src/Utilities/TimeZones.js +0 -1074
  91. package/lib/src/Utilities/TimeZones.js.map +0 -1
  92. package/lib/src/Utilities/Types.d.ts +0 -1
  93. package/lib/src/Utilities/Types.js +0 -2
  94. package/lib/src/Utilities/Types.js.map +0 -1
  95. package/lib/src/Utilities/Utils.d.ts +0 -2
  96. package/lib/src/Utilities/Utils.js +0 -274
  97. package/lib/src/Utilities/Utils.js.map +0 -1
  98. package/lib/src/Utilities/dayjs.d.ts +0 -2
  99. package/lib/src/Utilities/dayjs.js +0 -42
  100. package/lib/src/Utilities/dayjs.js.map +0 -1
  101. package/lib/src/Utilities/index.d.ts +0 -2
  102. package/lib/src/Utilities/index.js +0 -54
  103. package/lib/src/Utilities/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import { default as React } from 'react';
2
+ import React from 'react';
3
3
  import { IAddress } from './Types';
4
4
  export declare const StorageMessageKey = "ao-message";
5
5
  export interface IStorageMessage extends Record<string, any> {
@@ -0,0 +1,331 @@
1
+ import React from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ import { dayjs } from '../Utilities/dayjs';
4
+ export const StorageMessageKey = 'ao-message';
5
+ class UtilsBase {
6
+ DateRegEx = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}/;
7
+ NiNoRegEx = /([ACEHJLMOPRSWXY][A-CEGHJ-NPR-TW-Z]|B[A-CEHJ-NPR-TW-Z]|G[ACEGHJ-NPR-TW-Z]|[KT][A-CEGHJ-MPR-TW-Z]|N[A-CEGHJL-NPR-SW-Z]|Z[A-CEGHJ-NPR-TW-Y])[0-9]{6}[A-D ]/;
8
+ /**
9
+ * Unique id for the tab (openned browser tab)
10
+ */
11
+ TabIdKey;
12
+ constructor() {
13
+ this.TabIdKey = Math.random().toString(36).substring(2, 8);
14
+ }
15
+ /**
16
+ * Get number from any type/value
17
+ * @param num Value to get number
18
+ */
19
+ getNumber = (num) => {
20
+ if (!num || num === '')
21
+ return 0;
22
+ if (typeof num === 'number')
23
+ return isNaN(num) ? 0 : num;
24
+ return this.getNumber(parseFloat(num.replaceAll(',', '')));
25
+ };
26
+ /**
27
+ * Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY
28
+ * @param date Date to be formatted
29
+ * @param emptyValue Value to return if date is empty or null
30
+ * @param withTime Return date with time
31
+ */
32
+ getFormattedDate = (date, emptyValue, withTime, timeZone = 'Europe/London') => {
33
+ if (!date || date === '')
34
+ return emptyValue;
35
+ const dt = typeof date === 'string' &&
36
+ /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$/.test(date)
37
+ ? dayjs(date, 'DD/MM/YYYY')
38
+ : dayjs(date);
39
+ return dt.isValid()
40
+ ? withTime
41
+ ? dt.tz(timeZone).format(`DD/MM/YYYY hh:mm A`)
42
+ : dt.format(`DD/MM/YYYY`)
43
+ : emptyValue;
44
+ };
45
+ /**
46
+ * Get formatted number
47
+ * @param number Number to format
48
+ * @param decimalPlaces Number of decimal places
49
+ * @param withComma Get number with separator
50
+ * @param useDashForZero Use dash for zero
51
+ * @param withCurrency Prepend £ before number
52
+ */
53
+ getFormattedNumber = (number, decimalPlaces = 2, withComma = true, useDashForZero = false, withCurrency = false) => {
54
+ if (isNaN(number))
55
+ number = 0;
56
+ if (useDashForZero && (!number || number === '' || number === 0 || number === '0'))
57
+ return '-';
58
+ var isNegative = false;
59
+ if (number < 0) {
60
+ isNegative = true;
61
+ number = Math.abs(number);
62
+ }
63
+ var t = parseFloat(number)
64
+ .toFixed(decimalPlaces !== null && decimalPlaces !== undefined ? decimalPlaces : 2)
65
+ .split('.');
66
+ var str = number;
67
+ if (t.length >= 1) {
68
+ str = '';
69
+ //var r = t[0].slice('');
70
+ var r = t[0].slice(0);
71
+ for (var i = r.length - 1, j = 1; i >= 0; i--, j++) {
72
+ str = r[i] + str;
73
+ if (withComma && j % 3 === 0 && i > 0)
74
+ str = ',' + str;
75
+ }
76
+ if (t.length > 1)
77
+ str += '.' + t[1];
78
+ }
79
+ return (withCurrency ? '£' : '') + (isNegative ? `(${str})` : str);
80
+ };
81
+ /**
82
+ * Get formatted number
83
+ * @param number Number to format
84
+ * @param useDashForZero Use dash for zero
85
+ */
86
+ getFormattedCurrency = (number, useDashForZero = false) => this.getFormattedNumber(number, 2, true, useDashForZero, true);
87
+ /**
88
+ * Append zero if number is less then 10
89
+ * @param num Number to check
90
+ */
91
+ appendZero = (num) => (num < 10 ? `0${num}` : num);
92
+ /**
93
+ * Get formatted time (MM:SS)
94
+ * @param seconds Seconds - to get time
95
+ * @param minutes Minutes - to get time
96
+ */
97
+ getFormattedTime = (seconds, minutes = 0) => {
98
+ const dateTime = new Date(0, 0, 0, 0, minutes, seconds, 0), dateTimeM = this.appendZero(dateTime.getMinutes()), dateTimeS = this.appendZero(dateTime.getSeconds());
99
+ return `${dateTimeM}:${dateTimeS}`;
100
+ };
101
+ /**
102
+ * Get formatted time from total seconds
103
+ * @param seconds Total seconds to calculate hours and minutes
104
+ * @param ignoreSeconds Skip seconds in output string
105
+ */
106
+ getFormattedSeconds = (seconds, ignoreSeconds) => {
107
+ if (seconds > 0) {
108
+ var hours = Math.floor(seconds / 3600);
109
+ seconds %= 3600;
110
+ var minutes = Math.floor(seconds / 60);
111
+ seconds = Math.floor(seconds % 60);
112
+ return (`${this.appendZero(hours)}:${this.appendZero(minutes)}` +
113
+ (ignoreSeconds ? '' : `:${this.appendZero(seconds)}`));
114
+ }
115
+ return '-';
116
+ };
117
+ /**
118
+ * Get a property value from local storage
119
+ * @param {string} Key name to find the value
120
+ */
121
+ getLocal = (key) => {
122
+ const data = localStorage.getItem(key);
123
+ if (data)
124
+ return JSON.parse(data);
125
+ return null;
126
+ };
127
+ /**
128
+ * Set a property with value to local storage
129
+ * @param {string} Key name to find the value
130
+ * @param {any} data Data/value to be stored
131
+ */
132
+ setLocal = (key, data) => {
133
+ localStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');
134
+ };
135
+ /**
136
+ * Remove a property with value from local storage
137
+ * @param {string} Key name to find the value
138
+ */
139
+ removeLocal = (key) => {
140
+ localStorage.removeItem(key);
141
+ };
142
+ /**
143
+ * Get a property value from session storage
144
+ * @param {string} Key name to find the value
145
+ */
146
+ getSession = (key) => {
147
+ const data = sessionStorage.getItem(key);
148
+ if (data)
149
+ return JSON.parse(data);
150
+ return null;
151
+ };
152
+ /**
153
+ * Set a property with value to session storage
154
+ * @param {string} Key name to find the value
155
+ * @param {any} data Data/value to be stored
156
+ */
157
+ setSession = (key, data) => {
158
+ sessionStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');
159
+ };
160
+ jsonReplacer = (key, value) => {
161
+ if (value === null)
162
+ return undefined;
163
+ if (value === false)
164
+ return undefined;
165
+ return value;
166
+ };
167
+ /**
168
+ * Get file size in kb/mb/gb etc.
169
+ * @param {number} size File lenth/size
170
+ */
171
+ getFileSize = (size) => {
172
+ var selectedSize = 0;
173
+ var selectedUnit = 'b';
174
+ if (size > 0) {
175
+ var units = ['tb', 'gb', 'mb', 'kb', 'b'];
176
+ for (var i = 0; i < units.length; i++) {
177
+ var unit = units[i];
178
+ var cutoff = Math.pow(1000, 4 - i) / 10;
179
+ if (size >= cutoff) {
180
+ selectedSize = size / Math.pow(1000, 4 - i);
181
+ selectedUnit = unit;
182
+ break;
183
+ }
184
+ }
185
+ selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits
186
+ }
187
+ return `${selectedSize} ${selectedUnit.toUpperCase()}`;
188
+ };
189
+ /**
190
+ * A custom hook that builds on useLocation to parse the query string for you.
191
+ */
192
+ useQuery = () => new URLSearchParams(useLocation().search);
193
+ /**
194
+ * Sum number array
195
+ * @param {number[]} arr Number array
196
+ */
197
+ sumArray = (arr) => arr.reduce((a, b) => a + b);
198
+ /**
199
+ * Get sorted array by property
200
+ * @param {any[]} arr Array of objects
201
+ * @param {string} key Property/field name to sort
202
+ * @returns {any[]}
203
+ */
204
+ sortArray(arr, key) {
205
+ return arr.sort((a, b) => {
206
+ if (a[key] < b[key]) {
207
+ return -1;
208
+ }
209
+ if (a[key] > b[key]) {
210
+ return 1;
211
+ }
212
+ return 0;
213
+ });
214
+ }
215
+ /**
216
+ * Replace an item in array with index
217
+ * @param arr Array of objects
218
+ * @param index Index where to replace the item
219
+ * @param newValue New item to be replaced with
220
+ * @returns Array of objects
221
+ */
222
+ replaceItemAtIndex(arr, index, newValue) {
223
+ return [...arr.slice(0, index), newValue, ...arr.slice(index + 1)];
224
+ }
225
+ /**
226
+ * Remove an item from array with index
227
+ * @param arr Array of objects
228
+ * @param index Index which item to be removed
229
+ * @returns Array of object
230
+ */
231
+ removeItemAtIndex(arr, index) {
232
+ return [...arr.slice(0, index), ...arr.slice(index + 1)];
233
+ }
234
+ /**
235
+ * Capitalize the words of a string
236
+ * @param {string} value String or value to be capitalized
237
+ * @param {boolean} lower To lowercase other chars
238
+ */
239
+ capitalize = (value, lower = false) => value
240
+ ? (lower ? value.toLowerCase() : value).replace(/(?:^|\s)\S/g, (a) => a.toUpperCase())
241
+ : '';
242
+ /**
243
+ * Validate current MongoDB ObjectId
244
+ * @param id Id to check for ObjectId
245
+ */
246
+ isValidObjectId = (id) => (id && /^[a-fA-F0-9]{24}$/i.test(id) ? true : false);
247
+ /**
248
+ * Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs
249
+ * @param {string} Key name to find the value
250
+ * @param {any} data Data/value to be stored
251
+ */
252
+ sendMessageToAllTabs = (type, data) => {
253
+ const message = {
254
+ type,
255
+ t: this.TabIdKey,
256
+ domain: window.location.hostname,
257
+ ...data,
258
+ };
259
+ localStorage.setItem(StorageMessageKey, JSON.stringify(message));
260
+ localStorage.removeItem(StorageMessageKey);
261
+ };
262
+ /**
263
+ * Check and get new event message, from event object
264
+ * @param {StorageEvent} event Event object received in storage event listener
265
+ */
266
+ getStorageMessage = (event) => {
267
+ if (event.key === StorageMessageKey && event.newValue) {
268
+ const message = JSON.parse(event.newValue);
269
+ if (message && message.t !== Utils.TabIdKey && message.domain === window.location.hostname) {
270
+ return message;
271
+ }
272
+ }
273
+ return null;
274
+ };
275
+ /**
276
+ * Assign value to an object by key/path name
277
+ * @param obj Object to assign value to
278
+ * @param path key full path
279
+ * @param val value to be assigned
280
+ * @param separator Path separator
281
+ */
282
+ setNestedKeyValue = (obj, path, val, separator = '.') => {
283
+ const keys = path.split(separator);
284
+ const lastKey = keys.pop();
285
+ const lastObj = keys.reduce((obj, key) => (obj[key] = obj[key] || {}), obj);
286
+ lastObj[lastKey] = val;
287
+ };
288
+ /**
289
+ * Get comma separated address string
290
+ * @param address address object to be converted
291
+ */
292
+ getAddressString = (address, emptyString = '') => {
293
+ if (address) {
294
+ return ([
295
+ address.building,
296
+ address.street,
297
+ address.city,
298
+ address.county,
299
+ address.postcode,
300
+ address.country,
301
+ ]
302
+ .filter((v) => v && v.length > 0)
303
+ .join(', ') || emptyString);
304
+ }
305
+ return emptyString;
306
+ };
307
+ /**
308
+ * Get new random UUID
309
+ * @returns {string}
310
+ */
311
+ uuid = () => {
312
+ let u = '', m = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', i = 0, rb = (Math.random() * 0xffffffff) | 0;
313
+ while (i++ < 36) {
314
+ var c = m[i - 1], r = rb & 0xf, v = c == 'x' ? r : (r & 0x3) | 0x8;
315
+ u += c == '-' || c == '4' ? c : v.toString(16);
316
+ rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;
317
+ }
318
+ return u;
319
+ };
320
+ }
321
+ export const Utils = new UtilsBase();
322
+ export function useIsMountedRef() {
323
+ const isMountedRef = React.useRef(null);
324
+ React.useEffect(() => {
325
+ isMountedRef.current = true;
326
+ return () => {
327
+ isMountedRef.current = false;
328
+ };
329
+ });
330
+ return isMountedRef;
331
+ }
@@ -1,13 +1,14 @@
1
- import { default as dayjsBase } from 'dayjs';
2
- import { default as AdvancedFormat } from 'dayjs/plugin/advancedFormat';
3
- import { default as CustomParseFormat } from 'dayjs/plugin/customParseFormat';
4
- import { default as Duration } from 'dayjs/plugin/duration';
5
- import { default as IsSameOrAfter } from 'dayjs/plugin/isSameOrAfter';
6
- import { default as IsSameOrBefore } from 'dayjs/plugin/isSameOrBefore';
7
- import { default as RelativeTime } from 'dayjs/plugin/relativeTime';
8
- import { default as tz } from 'dayjs/plugin/timezone';
9
- import { default as utc } from 'dayjs/plugin/utc';
10
- import { default as Weekday } from 'dayjs/plugin/weekday';
1
+ import dayjsBase from 'dayjs';
2
+ import 'dayjs/locale/en-gb';
3
+ import AdvancedFormat from 'dayjs/plugin/advancedFormat';
4
+ import CustomParseFormat from 'dayjs/plugin/customParseFormat';
5
+ import Duration from 'dayjs/plugin/duration';
6
+ import IsSameOrAfter from 'dayjs/plugin/isSameOrAfter';
7
+ import IsSameOrBefore from 'dayjs/plugin/isSameOrBefore';
8
+ import RelativeTime from 'dayjs/plugin/relativeTime';
9
+ import tz from 'dayjs/plugin/timezone';
10
+ import utc from 'dayjs/plugin/utc';
11
+ import Weekday from 'dayjs/plugin/weekday';
11
12
  declare module 'dayjs' {
12
13
  interface Dayjs {
13
14
  addWorkdays(amount: number): dayjsBase.Dayjs;
@@ -0,0 +1,57 @@
1
+ import dayjsBase from 'dayjs';
2
+ import 'dayjs/locale/en-gb';
3
+ import AdvancedFormat from 'dayjs/plugin/advancedFormat';
4
+ import CustomParseFormat from 'dayjs/plugin/customParseFormat';
5
+ import Duration from 'dayjs/plugin/duration';
6
+ import IsSameOrAfter from 'dayjs/plugin/isSameOrAfter';
7
+ import IsSameOrBefore from 'dayjs/plugin/isSameOrBefore';
8
+ import RelativeTime from 'dayjs/plugin/relativeTime';
9
+ import tz from 'dayjs/plugin/timezone';
10
+ import utc from 'dayjs/plugin/utc';
11
+ import Weekday from 'dayjs/plugin/weekday';
12
+ dayjsBase.locale('en-gb');
13
+ dayjsBase.extend(AdvancedFormat);
14
+ dayjsBase.extend(CustomParseFormat);
15
+ dayjsBase.extend(Weekday);
16
+ dayjsBase.extend(IsSameOrAfter);
17
+ dayjsBase.extend(IsSameOrBefore);
18
+ dayjsBase.extend(RelativeTime);
19
+ dayjsBase.extend(utc);
20
+ dayjsBase.extend(tz);
21
+ dayjsBase.extend(Duration);
22
+ const addWorkdays = (option, c) => {
23
+ function determineSign(x) {
24
+ x = +x;
25
+ return x > 0 ? 1 : -1;
26
+ }
27
+ c.prototype.addWorkdays = function (amount) {
28
+ if (amount === 0 || isNaN(amount)) {
29
+ return this;
30
+ }
31
+ var sign = determineSign(amount);
32
+ var day = this.day();
33
+ var absIncrement = Math.abs(amount);
34
+ var days = 0;
35
+ if (day === 0 && sign === -1) {
36
+ days = 1;
37
+ }
38
+ else if (day === 6 && sign === 1) {
39
+ days = 1;
40
+ }
41
+ // Add padding for weekends.
42
+ var paddedAbsIncrement = absIncrement;
43
+ if (day !== 0 && day !== 6 && sign > 0) {
44
+ paddedAbsIncrement += day;
45
+ }
46
+ else if (day !== 0 && day !== 6 && sign < 0) {
47
+ paddedAbsIncrement += 6 - day;
48
+ }
49
+ var weekendsInbetween = Math.max(Math.floor(paddedAbsIncrement / 5) - 1, 0) + (paddedAbsIncrement > 5 && paddedAbsIncrement % 5 > 0 ? 1 : 0);
50
+ // Add the increment and number of weekends.
51
+ days += absIncrement + weekendsInbetween * 2;
52
+ return this.add(sign * days, 'day');
53
+ };
54
+ };
55
+ dayjsBase.extend(addWorkdays);
56
+ // Export the customized dayjs instance
57
+ export const dayjs = dayjsBase;
@@ -0,0 +1,14 @@
1
+ export * from './ApiUtility.axios';
2
+ export * from './BrowserInfo';
3
+ export * from './Countries';
4
+ export * from './CustomEventEmitter';
5
+ export * from './dayjs';
6
+ export * from './FastCompare';
7
+ export * from './HideablePromise';
8
+ export * from './LoadScripts';
9
+ export * from './MTDFraudPrevention';
10
+ export * from './Nationalities';
11
+ export * from './RouteUtils';
12
+ export * from './TimeZones';
13
+ export * from './Types';
14
+ export * from './Utils';
package/lib/index.js CHANGED
@@ -1,72 +1,3 @@
1
- import { SuspenseRoute as o } from "./src/Components/SuspenseRoute.js";
2
- import { useCallbackRef as i, useFirstRenderState as s, useInterval as n, useLatestRef as a, useTimeout as p, useUpdateEffect as u } from "./Hooks.js";
3
- import { ApiUtility as m, FileDownloadStatus as f, HttpMethods as l } from "./src/Utilities/ApiUtility.axios.js";
4
- import { getBrowserDoNotTrackStatus as d, getBrowserPluginsAsString as x, getDeviceLocalIPAsString as c, getScreenColourDepth as v, getScreenHeight as w, getScreenScalingFactor as h, getScreenWidth as C, getTimezone as D, getUserAgent as y, getWindowHeight as A, getWindowWidth as P, resetDeviceIpString as H, resetDeviceIpTimeStamp as I } from "./src/Utilities/BrowserInfo.js";
5
- import { AllCountries as R, getCountries as T, getCountryByPhoneNumber as E, getCountryOptions as F } from "./src/Utilities/Countries.js";
6
- import { CustomEventEmitter as b } from "./src/Utilities/CustomEventEmitter.js";
7
- import { dayjs as W } from "./src/Utilities/dayjs.js";
8
- import { fastCompare as L } from "./src/Utilities/FastCompare.js";
9
- import { HideablePromise as O } from "./src/Utilities/HideablePromise.js";
10
- import { LoadScript as j } from "./src/Utilities/LoadScripts.js";
11
- import { fraudPreventionHeadersEnum as K, getFraudPreventionHeaders as q, getScreenDetails as G, windowDetails as J } from "./src/Utilities/MTDFraudPrevention.js";
12
- import { AllNationalities as V, getNationalityOptions as X } from "./src/Utilities/Nationalities.js";
13
- import { FeatureStatus as _, RouteUtils as $ } from "./src/Utilities/RouteUtils.js";
14
- import { AllTimeZones as te, getTimeZoneOptions as oe } from "./src/Utilities/TimeZones.js";
15
- import { StorageMessageKey as ie, Utils as se, useIsMountedRef as ne } from "./src/Utilities/Utils.js";
16
- import { useInfiniteScroll as pe } from "./src/Hooks/useInfiniteScroll.js";
17
- import { isBrowser as ge, isNavigator as me, useNetworkState as fe } from "./src/Hooks/useNetworkState.js";
18
- import { disabledEventPropagation as Se, useShortcuts as de } from "./src/Hooks/useShortcuts.js";
19
- export {
20
- R as AllCountries,
21
- V as AllNationalities,
22
- te as AllTimeZones,
23
- m as ApiUtility,
24
- b as CustomEventEmitter,
25
- _ as FeatureStatus,
26
- f as FileDownloadStatus,
27
- O as HideablePromise,
28
- l as HttpMethods,
29
- j as LoadScript,
30
- $ as RouteUtils,
31
- ie as StorageMessageKey,
32
- o as SuspenseRoute,
33
- se as Utils,
34
- W as dayjs,
35
- Se as disabledEventPropagation,
36
- L as fastCompare,
37
- K as fraudPreventionHeadersEnum,
38
- d as getBrowserDoNotTrackStatus,
39
- x as getBrowserPluginsAsString,
40
- T as getCountries,
41
- E as getCountryByPhoneNumber,
42
- F as getCountryOptions,
43
- c as getDeviceLocalIPAsString,
44
- q as getFraudPreventionHeaders,
45
- X as getNationalityOptions,
46
- v as getScreenColourDepth,
47
- G as getScreenDetails,
48
- w as getScreenHeight,
49
- h as getScreenScalingFactor,
50
- C as getScreenWidth,
51
- oe as getTimeZoneOptions,
52
- D as getTimezone,
53
- y as getUserAgent,
54
- A as getWindowHeight,
55
- P as getWindowWidth,
56
- ge as isBrowser,
57
- me as isNavigator,
58
- H as resetDeviceIpString,
59
- I as resetDeviceIpTimeStamp,
60
- i as useCallbackRef,
61
- s as useFirstRenderState,
62
- pe as useInfiniteScroll,
63
- n as useInterval,
64
- ne as useIsMountedRef,
65
- a as useLatestRef,
66
- fe as useNetworkState,
67
- de as useShortcuts,
68
- p as useTimeout,
69
- u as useUpdateEffect,
70
- J as windowDetails
71
- };
72
- //# sourceMappingURL=index.js.map
1
+ export * from './Components';
2
+ export * from './Hooks';
3
+ export * from './Utilities';
package/package.json CHANGED
@@ -1,52 +1,11 @@
1
1
  {
2
2
  "name": "@capsitech/react-utilities",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "A set of javascript utility methods",
5
- "main": "lib/index.cjs",
6
- "module": "lib/index.js",
5
+ "main": "lib/index.js",
6
+ "jsnext:main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/index.d.ts",
11
- "import": "./lib/index.js"
12
- },
13
- "./Components": {
14
- "types": "./lib/Components.d.ts",
15
- "import": "./lib/Components.js"
16
- },
17
- "./Components/*": {
18
- "types": "./lib/Components/*.d.ts",
19
- "import": "./lib/src/Components/*.js"
20
- },
21
- "./Hooks": {
22
- "types": "./lib/Hooks.d.ts",
23
- "import": "./lib/Hooks.js"
24
- },
25
- "./Hooks/*": {
26
- "types": "./lib/Hooks/*.d.ts",
27
- "import": "./lib/src/Hooks/*.js"
28
- },
29
- "./Utilities": {
30
- "types": "./lib/Utilities.d.ts",
31
- "import": "./lib/Utilities.js"
32
- },
33
- "./Utilities/*": {
34
- "types": "./lib/Utilities/*.d.ts",
35
- "import": "./lib/src/Utilities/*.js"
36
- },
37
- "./lib/Components/*": {
38
- "types": "./lib/Components/*.d.ts",
39
- "import": "./lib/src/Components/*.js"
40
- },
41
- "./lib/Hooks/*": {
42
- "types": "./lib/Hooks/*.d.ts",
43
- "import": "./lib/src/Hooks/*.js"
44
- },
45
- "./lib/Utilities/*": {
46
- "types": "./lib/Utilities/*.d.ts",
47
- "import": "./lib/src/Utilities/*.js"
48
- }
49
- },
8
+ "module": "lib/index.js",
50
9
  "files": [
51
10
  "lib",
52
11
  "README.md",
@@ -72,44 +31,41 @@
72
31
  },
73
32
  "scripts": {
74
33
  "clean": "rimraf lib",
75
- "build": "yarn clean && vite build",
34
+ "build": "yarn clean && tsc --project ./tsconfig.json --module es2015 --outDir ./lib -d",
76
35
  "build:publish": "yarn && npm version patch && yarn build && npm publish",
77
36
  "start": "storybook dev -p 6006"
78
37
  },
79
38
  "dependencies": {
80
- "dayjs": "^1.11.13",
39
+ "dayjs": "^1.11.19",
81
40
  "lodash": "^4.17.21"
82
41
  },
83
42
  "peerDependencies": {
84
- "axios": "^1.11.0",
43
+ "axios": "^1.13.2",
85
44
  "file-saver": "^2.0.5",
86
45
  "qs": "^6.14.0",
87
46
  "react": ">=18",
88
- "react-dom": ">=18",
89
- "react-router-dom": "^7.8.1"
47
+ "react-dom": ">=18"
90
48
  },
91
49
  "devDependencies": {
92
- "@storybook/addon-docs": "^9.1.2",
93
- "@storybook/addon-webpack5-compiler-babel": "^3.0.6",
94
- "@storybook/react-webpack5": "^9.1.2",
50
+ "@babel/preset-env": "7.28.5",
51
+ "@babel/preset-react": "7.28.5",
52
+ "@babel/preset-typescript": "7.28.5",
53
+ "@storybook/addon-docs": "^10.1.11",
54
+ "@storybook/addon-webpack5-compiler-babel": "^4.0.0",
55
+ "@storybook/react-webpack5": "^10.1.11",
95
56
  "@types/file-saver": "^2.0.7",
96
- "@types/glob": "^9.0.0",
97
57
  "@types/lodash": "4.17.20",
98
58
  "@types/qs": "^6",
99
59
  "@types/react": "^18.3.12",
100
- "@vitejs/plugin-react": "^5.0.2",
101
60
  "axios": "^1.11.0",
102
61
  "file-saver": "^2.0.5",
103
- "globe": "0.3.1",
104
62
  "qs": "^6.14.0",
105
63
  "react": "^18.3.1",
106
64
  "react-dom": "^18.3.1",
107
65
  "react-router-dom": "^7.8.1",
108
66
  "rimraf": "6.0.1",
109
- "storybook": "^9.1.2",
110
- "typescript": "5.8.3",
111
- "vite": "^7.1.4",
112
- "vite-plugin-dts": "^4.5.4"
67
+ "storybook": "^10.1.11",
68
+ "typescript": "5.8.3"
113
69
  },
114
70
  "browserslist": {
115
71
  "production": [
@@ -123,5 +79,5 @@
123
79
  "last 1 safari version"
124
80
  ]
125
81
  },
126
- "packageManager": "yarn@4.5.1"
82
+ "packageManager": "yarn@4.11.0"
127
83
  }
@@ -1,2 +0,0 @@
1
- export * from './Components/index'
2
- export {}
package/lib/Components.js DELETED
@@ -1,5 +0,0 @@
1
- import { SuspenseRoute as p } from "./src/Components/SuspenseRoute.js";
2
- export {
3
- p as SuspenseRoute
4
- };
5
- //# sourceMappingURL=Components.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Components.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/lib/Hooks.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './Hooks/index'
2
- export {}