@capsitech/react-utilities 0.1.9 → 0.1.10

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,160 +1,235 @@
1
- import p from "react";
2
- import { useLocation as h } from "react-router-dom";
3
- import { d as x } from "../../dayjs-aKjfjjRl.mjs";
4
- const g = "ao-message";
5
- class m {
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;
1
+ var m = Object.defineProperty;
2
+ var S = (i, e, t) => e in i ? m(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var o = (i, e, t) => S(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import x from "react";
5
+ import { useLocation as d } from "react-router-dom";
6
+ import { dayjs as h } from "./dayjs.js";
7
+ const c = "ao-message";
8
+ class M {
12
9
  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 = (e) => !e || e === "" ? 0 : typeof e == "number" ? isNaN(e) ? 0 : e : this.getNumber(parseFloat(e.replaceAll(",", "")));
20
- /**
21
- * Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY
22
- * @param date Date to be formatted
23
- * @param emptyValue Value to return if date is empty or null
24
- * @param withTime Return date with time
25
- */
26
- getFormattedDate = (e, t, r, a = "Europe/London") => {
27
- if (!e || e === "") return t;
28
- const o = typeof e == "string" && /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$/.test(
29
- e
30
- ) ? x(e, "DD/MM/YYYY") : x(e);
31
- return o.isValid() ? r ? o.tz(a).format("DD/MM/YYYY hh:mm A") : o.format("DD/MM/YYYY") : t;
32
- };
33
- /**
34
- * Get formatted number
35
- * @param number Number to format
36
- * @param decimalPlaces Number of decimal places
37
- * @param withComma Get number with separator
38
- * @param useDashForZero Use dash for zero
39
- * @param withCurrency Prepend £ before number
40
- */
41
- getFormattedNumber = (e, t = 2, r = !0, a = !1, o = !1) => {
42
- if (isNaN(e) && (e = 0), a && (!e || e === "" || e === 0 || e === "0")) return "-";
43
- var i = !1;
44
- e < 0 && (i = !0, e = Math.abs(e));
45
- var n = parseFloat(e).toFixed(t ?? 2).split("."), s = e;
46
- if (n.length >= 1) {
47
- s = "";
48
- for (var l = n[0].slice(0), f = l.length - 1, c = 1; f >= 0; f--, c++)
49
- s = l[f] + s, r && c % 3 === 0 && f > 0 && (s = "," + s);
50
- n.length > 1 && (s += "." + n[1]);
51
- }
52
- return (o ? "£" : "") + (i ? `(${s})` : s);
53
- };
54
- /**
55
- * Get formatted number
56
- * @param number Number to format
57
- * @param useDashForZero Use dash for zero
58
- */
59
- getFormattedCurrency = (e, t = !1) => this.getFormattedNumber(e, 2, !0, t, !0);
60
- /**
61
- * Append zero if number is less then 10
62
- * @param num Number to check
63
- */
64
- appendZero = (e) => e < 10 ? `0${e}` : e;
65
- /**
66
- * Get formatted time (MM:SS)
67
- * @param seconds Seconds - to get time
68
- * @param minutes Minutes - to get time
69
- */
70
- getFormattedTime = (e, t = 0) => {
71
- const r = new Date(0, 0, 0, 0, t, e, 0), a = this.appendZero(r.getMinutes()), o = this.appendZero(r.getSeconds());
72
- return `${a}:${o}`;
73
- };
74
- /**
75
- * Get formatted time from total seconds
76
- * @param seconds Total seconds to calculate hours and minutes
77
- * @param ignoreSeconds Skip seconds in output string
78
- */
79
- getFormattedSeconds = (e, t) => {
80
- if (e > 0) {
81
- var r = Math.floor(e / 3600);
82
- e %= 3600;
83
- var a = Math.floor(e / 60);
84
- return e = Math.floor(e % 60), `${this.appendZero(r)}:${this.appendZero(a)}` + (t ? "" : `:${this.appendZero(e)}`);
85
- }
86
- return "-";
87
- };
88
- /**
89
- * Get a property value from local storage
90
- * @param {string} Key name to find the value
91
- */
92
- getLocal = (e) => {
93
- const t = localStorage.getItem(e);
94
- return t ? JSON.parse(t) : null;
95
- };
96
- /**
97
- * Set a property with value to local storage
98
- * @param {string} Key name to find the value
99
- * @param {any} data Data/value to be stored
100
- */
101
- setLocal = (e, t) => {
102
- localStorage.setItem(e, t ? JSON.stringify(t, this.jsonReplacer) : "");
103
- };
104
- /**
105
- * Remove a property with value from local storage
106
- * @param {string} Key name to find the value
107
- */
108
- removeLocal = (e) => {
109
- localStorage.removeItem(e);
110
- };
111
- /**
112
- * Get a property value from session storage
113
- * @param {string} Key name to find the value
114
- */
115
- getSession = (e) => {
116
- const t = sessionStorage.getItem(e);
117
- return t ? JSON.parse(t) : null;
118
- };
119
- /**
120
- * Set a property with value to session storage
121
- * @param {string} Key name to find the value
122
- * @param {any} data Data/value to be stored
123
- */
124
- setSession = (e, t) => {
125
- sessionStorage.setItem(e, t ? JSON.stringify(t, this.jsonReplacer) : "");
126
- };
127
- jsonReplacer = (e, t) => {
128
- if (t !== null && t !== !1)
129
- return t;
130
- };
131
- /**
132
- * Get file size in kb/mb/gb etc.
133
- * @param {number} size File lenth/size
134
- */
135
- getFileSize = (e) => {
136
- var t = 0, r = "b";
137
- if (e > 0) {
138
- for (var a = ["tb", "gb", "mb", "kb", "b"], o = 0; o < a.length; o++) {
139
- var i = a[o], n = Math.pow(1e3, 4 - o) / 10;
140
- if (e >= n) {
141
- t = e / Math.pow(1e3, 4 - o), r = i;
142
- break;
10
+ o(this, "DateRegEx", /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}/);
11
+ o(this, "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 ]/);
12
+ /**
13
+ * Unique id for the tab (openned browser tab)
14
+ */
15
+ o(this, "TabIdKey");
16
+ /**
17
+ * Get number from any type/value
18
+ * @param num Value to get number
19
+ */
20
+ o(this, "getNumber", (e) => !e || e === "" ? 0 : typeof e == "number" ? isNaN(e) ? 0 : e : this.getNumber(parseFloat(e.replaceAll(",", ""))));
21
+ /**
22
+ * Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY
23
+ * @param date Date to be formatted
24
+ * @param emptyValue Value to return if date is empty or null
25
+ * @param withTime Return date with time
26
+ */
27
+ o(this, "getFormattedDate", (e, t, r, s = "Europe/London") => {
28
+ if (!e || e === "") return t;
29
+ const a = typeof e == "string" && /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$/.test(
30
+ e
31
+ ) ? h(e, "DD/MM/YYYY") : h(e);
32
+ return a.isValid() ? r ? a.tz(s).format("DD/MM/YYYY hh:mm A") : a.format("DD/MM/YYYY") : t;
33
+ });
34
+ /**
35
+ * Get formatted number
36
+ * @param number Number to format
37
+ * @param decimalPlaces Number of decimal places
38
+ * @param withComma Get number with separator
39
+ * @param useDashForZero Use dash for zero
40
+ * @param withCurrency Prepend £ before number
41
+ */
42
+ o(this, "getFormattedNumber", (e, t = 2, r = !0, s = !1, a = !1) => {
43
+ if (isNaN(e) && (e = 0), s && (!e || e === "" || e === 0 || e === "0")) return "-";
44
+ var u = !1;
45
+ e < 0 && (u = !0, e = Math.abs(e));
46
+ var l = parseFloat(e).toFixed(t != null ? t : 2).split("."), n = e;
47
+ if (l.length >= 1) {
48
+ n = "";
49
+ for (var f = l[0].slice(0), g = f.length - 1, p = 1; g >= 0; g--, p++)
50
+ n = f[g] + n, r && p % 3 === 0 && g > 0 && (n = "," + n);
51
+ l.length > 1 && (n += "." + l[1]);
52
+ }
53
+ return (a ? "£" : "") + (u ? `(${n})` : n);
54
+ });
55
+ /**
56
+ * Get formatted number
57
+ * @param number Number to format
58
+ * @param useDashForZero Use dash for zero
59
+ */
60
+ o(this, "getFormattedCurrency", (e, t = !1) => this.getFormattedNumber(e, 2, !0, t, !0));
61
+ /**
62
+ * Append zero if number is less then 10
63
+ * @param num Number to check
64
+ */
65
+ o(this, "appendZero", (e) => e < 10 ? `0${e}` : e);
66
+ /**
67
+ * Get formatted time (MM:SS)
68
+ * @param seconds Seconds - to get time
69
+ * @param minutes Minutes - to get time
70
+ */
71
+ o(this, "getFormattedTime", (e, t = 0) => {
72
+ const r = new Date(0, 0, 0, 0, t, e, 0), s = this.appendZero(r.getMinutes()), a = this.appendZero(r.getSeconds());
73
+ return `${s}:${a}`;
74
+ });
75
+ /**
76
+ * Get formatted time from total seconds
77
+ * @param seconds Total seconds to calculate hours and minutes
78
+ * @param ignoreSeconds Skip seconds in output string
79
+ */
80
+ o(this, "getFormattedSeconds", (e, t) => {
81
+ if (e > 0) {
82
+ var r = Math.floor(e / 3600);
83
+ e %= 3600;
84
+ var s = Math.floor(e / 60);
85
+ return e = Math.floor(e % 60), `${this.appendZero(r)}:${this.appendZero(s)}` + (t ? "" : `:${this.appendZero(e)}`);
86
+ }
87
+ return "-";
88
+ });
89
+ /**
90
+ * Get a property value from local storage
91
+ * @param {string} Key name to find the value
92
+ */
93
+ o(this, "getLocal", (e) => {
94
+ const t = localStorage.getItem(e);
95
+ return t ? JSON.parse(t) : null;
96
+ });
97
+ /**
98
+ * Set a property with value to local storage
99
+ * @param {string} Key name to find the value
100
+ * @param {any} data Data/value to be stored
101
+ */
102
+ o(this, "setLocal", (e, t) => {
103
+ localStorage.setItem(e, t ? JSON.stringify(t, this.jsonReplacer) : "");
104
+ });
105
+ /**
106
+ * Remove a property with value from local storage
107
+ * @param {string} Key name to find the value
108
+ */
109
+ o(this, "removeLocal", (e) => {
110
+ localStorage.removeItem(e);
111
+ });
112
+ /**
113
+ * Get a property value from session storage
114
+ * @param {string} Key name to find the value
115
+ */
116
+ o(this, "getSession", (e) => {
117
+ const t = sessionStorage.getItem(e);
118
+ return t ? JSON.parse(t) : null;
119
+ });
120
+ /**
121
+ * Set a property with value to session storage
122
+ * @param {string} Key name to find the value
123
+ * @param {any} data Data/value to be stored
124
+ */
125
+ o(this, "setSession", (e, t) => {
126
+ sessionStorage.setItem(e, t ? JSON.stringify(t, this.jsonReplacer) : "");
127
+ });
128
+ o(this, "jsonReplacer", (e, t) => {
129
+ if (t !== null && t !== !1)
130
+ return t;
131
+ });
132
+ /**
133
+ * Get file size in kb/mb/gb etc.
134
+ * @param {number} size File lenth/size
135
+ */
136
+ o(this, "getFileSize", (e) => {
137
+ var t = 0, r = "b";
138
+ if (e > 0) {
139
+ for (var s = ["tb", "gb", "mb", "kb", "b"], a = 0; a < s.length; a++) {
140
+ var u = s[a], l = Math.pow(1e3, 4 - a) / 10;
141
+ if (e >= l) {
142
+ t = e / Math.pow(1e3, 4 - a), r = u;
143
+ break;
144
+ }
143
145
  }
146
+ t = Math.round(10 * t) / 10;
144
147
  }
145
- t = Math.round(10 * t) / 10;
146
- }
147
- return `${t} ${r.toUpperCase()}`;
148
- };
149
- /**
150
- * A custom hook that builds on useLocation to parse the query string for you.
151
- */
152
- useQuery = () => new URLSearchParams(h().search);
153
- /**
154
- * Sum number array
155
- * @param {number[]} arr Number array
156
- */
157
- sumArray = (e) => e.reduce((t, r) => t + r);
148
+ return `${t} ${r.toUpperCase()}`;
149
+ });
150
+ /**
151
+ * A custom hook that builds on useLocation to parse the query string for you.
152
+ */
153
+ o(this, "useQuery", () => new URLSearchParams(d().search));
154
+ /**
155
+ * Sum number array
156
+ * @param {number[]} arr Number array
157
+ */
158
+ o(this, "sumArray", (e) => e.reduce((t, r) => t + r));
159
+ /**
160
+ * Capitalize the words of a string
161
+ * @param {string} value String or value to be capitalized
162
+ * @param {boolean} lower To lowercase other chars
163
+ */
164
+ o(this, "capitalize", (e, t = !1) => e ? (t ? e.toLowerCase() : e).replace(/(?:^|\s)\S/g, (r) => r.toUpperCase()) : "");
165
+ /**
166
+ * Validate current MongoDB ObjectId
167
+ * @param id Id to check for ObjectId
168
+ */
169
+ o(this, "isValidObjectId", (e) => !!(e && /^[a-fA-F0-9]{24}$/i.test(e)));
170
+ /**
171
+ * Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs
172
+ * @param {string} Key name to find the value
173
+ * @param {any} data Data/value to be stored
174
+ */
175
+ o(this, "sendMessageToAllTabs", (e, t) => {
176
+ const r = {
177
+ type: e,
178
+ t: this.TabIdKey,
179
+ domain: window.location.hostname,
180
+ ...t
181
+ };
182
+ localStorage.setItem(c, JSON.stringify(r)), localStorage.removeItem(c);
183
+ });
184
+ /**
185
+ * Check and get new event message, from event object
186
+ * @param {StorageEvent} event Event object received in storage event listener
187
+ */
188
+ o(this, "getStorageMessage", (e) => {
189
+ if (e.key === c && e.newValue) {
190
+ const t = JSON.parse(e.newValue);
191
+ if (t && t.t !== N.TabIdKey && t.domain === window.location.hostname)
192
+ return t;
193
+ }
194
+ return null;
195
+ });
196
+ /**
197
+ * Assign value to an object by key/path name
198
+ * @param obj Object to assign value to
199
+ * @param path key full path
200
+ * @param val value to be assigned
201
+ * @param separator Path separator
202
+ */
203
+ o(this, "setNestedKeyValue", (e, t, r, s = ".") => {
204
+ const a = t.split(s), u = a.pop(), l = a.reduce((n, f) => n[f] = n[f] || {}, e);
205
+ l[u] = r;
206
+ });
207
+ /**
208
+ * Get comma separated address string
209
+ * @param address address object to be converted
210
+ */
211
+ o(this, "getAddressString", (e, t = "") => e && [
212
+ e.building,
213
+ e.street,
214
+ e.city,
215
+ e.county,
216
+ e.postcode,
217
+ e.country
218
+ ].filter((r) => r && r.length > 0).join(", ") || t);
219
+ /**
220
+ * Get new random UUID
221
+ * @returns {string}
222
+ */
223
+ o(this, "uuid", () => {
224
+ let e = "", t = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", r = 0, s = Math.random() * 4294967295 | 0;
225
+ for (; r++ < 36; ) {
226
+ var a = t[r - 1], u = s & 15, l = a == "x" ? u : u & 3 | 8;
227
+ e += a == "-" || a == "4" ? a : l.toString(16), s = r % 8 == 0 ? Math.random() * 4294967295 | 0 : s >> 4;
228
+ }
229
+ return e;
230
+ });
231
+ this.TabIdKey = Math.random().toString(36).substring(2, 8);
232
+ }
158
233
  /**
159
234
  * Get sorted array by property
160
235
  * @param {any[]} arr Array of objects
@@ -162,7 +237,7 @@ class m {
162
237
  * @returns {any[]}
163
238
  */
164
239
  sortArray(e, t) {
165
- return e.sort((r, a) => r[t] < a[t] ? -1 : r[t] > a[t] ? 1 : 0);
240
+ return e.sort((r, s) => r[t] < s[t] ? -1 : r[t] > s[t] ? 1 : 0);
166
241
  }
167
242
  /**
168
243
  * Replace an item in array with index
@@ -183,89 +258,17 @@ class m {
183
258
  removeItemAtIndex(e, t) {
184
259
  return [...e.slice(0, t), ...e.slice(t + 1)];
185
260
  }
186
- /**
187
- * Capitalize the words of a string
188
- * @param {string} value String or value to be capitalized
189
- * @param {boolean} lower To lowercase other chars
190
- */
191
- capitalize = (e, t = !1) => e ? (t ? e.toLowerCase() : e).replace(/(?:^|\s)\S/g, (r) => r.toUpperCase()) : "";
192
- /**
193
- * Validate current MongoDB ObjectId
194
- * @param id Id to check for ObjectId
195
- */
196
- isValidObjectId = (e) => !!(e && /^[a-fA-F0-9]{24}$/i.test(e));
197
- /**
198
- * Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs
199
- * @param {string} Key name to find the value
200
- * @param {any} data Data/value to be stored
201
- */
202
- sendMessageToAllTabs = (e, t) => {
203
- const r = {
204
- type: e,
205
- t: this.TabIdKey,
206
- domain: window.location.hostname,
207
- ...t
208
- };
209
- localStorage.setItem(g, JSON.stringify(r)), localStorage.removeItem(g);
210
- };
211
- /**
212
- * Check and get new event message, from event object
213
- * @param {StorageEvent} event Event object received in storage event listener
214
- */
215
- getStorageMessage = (e) => {
216
- if (e.key === g && e.newValue) {
217
- const t = JSON.parse(e.newValue);
218
- if (t && t.t !== S.TabIdKey && t.domain === window.location.hostname)
219
- return t;
220
- }
221
- return null;
222
- };
223
- /**
224
- * Assign value to an object by key/path name
225
- * @param obj Object to assign value to
226
- * @param path key full path
227
- * @param val value to be assigned
228
- * @param separator Path separator
229
- */
230
- setNestedKeyValue = (e, t, r, a = ".") => {
231
- const o = t.split(a), i = o.pop(), n = o.reduce((s, l) => s[l] = s[l] || {}, e);
232
- n[i] = r;
233
- };
234
- /**
235
- * Get comma separated address string
236
- * @param address address object to be converted
237
- */
238
- getAddressString = (e, t = "") => e && [
239
- e.building,
240
- e.street,
241
- e.city,
242
- e.county,
243
- e.postcode,
244
- e.country
245
- ].filter((r) => r && r.length > 0).join(", ") || t;
246
- /**
247
- * Get new random UUID
248
- * @returns {string}
249
- */
250
- uuid = () => {
251
- let e = "", t = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", r = 0, a = Math.random() * 4294967295 | 0;
252
- for (; r++ < 36; ) {
253
- var o = t[r - 1], i = a & 15, n = o == "x" ? i : i & 3 | 8;
254
- e += o == "-" || o == "4" ? o : n.toString(16), a = r % 8 == 0 ? Math.random() * 4294967295 | 0 : a >> 4;
255
- }
256
- return e;
257
- };
258
261
  }
259
- const S = new m();
260
- function y() {
261
- const u = p.useRef(null);
262
- return p.useEffect(() => (u.current = !0, () => {
263
- u.current = !1;
264
- })), u;
262
+ const N = new M();
263
+ function T() {
264
+ const i = x.useRef(null);
265
+ return x.useEffect(() => (i.current = !0, () => {
266
+ i.current = !1;
267
+ })), i;
265
268
  }
266
269
  export {
267
- g as StorageMessageKey,
268
- S as Utils,
269
- y as useIsMountedRef
270
+ c as StorageMessageKey,
271
+ N as Utils,
272
+ T as useIsMountedRef
270
273
  };
271
274
  //# sourceMappingURL=Utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.js","sources":["../../../src/Utilities/Utils.tsx"],"sourcesContent":["import { Dayjs } from 'dayjs';\r\nimport React from 'react';\r\nimport { useLocation } from 'react-router-dom';\r\nimport { dayjs } from '../Utilities/dayjs';\r\nimport { IAddress } from './Types';\r\n\r\nexport const StorageMessageKey = 'ao-message';\r\n\r\nexport interface IStorageMessage extends Record<string, any> {\r\n type: string;\r\n t: string;\r\n domain: string;\r\n}\r\n\r\nexport interface IFormattedNumberOptions {\r\n decimalPlaces?: number;\r\n withComma?: boolean;\r\n useDashForZero?: boolean;\r\n}\r\n\r\nclass UtilsBase {\r\n DateRegEx = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}/;\r\n NiNoRegEx =\r\n /([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 ]/;\r\n /**\r\n * Unique id for the tab (openned browser tab)\r\n */\r\n public TabIdKey: string;\r\n\r\n constructor() {\r\n this.TabIdKey = Math.random().toString(36).substring(2, 8);\r\n }\r\n\r\n /**\r\n * Get number from any type/value\r\n * @param num Value to get number\r\n */\r\n getNumber = (num?: string | number): number => {\r\n if (!num || num === '') return 0;\r\n if (typeof num === 'number') return isNaN(num) ? 0 : num;\r\n return this.getNumber(parseFloat(num.replaceAll(',', '')));\r\n };\r\n /**\r\n * Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY\r\n * @param date Date to be formatted\r\n * @param emptyValue Value to return if date is empty or null\r\n * @param withTime Return date with time\r\n */\r\n getFormattedDate = (\r\n date: string | number | Date | Dayjs | undefined,\r\n emptyValue?: string,\r\n withTime?: boolean,\r\n timeZone: string = 'Europe/London'\r\n ) => {\r\n if (!date || date === '') return emptyValue;\r\n const dt =\r\n typeof date === 'string' &&\r\n /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$/.test(\r\n date\r\n )\r\n ? dayjs(date, 'DD/MM/YYYY')\r\n : dayjs(date);\r\n return dt.isValid()\r\n ? withTime\r\n ? dt.tz(timeZone).format(`DD/MM/YYYY hh:mm A`)\r\n : dt.format(`DD/MM/YYYY`)\r\n : emptyValue;\r\n };\r\n /**\r\n * Get formatted number\r\n * @param number Number to format\r\n * @param decimalPlaces Number of decimal places\r\n * @param withComma Get number with separator\r\n * @param useDashForZero Use dash for zero\r\n * @param withCurrency Prepend £ before number\r\n */\r\n getFormattedNumber = (\r\n number: any,\r\n decimalPlaces: number = 2,\r\n withComma: boolean = true,\r\n useDashForZero: boolean = false,\r\n withCurrency: boolean = false\r\n ) => {\r\n if (isNaN(number)) number = 0;\r\n\r\n if (useDashForZero && (!number || number === '' || number === 0 || number === '0')) return '-';\r\n\r\n var isNegative = false;\r\n if (number < 0) {\r\n isNegative = true;\r\n number = Math.abs(number);\r\n }\r\n var t = parseFloat(number)\r\n .toFixed(decimalPlaces !== null && decimalPlaces !== undefined ? decimalPlaces : 2)\r\n .split('.');\r\n var str = number;\r\n if (t.length >= 1) {\r\n str = '';\r\n //var r = t[0].slice('');\r\n var r = t[0].slice(0);\r\n for (var i = r.length - 1, j = 1; i >= 0; i--, j++) {\r\n str = r[i] + str;\r\n if (withComma && j % 3 === 0 && i > 0) str = ',' + str;\r\n }\r\n if (t.length > 1) str += '.' + t[1];\r\n }\r\n return (withCurrency ? '£' : '') + (isNegative ? `(${str})` : str);\r\n };\r\n /**\r\n * Get formatted number\r\n * @param number Number to format\r\n * @param useDashForZero Use dash for zero\r\n */\r\n getFormattedCurrency = (number: any, useDashForZero: boolean = false) =>\r\n this.getFormattedNumber(number, 2, true, useDashForZero, true);\r\n\r\n /**\r\n * Append zero if number is less then 10\r\n * @param num Number to check\r\n */\r\n appendZero = (num: number) => (num < 10 ? `0${num}` : num);\r\n /**\r\n * Get formatted time (MM:SS)\r\n * @param seconds Seconds - to get time\r\n * @param minutes Minutes - to get time\r\n */\r\n getFormattedTime = (seconds: number, minutes: number = 0) => {\r\n const dateTime = new Date(0, 0, 0, 0, minutes, seconds, 0),\r\n dateTimeM = this.appendZero(dateTime.getMinutes()),\r\n dateTimeS = this.appendZero(dateTime.getSeconds());\r\n\r\n return `${dateTimeM}:${dateTimeS}`;\r\n };\r\n /**\r\n * Get formatted time from total seconds\r\n * @param seconds Total seconds to calculate hours and minutes\r\n * @param ignoreSeconds Skip seconds in output string\r\n */\r\n getFormattedSeconds = (seconds: number, ignoreSeconds?: boolean) => {\r\n if (seconds > 0) {\r\n var hours = Math.floor(seconds / 3600);\r\n seconds %= 3600;\r\n var minutes = Math.floor(seconds / 60);\r\n seconds = Math.floor(seconds % 60);\r\n return (\r\n `${this.appendZero(hours)}:${this.appendZero(minutes)}` +\r\n (ignoreSeconds ? '' : `:${this.appendZero(seconds)}`)\r\n );\r\n }\r\n return '-';\r\n };\r\n\r\n /**\r\n * Get a property value from local storage\r\n * @param {string} Key name to find the value\r\n */\r\n getLocal = (key: string): any => {\r\n const data = localStorage.getItem(key);\r\n if (data) return JSON.parse(data);\r\n return null;\r\n };\r\n /**\r\n * Set a property with value to local storage\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n setLocal = (key: string, data: any) => {\r\n localStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');\r\n };\r\n /**\r\n * Remove a property with value from local storage\r\n * @param {string} Key name to find the value\r\n */\r\n removeLocal = (key: string) => {\r\n localStorage.removeItem(key);\r\n };\r\n /**\r\n * Get a property value from session storage\r\n * @param {string} Key name to find the value\r\n */\r\n getSession = (key: string): any => {\r\n const data = sessionStorage.getItem(key);\r\n if (data) return JSON.parse(data);\r\n return null;\r\n };\r\n /**\r\n * Set a property with value to session storage\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n setSession = (key: string, data: any) => {\r\n sessionStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');\r\n };\r\n jsonReplacer = (key: string, value: any) => {\r\n if (value === null) return undefined;\r\n if (value === false) return undefined;\r\n return value;\r\n };\r\n /**\r\n * Get file size in kb/mb/gb etc.\r\n * @param {number} size File lenth/size\r\n */\r\n getFileSize = (size: number) => {\r\n var selectedSize = 0;\r\n var selectedUnit = 'b';\r\n\r\n if (size > 0) {\r\n var units = ['tb', 'gb', 'mb', 'kb', 'b'];\r\n\r\n for (var i = 0; i < units.length; i++) {\r\n var unit = units[i];\r\n var cutoff = Math.pow(1000, 4 - i) / 10;\r\n\r\n if (size >= cutoff) {\r\n selectedSize = size / Math.pow(1000, 4 - i);\r\n selectedUnit = unit;\r\n break;\r\n }\r\n }\r\n\r\n selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits\r\n }\r\n\r\n return `${selectedSize} ${selectedUnit.toUpperCase()}`;\r\n };\r\n\r\n /**\r\n * A custom hook that builds on useLocation to parse the query string for you.\r\n */\r\n useQuery = () => new URLSearchParams(useLocation().search);\r\n\r\n /**\r\n * Sum number array\r\n * @param {number[]} arr Number array\r\n */\r\n sumArray = (arr: number[]) => arr.reduce((a, b) => a + b);\r\n /**\r\n * Get sorted array by property\r\n * @param {any[]} arr Array of objects\r\n * @param {string} key Property/field name to sort\r\n * @returns {any[]}\r\n */\r\n sortArray<T = any>(arr: T[], key: keyof T): T[] {\r\n return arr.sort((a, b) => {\r\n if (a[key] < b[key]) {\r\n return -1;\r\n }\r\n if (a[key] > b[key]) {\r\n return 1;\r\n }\r\n return 0;\r\n });\r\n }\r\n /**\r\n * Replace an item in array with index\r\n * @param arr Array of objects\r\n * @param index Index where to replace the item\r\n * @param newValue New item to be replaced with\r\n * @returns Array of objects\r\n */\r\n replaceItemAtIndex<T = any>(arr: T[], index: number, newValue: T): T[] {\r\n return [...arr.slice(0, index), newValue, ...arr.slice(index + 1)];\r\n }\r\n /**\r\n * Remove an item from array with index\r\n * @param arr Array of objects\r\n * @param index Index which item to be removed\r\n * @returns Array of object\r\n */\r\n removeItemAtIndex<T = any>(arr: T[], index: number): T[] {\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n }\r\n /**\r\n * Capitalize the words of a string\r\n * @param {string} value String or value to be capitalized\r\n * @param {boolean} lower To lowercase other chars\r\n */\r\n capitalize = (value: string | null | undefined, lower: boolean = false) =>\r\n value\r\n ? (lower ? value.toLowerCase() : value).replace(/(?:^|\\s)\\S/g, (a) => a.toUpperCase())\r\n : '';\r\n\r\n /**\r\n * Validate current MongoDB ObjectId\r\n * @param id Id to check for ObjectId\r\n */\r\n isValidObjectId = (id?: string) => (id && /^[a-fA-F0-9]{24}$/i.test(id) ? true : false);\r\n\r\n /**\r\n * Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n sendMessageToAllTabs = (type: string, data?: any) => {\r\n const message: IStorageMessage = {\r\n type,\r\n t: this.TabIdKey,\r\n domain: window.location.hostname,\r\n ...data,\r\n };\r\n localStorage.setItem(StorageMessageKey, JSON.stringify(message));\r\n localStorage.removeItem(StorageMessageKey);\r\n };\r\n /**\r\n * Check and get new event message, from event object\r\n * @param {StorageEvent} event Event object received in storage event listener\r\n */\r\n getStorageMessage = (event: StorageEvent): IStorageMessage | null => {\r\n if (event.key === StorageMessageKey && event.newValue) {\r\n const message: IStorageMessage = JSON.parse(event.newValue);\r\n if (message && message.t !== Utils.TabIdKey && message.domain === window.location.hostname) {\r\n return message;\r\n }\r\n }\r\n return null;\r\n };\r\n\r\n /**\r\n * Assign value to an object by key/path name\r\n * @param obj Object to assign value to\r\n * @param path key full path\r\n * @param val value to be assigned\r\n * @param separator Path separator\r\n */\r\n setNestedKeyValue = (obj: any, path: string, val: any, separator: string = '.') => {\r\n const keys = path.split(separator);\r\n const lastKey = keys.pop();\r\n const lastObj = keys.reduce((obj, key) => (obj[key] = obj[key] || {}), obj);\r\n lastObj[lastKey as any] = val;\r\n };\r\n\r\n /**\r\n * Get comma separated address string\r\n * @param address address object to be converted\r\n */\r\n getAddressString = (address?: IAddress, emptyString: string = '') => {\r\n if (address) {\r\n return (\r\n [\r\n address.building,\r\n address.street,\r\n address.city,\r\n address.county,\r\n address.postcode,\r\n address.country,\r\n ]\r\n .filter((v) => v && v.length > 0)\r\n .join(', ') || emptyString\r\n );\r\n }\r\n return emptyString;\r\n };\r\n\r\n /**\r\n * Get new random UUID\r\n * @returns {string}\r\n */\r\n uuid = (): string => {\r\n let u = '',\r\n m = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',\r\n i = 0,\r\n rb = (Math.random() * 0xffffffff) | 0;\r\n\r\n while (i++ < 36) {\r\n var c = m[i - 1],\r\n r = rb & 0xf,\r\n v = c == 'x' ? r : (r & 0x3) | 0x8;\r\n\r\n u += c == '-' || c == '4' ? c : v.toString(16);\r\n rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;\r\n }\r\n return u;\r\n };\r\n}\r\nexport const Utils = new UtilsBase();\r\n\r\nexport function useIsMountedRef() {\r\n const isMountedRef = React.useRef<boolean | null>(null);\r\n React.useEffect(() => {\r\n isMountedRef.current = true;\r\n return () => {\r\n isMountedRef.current = false;\r\n };\r\n });\r\n return isMountedRef;\r\n}\r\n"],"names":["StorageMessageKey","UtilsBase","num","date","emptyValue","withTime","timeZone","dt","dayjs","number","decimalPlaces","withComma","useDashForZero","withCurrency","isNegative","t","str","r","i","j","seconds","minutes","dateTime","dateTimeM","dateTimeS","ignoreSeconds","hours","key","data","value","size","selectedSize","selectedUnit","units","unit","cutoff","useLocation","arr","a","b","index","newValue","lower","id","type","message","event","Utils","obj","path","val","separator","keys","lastKey","lastObj","address","emptyString","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AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB,OAAO,MAAc;AACnB,QAAIE,IAAI,IACNC,IAAI,wCACJzC,IAAI,GACJ0C,IAAM,KAAK,OAAA,IAAW,aAAc;AAEtC,WAAO1C,MAAM,MAAI;AACf,UAAI2C,IAAIF,EAAEzC,IAAI,CAAC,GACbD,IAAI2C,IAAK,IACTH,IAAII,KAAK,MAAM5C,IAAKA,IAAI,IAAO;AAEjC,MAAAyC,KAAKG,KAAK,OAAOA,KAAK,MAAMA,IAAIJ,EAAE,SAAS,EAAE,GAC7CG,IAAK1C,IAAI,KAAK,IAAK,KAAK,WAAW,aAAc,IAAI0C,KAAM;AAAA,IAC7D;AACA,WAAOF;AAAA,EACT;AACF;AACO,MAAMX,IAAQ,IAAI9C,EAAA;AAElB,SAAS6D,IAAkB;AAChC,QAAMC,IAAeC,EAAM,OAAuB,IAAI;AACtD,SAAAA,EAAM,UAAU,OACdD,EAAa,UAAU,IAChB,MAAM;AACX,IAAAA,EAAa,UAAU;AAAA,EACzB,EACD,GACMA;AACT;"}
1
+ {"version":3,"file":"Utils.js","sources":["../../../src/Utilities/Utils.tsx"],"sourcesContent":["import { Dayjs } from 'dayjs';\r\nimport React from 'react';\r\nimport { useLocation } from 'react-router-dom';\r\nimport { dayjs } from '../Utilities/dayjs';\r\nimport { IAddress } from './Types';\r\n\r\nexport const StorageMessageKey = 'ao-message';\r\n\r\nexport interface IStorageMessage extends Record<string, any> {\r\n type: string;\r\n t: string;\r\n domain: string;\r\n}\r\n\r\nexport interface IFormattedNumberOptions {\r\n decimalPlaces?: number;\r\n withComma?: boolean;\r\n useDashForZero?: boolean;\r\n}\r\n\r\nclass UtilsBase {\r\n DateRegEx = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}/;\r\n NiNoRegEx =\r\n /([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 ]/;\r\n /**\r\n * Unique id for the tab (openned browser tab)\r\n */\r\n public TabIdKey: string;\r\n\r\n constructor() {\r\n this.TabIdKey = Math.random().toString(36).substring(2, 8);\r\n }\r\n\r\n /**\r\n * Get number from any type/value\r\n * @param num Value to get number\r\n */\r\n getNumber = (num?: string | number): number => {\r\n if (!num || num === '') return 0;\r\n if (typeof num === 'number') return isNaN(num) ? 0 : num;\r\n return this.getNumber(parseFloat(num.replaceAll(',', '')));\r\n };\r\n /**\r\n * Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY\r\n * @param date Date to be formatted\r\n * @param emptyValue Value to return if date is empty or null\r\n * @param withTime Return date with time\r\n */\r\n getFormattedDate = (\r\n date: string | number | Date | Dayjs | undefined,\r\n emptyValue?: string,\r\n withTime?: boolean,\r\n timeZone: string = 'Europe/London'\r\n ) => {\r\n if (!date || date === '') return emptyValue;\r\n const dt =\r\n typeof date === 'string' &&\r\n /^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$/.test(\r\n date\r\n )\r\n ? dayjs(date, 'DD/MM/YYYY')\r\n : dayjs(date);\r\n return dt.isValid()\r\n ? withTime\r\n ? dt.tz(timeZone).format(`DD/MM/YYYY hh:mm A`)\r\n : dt.format(`DD/MM/YYYY`)\r\n : emptyValue;\r\n };\r\n /**\r\n * Get formatted number\r\n * @param number Number to format\r\n * @param decimalPlaces Number of decimal places\r\n * @param withComma Get number with separator\r\n * @param useDashForZero Use dash for zero\r\n * @param withCurrency Prepend £ before number\r\n */\r\n getFormattedNumber = (\r\n number: any,\r\n decimalPlaces: number = 2,\r\n withComma: boolean = true,\r\n useDashForZero: boolean = false,\r\n withCurrency: boolean = false\r\n ) => {\r\n if (isNaN(number)) number = 0;\r\n\r\n if (useDashForZero && (!number || number === '' || number === 0 || number === '0')) return '-';\r\n\r\n var isNegative = false;\r\n if (number < 0) {\r\n isNegative = true;\r\n number = Math.abs(number);\r\n }\r\n var t = parseFloat(number)\r\n .toFixed(decimalPlaces !== null && decimalPlaces !== undefined ? decimalPlaces : 2)\r\n .split('.');\r\n var str = number;\r\n if (t.length >= 1) {\r\n str = '';\r\n //var r = t[0].slice('');\r\n var r = t[0].slice(0);\r\n for (var i = r.length - 1, j = 1; i >= 0; i--, j++) {\r\n str = r[i] + str;\r\n if (withComma && j % 3 === 0 && i > 0) str = ',' + str;\r\n }\r\n if (t.length > 1) str += '.' + t[1];\r\n }\r\n return (withCurrency ? '£' : '') + (isNegative ? `(${str})` : str);\r\n };\r\n /**\r\n * Get formatted number\r\n * @param number Number to format\r\n * @param useDashForZero Use dash for zero\r\n */\r\n getFormattedCurrency = (number: any, useDashForZero: boolean = false) =>\r\n this.getFormattedNumber(number, 2, true, useDashForZero, true);\r\n\r\n /**\r\n * Append zero if number is less then 10\r\n * @param num Number to check\r\n */\r\n appendZero = (num: number) => (num < 10 ? `0${num}` : num);\r\n /**\r\n * Get formatted time (MM:SS)\r\n * @param seconds Seconds - to get time\r\n * @param minutes Minutes - to get time\r\n */\r\n getFormattedTime = (seconds: number, minutes: number = 0) => {\r\n const dateTime = new Date(0, 0, 0, 0, minutes, seconds, 0),\r\n dateTimeM = this.appendZero(dateTime.getMinutes()),\r\n dateTimeS = this.appendZero(dateTime.getSeconds());\r\n\r\n return `${dateTimeM}:${dateTimeS}`;\r\n };\r\n /**\r\n * Get formatted time from total seconds\r\n * @param seconds Total seconds to calculate hours and minutes\r\n * @param ignoreSeconds Skip seconds in output string\r\n */\r\n getFormattedSeconds = (seconds: number, ignoreSeconds?: boolean) => {\r\n if (seconds > 0) {\r\n var hours = Math.floor(seconds / 3600);\r\n seconds %= 3600;\r\n var minutes = Math.floor(seconds / 60);\r\n seconds = Math.floor(seconds % 60);\r\n return (\r\n `${this.appendZero(hours)}:${this.appendZero(minutes)}` +\r\n (ignoreSeconds ? '' : `:${this.appendZero(seconds)}`)\r\n );\r\n }\r\n return '-';\r\n };\r\n\r\n /**\r\n * Get a property value from local storage\r\n * @param {string} Key name to find the value\r\n */\r\n getLocal = (key: string): any => {\r\n const data = localStorage.getItem(key);\r\n if (data) return JSON.parse(data);\r\n return null;\r\n };\r\n /**\r\n * Set a property with value to local storage\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n setLocal = (key: string, data: any) => {\r\n localStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');\r\n };\r\n /**\r\n * Remove a property with value from local storage\r\n * @param {string} Key name to find the value\r\n */\r\n removeLocal = (key: string) => {\r\n localStorage.removeItem(key);\r\n };\r\n /**\r\n * Get a property value from session storage\r\n * @param {string} Key name to find the value\r\n */\r\n getSession = (key: string): any => {\r\n const data = sessionStorage.getItem(key);\r\n if (data) return JSON.parse(data);\r\n return null;\r\n };\r\n /**\r\n * Set a property with value to session storage\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n setSession = (key: string, data: any) => {\r\n sessionStorage.setItem(key, data ? JSON.stringify(data, this.jsonReplacer) : '');\r\n };\r\n jsonReplacer = (key: string, value: any) => {\r\n if (value === null) return undefined;\r\n if (value === false) return undefined;\r\n return value;\r\n };\r\n /**\r\n * Get file size in kb/mb/gb etc.\r\n * @param {number} size File lenth/size\r\n */\r\n getFileSize = (size: number) => {\r\n var selectedSize = 0;\r\n var selectedUnit = 'b';\r\n\r\n if (size > 0) {\r\n var units = ['tb', 'gb', 'mb', 'kb', 'b'];\r\n\r\n for (var i = 0; i < units.length; i++) {\r\n var unit = units[i];\r\n var cutoff = Math.pow(1000, 4 - i) / 10;\r\n\r\n if (size >= cutoff) {\r\n selectedSize = size / Math.pow(1000, 4 - i);\r\n selectedUnit = unit;\r\n break;\r\n }\r\n }\r\n\r\n selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits\r\n }\r\n\r\n return `${selectedSize} ${selectedUnit.toUpperCase()}`;\r\n };\r\n\r\n /**\r\n * A custom hook that builds on useLocation to parse the query string for you.\r\n */\r\n useQuery = () => new URLSearchParams(useLocation().search);\r\n\r\n /**\r\n * Sum number array\r\n * @param {number[]} arr Number array\r\n */\r\n sumArray = (arr: number[]) => arr.reduce((a, b) => a + b);\r\n /**\r\n * Get sorted array by property\r\n * @param {any[]} arr Array of objects\r\n * @param {string} key Property/field name to sort\r\n * @returns {any[]}\r\n */\r\n sortArray<T = any>(arr: T[], key: keyof T): T[] {\r\n return arr.sort((a, b) => {\r\n if (a[key] < b[key]) {\r\n return -1;\r\n }\r\n if (a[key] > b[key]) {\r\n return 1;\r\n }\r\n return 0;\r\n });\r\n }\r\n /**\r\n * Replace an item in array with index\r\n * @param arr Array of objects\r\n * @param index Index where to replace the item\r\n * @param newValue New item to be replaced with\r\n * @returns Array of objects\r\n */\r\n replaceItemAtIndex<T = any>(arr: T[], index: number, newValue: T): T[] {\r\n return [...arr.slice(0, index), newValue, ...arr.slice(index + 1)];\r\n }\r\n /**\r\n * Remove an item from array with index\r\n * @param arr Array of objects\r\n * @param index Index which item to be removed\r\n * @returns Array of object\r\n */\r\n removeItemAtIndex<T = any>(arr: T[], index: number): T[] {\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n }\r\n /**\r\n * Capitalize the words of a string\r\n * @param {string} value String or value to be capitalized\r\n * @param {boolean} lower To lowercase other chars\r\n */\r\n capitalize = (value: string | null | undefined, lower: boolean = false) =>\r\n value\r\n ? (lower ? value.toLowerCase() : value).replace(/(?:^|\\s)\\S/g, (a) => a.toUpperCase())\r\n : '';\r\n\r\n /**\r\n * Validate current MongoDB ObjectId\r\n * @param id Id to check for ObjectId\r\n */\r\n isValidObjectId = (id?: string) => (id && /^[a-fA-F0-9]{24}$/i.test(id) ? true : false);\r\n\r\n /**\r\n * Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs\r\n * @param {string} Key name to find the value\r\n * @param {any} data Data/value to be stored\r\n */\r\n sendMessageToAllTabs = (type: string, data?: any) => {\r\n const message: IStorageMessage = {\r\n type,\r\n t: this.TabIdKey,\r\n domain: window.location.hostname,\r\n ...data,\r\n };\r\n localStorage.setItem(StorageMessageKey, JSON.stringify(message));\r\n localStorage.removeItem(StorageMessageKey);\r\n };\r\n /**\r\n * Check and get new event message, from event object\r\n * @param {StorageEvent} event Event object received in storage event listener\r\n */\r\n getStorageMessage = (event: StorageEvent): IStorageMessage | null => {\r\n if (event.key === StorageMessageKey && event.newValue) {\r\n const message: IStorageMessage = JSON.parse(event.newValue);\r\n if (message && message.t !== Utils.TabIdKey && message.domain === window.location.hostname) {\r\n return message;\r\n }\r\n }\r\n return null;\r\n };\r\n\r\n /**\r\n * Assign value to an object by key/path name\r\n * @param obj Object to assign value to\r\n * @param path key full path\r\n * @param val value to be assigned\r\n * @param separator Path separator\r\n */\r\n setNestedKeyValue = (obj: any, path: string, val: any, separator: string = '.') => {\r\n const keys = path.split(separator);\r\n const lastKey = keys.pop();\r\n const lastObj = keys.reduce((obj, key) => (obj[key] = obj[key] || {}), obj);\r\n lastObj[lastKey as any] = val;\r\n };\r\n\r\n /**\r\n * Get comma separated address string\r\n * @param address address object to be converted\r\n */\r\n getAddressString = (address?: IAddress, emptyString: string = '') => {\r\n if (address) {\r\n return (\r\n [\r\n address.building,\r\n address.street,\r\n address.city,\r\n address.county,\r\n address.postcode,\r\n address.country,\r\n ]\r\n .filter((v) => v && v.length > 0)\r\n .join(', ') || emptyString\r\n );\r\n }\r\n return emptyString;\r\n };\r\n\r\n /**\r\n * Get new random UUID\r\n * @returns {string}\r\n */\r\n uuid = (): string => {\r\n let u = '',\r\n m = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',\r\n i = 0,\r\n rb = (Math.random() * 0xffffffff) | 0;\r\n\r\n while (i++ < 36) {\r\n var c = m[i - 1],\r\n r = rb & 0xf,\r\n v = c == 'x' ? r : (r & 0x3) | 0x8;\r\n\r\n u += c == '-' || c == '4' ? c : v.toString(16);\r\n rb = i % 8 == 0 ? (Math.random() * 0xffffffff) | 0 : rb >> 4;\r\n }\r\n return u;\r\n };\r\n}\r\nexport const Utils = new UtilsBase();\r\n\r\nexport function useIsMountedRef() {\r\n const isMountedRef = React.useRef<boolean | null>(null);\r\n React.useEffect(() => {\r\n isMountedRef.current = true;\r\n return () => {\r\n isMountedRef.current = false;\r\n };\r\n });\r\n return isMountedRef;\r\n}\r\n"],"names":["StorageMessageKey","UtilsBase","__publicField","num","date","emptyValue","withTime","timeZone","dt","dayjs","number","decimalPlaces","withComma","useDashForZero","withCurrency","isNegative","t","str","r","i","j","seconds","minutes","dateTime","dateTimeM","dateTimeS","ignoreSeconds","hours","key","data","value","size","selectedSize","selectedUnit","units","unit","cutoff","useLocation","arr","a","b","lower","id","type","message","event","Utils","obj","path","val","separator","keys","lastKey","lastObj","address","emptyString","v","u","m","rb","c","index","newValue","useIsMountedRef","isMountedRef","React"],"mappings":";;;;;;AAMO,MAAMA,IAAoB;AAcjC,MAAMC,EAAU;AAAA,EASd,cAAc;AARd,IAAAC,EAAA,mBAAY;AACZ,IAAAA,EAAA,mBACE;AAIK;AAAA;AAAA;AAAA,IAAAA,EAAA;AAUP;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA,mBAAY,CAACC,MACP,CAACA,KAAOA,MAAQ,KAAW,IAC3B,OAAOA,KAAQ,WAAiB,MAAMA,CAAG,IAAI,IAAIA,IAC9C,KAAK,UAAU,WAAWA,EAAI,WAAW,KAAK,EAAE,CAAC,CAAC;AAQ3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAD,EAAA,0BAAmB,CACjBE,GACAC,GACAC,GACAC,IAAmB,oBAChB;AACH,UAAI,CAACH,KAAQA,MAAS,GAAI,QAAOC;AACjC,YAAMG,IACJ,OAAOJ,KAAS,YACd,qFAAqF;AAAA,QACnFA;AAAA,MAAA,IAEAK,EAAML,GAAM,Y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