react-js-plugins 3.14.3 → 3.14.5
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/dist/chunkautils/chunk21211.js +30 -11
- package/dist/chunkautils/chunk22123.js +59 -118
- package/dist/chunkautils/chunk22523.js +16 -17
- package/dist/chunkautils/chunk23111.js +17 -35
- package/dist/chunkautils/chunk34621.d.ts +11 -0
- package/dist/chunkautils/chunk34621.js +85 -0
- package/dist/chunkautils/chunk65431.js +312 -364
- package/dist/chunkautils/chunk75342.d.ts +0 -4
- package/dist/chunkautils/chunk75342.js +229 -335
- package/dist/chunkautils/chunk83453.js +278 -469
- package/dist/chunkautils/chunk83454.js +124 -218
- package/dist/chunkautils/chunk91172.js +27 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.js +15 -11
- package/package.json +7 -3
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
2
|
var t = {};
|
|
50
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -61,21 +14,50 @@ import * as X from 'xlsx';
|
|
|
61
14
|
import CryptoJS from 'crypto-js';
|
|
62
15
|
import Swal from "sweetalert2";
|
|
63
16
|
import { DateTime } from 'luxon';
|
|
64
|
-
export
|
|
17
|
+
export const isWindowReady = () => {
|
|
65
18
|
return typeof window !== "undefined" && document.readyState === "complete";
|
|
66
19
|
};
|
|
67
|
-
export
|
|
68
|
-
export
|
|
69
|
-
var
|
|
70
|
-
return Swal.fire(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
20
|
+
export const isBrowser = typeof window !== 'undefined' && typeof window.btoa === 'function';
|
|
21
|
+
export const _alert = (_a) => {
|
|
22
|
+
var { title = "Are you sure?", text = "This action cannot be undone.", icon = "warning", confirmButtonText = "OK", cancelButtonText = "Cancel", showCancelButton = true, showConfirmButton = true, confirmButtonColor = '#2e7d32', cancelButtonColor = '#da2a2a', input = null, inputPlaceholder = "", inputValidator = null, customClass = {}, timer = null, allowOutsideClick = true, html = null, toast = false, position = "center" } = _a, rest = __rest(_a, ["title", "text", "icon", "confirmButtonText", "cancelButtonText", "showCancelButton", "showConfirmButton", "confirmButtonColor", "cancelButtonColor", "input", "inputPlaceholder", "inputValidator", "customClass", "timer", "allowOutsideClick", "html", "toast", "position"]);
|
|
23
|
+
return Swal.fire(Object.assign({ title,
|
|
24
|
+
text,
|
|
25
|
+
icon,
|
|
26
|
+
confirmButtonText,
|
|
27
|
+
cancelButtonText,
|
|
28
|
+
showCancelButton,
|
|
29
|
+
showConfirmButton,
|
|
30
|
+
confirmButtonColor,
|
|
31
|
+
cancelButtonColor,
|
|
32
|
+
input,
|
|
33
|
+
inputPlaceholder,
|
|
34
|
+
inputValidator,
|
|
35
|
+
customClass,
|
|
36
|
+
timer,
|
|
37
|
+
allowOutsideClick,
|
|
38
|
+
html,
|
|
39
|
+
toast,
|
|
40
|
+
position }, rest));
|
|
41
|
+
};
|
|
42
|
+
export const _confirm = (_a) => {
|
|
43
|
+
var { title = "Are you sure?", text = "You won't be able to revert this!", icon = "warning", confirmButtonText = "Yes", cancelButtonText = "No", showCancelButton = true, confirmButtonColor = "#3085d6", cancelButtonColor = "#d33", reverseButtons = true, focusCancel = true, allowOutsideClick = false, customClass = {}, html = null } = _a, rest = __rest(_a, ["title", "text", "icon", "confirmButtonText", "cancelButtonText", "showCancelButton", "confirmButtonColor", "cancelButtonColor", "reverseButtons", "focusCancel", "allowOutsideClick", "customClass", "html"]);
|
|
44
|
+
return Swal.fire(Object.assign({ title,
|
|
45
|
+
text,
|
|
46
|
+
icon,
|
|
47
|
+
showCancelButton,
|
|
48
|
+
confirmButtonText,
|
|
49
|
+
cancelButtonText,
|
|
50
|
+
confirmButtonColor,
|
|
51
|
+
cancelButtonColor,
|
|
52
|
+
reverseButtons,
|
|
53
|
+
focusCancel,
|
|
54
|
+
allowOutsideClick,
|
|
55
|
+
customClass,
|
|
56
|
+
html }, rest)).then((result) => {
|
|
57
|
+
return { result, instance: Swal };
|
|
76
58
|
});
|
|
77
59
|
};
|
|
78
|
-
export
|
|
60
|
+
export const _encodeURI = (str) => {
|
|
79
61
|
try {
|
|
80
62
|
if (typeof str !== 'string')
|
|
81
63
|
return '';
|
|
@@ -86,7 +68,7 @@ export var _encodeURI = function (str) {
|
|
|
86
68
|
return '';
|
|
87
69
|
}
|
|
88
70
|
};
|
|
89
|
-
export
|
|
71
|
+
export const _decodeURI = (str) => {
|
|
90
72
|
try {
|
|
91
73
|
if (typeof str !== 'string')
|
|
92
74
|
return '';
|
|
@@ -97,7 +79,7 @@ export var _decodeURI = function (str) {
|
|
|
97
79
|
return '';
|
|
98
80
|
}
|
|
99
81
|
};
|
|
100
|
-
export
|
|
82
|
+
export const _encryptJson = (decrypted, secretKey) => {
|
|
101
83
|
try {
|
|
102
84
|
if (!decrypted) {
|
|
103
85
|
throw new Error("Invalid input: 'decrypted' data cannot be empty.");
|
|
@@ -105,15 +87,15 @@ export var _encryptJson = function (decrypted, secretKey) {
|
|
|
105
87
|
if (!secretKey || typeof secretKey !== 'string') {
|
|
106
88
|
throw new Error("Invalid input: 'secretKey' must be a non-empty string.");
|
|
107
89
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
iv
|
|
90
|
+
const jsonData = JSON.stringify(decrypted);
|
|
91
|
+
const iv = CryptoJS.lib.WordArray.random(16);
|
|
92
|
+
const key = CryptoJS.enc.Utf8.parse(secretKey);
|
|
93
|
+
const encrypted = CryptoJS.AES.encrypt(jsonData, key, {
|
|
94
|
+
iv,
|
|
113
95
|
mode: CryptoJS.mode.CBC,
|
|
114
96
|
padding: CryptoJS.pad.Pkcs7,
|
|
115
97
|
});
|
|
116
|
-
|
|
98
|
+
const encryptedData = iv.concat(encrypted.ciphertext);
|
|
117
99
|
return CryptoJS.enc.Base64.stringify(encryptedData);
|
|
118
100
|
}
|
|
119
101
|
catch (error) {
|
|
@@ -121,7 +103,7 @@ export var _encryptJson = function (decrypted, secretKey) {
|
|
|
121
103
|
return null;
|
|
122
104
|
}
|
|
123
105
|
};
|
|
124
|
-
export
|
|
106
|
+
export const _decryptJson = (encrypted, secretKey) => {
|
|
125
107
|
try {
|
|
126
108
|
if (!encrypted || typeof encrypted !== 'string') {
|
|
127
109
|
throw new Error("Invalid input: 'encrypted' must be a valid string.");
|
|
@@ -129,16 +111,16 @@ export var _decryptJson = function (encrypted, secretKey) {
|
|
|
129
111
|
if (!secretKey || typeof secretKey !== 'string') {
|
|
130
112
|
throw new Error("Invalid input: 'secretKey' must be a non-empty string.");
|
|
131
113
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
iv
|
|
114
|
+
const encryptedData = CryptoJS.enc.Base64.parse(encrypted);
|
|
115
|
+
const iv = CryptoJS.lib.WordArray.create(encryptedData.words.slice(0, 4), 16);
|
|
116
|
+
const ciphertext = CryptoJS.lib.WordArray.create(encryptedData.words.slice(4), encryptedData.sigBytes - 16);
|
|
117
|
+
const key = CryptoJS.enc.Utf8.parse(secretKey);
|
|
118
|
+
const decrypted = CryptoJS.AES.decrypt({ ciphertext }, key, {
|
|
119
|
+
iv,
|
|
138
120
|
mode: CryptoJS.mode.CBC,
|
|
139
121
|
padding: CryptoJS.pad.Pkcs7,
|
|
140
122
|
});
|
|
141
|
-
|
|
123
|
+
const decryptedString = decrypted.toString(CryptoJS.enc.Utf8);
|
|
142
124
|
if (!decryptedString) {
|
|
143
125
|
throw new Error("Decryption failed: Invalid key or corrupted data.");
|
|
144
126
|
}
|
|
@@ -149,14 +131,13 @@ export var _decryptJson = function (encrypted, secretKey) {
|
|
|
149
131
|
return null;
|
|
150
132
|
}
|
|
151
133
|
};
|
|
152
|
-
export
|
|
153
|
-
if (isRandom === void 0) { isRandom = true; }
|
|
134
|
+
export const _encryptString = (text, secretKey, isRandom = true) => {
|
|
154
135
|
try {
|
|
155
|
-
|
|
156
|
-
|
|
136
|
+
const key = CryptoJS.enc.Utf8.parse(secretKey);
|
|
137
|
+
const iv = isRandom
|
|
157
138
|
? CryptoJS.lib.WordArray.random(16)
|
|
158
139
|
: CryptoJS.enc.Utf8.parse(secretKey);
|
|
159
|
-
|
|
140
|
+
const encrypted = CryptoJS.AES.encrypt(text, key, {
|
|
160
141
|
iv: iv,
|
|
161
142
|
mode: CryptoJS.mode.CBC,
|
|
162
143
|
padding: CryptoJS.pad.Pkcs7,
|
|
@@ -171,11 +152,11 @@ export var _encryptString = function (text, secretKey, isRandom) {
|
|
|
171
152
|
throw error;
|
|
172
153
|
}
|
|
173
154
|
};
|
|
174
|
-
export
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
iv
|
|
155
|
+
export const _decryptString = (ciphertext, ivBase64, secretKey) => {
|
|
156
|
+
const key = CryptoJS.enc.Utf8.parse(secretKey);
|
|
157
|
+
const iv = CryptoJS.enc.Base64.parse(ivBase64);
|
|
158
|
+
const decryptedText = CryptoJS.AES.decrypt(ciphertext, key, {
|
|
159
|
+
iv,
|
|
179
160
|
mode: CryptoJS.mode.CBC,
|
|
180
161
|
padding: CryptoJS.pad.Pkcs7
|
|
181
162
|
});
|
|
@@ -242,13 +223,13 @@ export var _decryptString = function (ciphertext, ivBase64, secretKey) {
|
|
|
242
223
|
// return null;
|
|
243
224
|
// }
|
|
244
225
|
// };
|
|
245
|
-
export
|
|
226
|
+
export const _encryptData = (params) => {
|
|
246
227
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
228
|
+
const { data, secretKey, iv } = params;
|
|
229
|
+
const t = CryptoJS.enc.Base64.parse(secretKey);
|
|
230
|
+
const o = CryptoJS.enc.Base64.parse(iv);
|
|
231
|
+
const e = typeof data === 'string' ? data : JSON.stringify(data);
|
|
232
|
+
const n = CryptoJS.AES.encrypt(e, t, {
|
|
252
233
|
iv: o,
|
|
253
234
|
mode: CryptoJS.mode.CBC,
|
|
254
235
|
padding: CryptoJS.pad.Pkcs7
|
|
@@ -260,20 +241,20 @@ export var _encryptData = function (params) {
|
|
|
260
241
|
return null;
|
|
261
242
|
}
|
|
262
243
|
};
|
|
263
|
-
export
|
|
244
|
+
export const _decryptData = (params) => {
|
|
264
245
|
try {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
246
|
+
const { data, secretKey, iv } = params;
|
|
247
|
+
const t = CryptoJS.enc.Base64.parse(secretKey);
|
|
248
|
+
const e = CryptoJS.enc.Base64.parse(iv);
|
|
249
|
+
const o = CryptoJS.lib.CipherParams.create({
|
|
269
250
|
ciphertext: CryptoJS.enc.Base64.parse(data)
|
|
270
251
|
});
|
|
271
|
-
|
|
252
|
+
const c = CryptoJS.AES.decrypt(o, t, {
|
|
272
253
|
iv: e,
|
|
273
254
|
mode: CryptoJS.mode.CBC,
|
|
274
255
|
padding: CryptoJS.pad.Pkcs7
|
|
275
256
|
});
|
|
276
|
-
|
|
257
|
+
const p = c.toString(CryptoJS.enc.Utf8);
|
|
277
258
|
if (!p) {
|
|
278
259
|
throw new Error('Decryption failed: Invalid key or corrupted data.');
|
|
279
260
|
}
|
|
@@ -289,48 +270,45 @@ export var _decryptData = function (params) {
|
|
|
289
270
|
return null;
|
|
290
271
|
}
|
|
291
272
|
};
|
|
292
|
-
export
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
var password = "";
|
|
273
|
+
export const _generatePassword = (length = 8) => {
|
|
274
|
+
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
275
|
+
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
|
|
276
|
+
const numbers = '0123456789';
|
|
277
|
+
const specialChars = '!@#$%^&*_-+=<>?';
|
|
278
|
+
const allChars = uppercase + lowercase + numbers + specialChars;
|
|
279
|
+
let password = "";
|
|
300
280
|
password += uppercase[Math.floor(Math.random() * uppercase.length)];
|
|
301
281
|
password += lowercase[Math.floor(Math.random() * lowercase.length)];
|
|
302
282
|
password += numbers[Math.floor(Math.random() * numbers.length)];
|
|
303
283
|
password += specialChars[Math.floor(Math.random() * specialChars.length)];
|
|
304
|
-
for (
|
|
284
|
+
for (let i = 4; i < length; i++) {
|
|
305
285
|
password += allChars[Math.floor(Math.random() * allChars.length)];
|
|
306
286
|
}
|
|
307
|
-
return password.split('').sort(
|
|
287
|
+
return password.split('').sort(() => Math.random() - 0.5).join('');
|
|
308
288
|
};
|
|
309
|
-
export
|
|
310
|
-
if (format === void 0) { format = 'YYYY-MM-DDTHH:mm:ss'; }
|
|
289
|
+
export const _getStartStopTime = (sdate, format = 'YYYY-MM-DDTHH:mm:ss') => {
|
|
311
290
|
if (!(sdate instanceof Date) || isNaN(sdate.getTime())) {
|
|
312
291
|
return 'Invalid Date';
|
|
313
292
|
}
|
|
314
|
-
|
|
315
|
-
|
|
293
|
+
const start = new Date(sdate.getFullYear(), sdate.getMonth(), 1);
|
|
294
|
+
const end = new Date(sdate.getFullYear(), sdate.getMonth() + 1, 0, 23, 59, 59);
|
|
316
295
|
return {
|
|
317
296
|
startTime: moment(start).format(format),
|
|
318
297
|
stopTime: moment(end).format(format)
|
|
319
298
|
};
|
|
320
299
|
};
|
|
321
|
-
export
|
|
300
|
+
export const _convertLocalToUTC = (date) => {
|
|
322
301
|
return new Date(date).toISOString();
|
|
323
302
|
};
|
|
324
|
-
export
|
|
325
|
-
|
|
303
|
+
export const _convertUTCToLocal = (utcString) => {
|
|
304
|
+
const normalized = /Z$|[+-]\d{2}:\d{2}$/.test(utcString)
|
|
326
305
|
? utcString
|
|
327
306
|
: utcString + "Z";
|
|
328
307
|
return new Date(normalized);
|
|
329
308
|
};
|
|
330
|
-
export function _globalizeDateTime(input, options) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
var dt = typeof input === 'string'
|
|
309
|
+
export function _globalizeDateTime(input, options = {}) {
|
|
310
|
+
const { timeZone = 'UTC', format, toUTC = false } = options;
|
|
311
|
+
let dt = typeof input === 'string'
|
|
334
312
|
? DateTime.fromISO(input)
|
|
335
313
|
: DateTime.fromJSDate(input);
|
|
336
314
|
if (!dt.isValid)
|
|
@@ -338,10 +316,10 @@ export function _globalizeDateTime(input, options) {
|
|
|
338
316
|
// Convert to UTC or specific timezone
|
|
339
317
|
dt = toUTC ? dt.toUTC() : dt.setZone(timeZone);
|
|
340
318
|
// Return formatted string
|
|
341
|
-
|
|
319
|
+
const output = format ? dt.toFormat(format) : dt.toISO();
|
|
342
320
|
return output !== null && output !== void 0 ? output : '';
|
|
343
321
|
}
|
|
344
|
-
|
|
322
|
+
const countryToLocaleMap = {
|
|
345
323
|
US: 'en-US',
|
|
346
324
|
GB: 'en-GB',
|
|
347
325
|
DE: 'de-DE',
|
|
@@ -355,7 +333,7 @@ var countryToLocaleMap = {
|
|
|
355
333
|
KR: 'ko-KR',
|
|
356
334
|
IT: 'it-IT',
|
|
357
335
|
};
|
|
358
|
-
|
|
336
|
+
const formatPresets = {
|
|
359
337
|
DATE_SHORT: DateTime.DATE_SHORT,
|
|
360
338
|
DATE_MED: DateTime.DATE_MED,
|
|
361
339
|
DATE_FULL: DateTime.DATE_FULL,
|
|
@@ -366,11 +344,10 @@ var formatPresets = {
|
|
|
366
344
|
DATETIME_MED: DateTime.DATETIME_MED,
|
|
367
345
|
DATETIME_FULL: DateTime.DATETIME_FULL,
|
|
368
346
|
};
|
|
369
|
-
export function _formatInternationalDate(date, options) {
|
|
370
|
-
if (options === void 0) { options = {}; }
|
|
347
|
+
export function _formatInternationalDate(date, options = {}) {
|
|
371
348
|
try {
|
|
372
349
|
// Convert input to Luxon DateTime with error handling
|
|
373
|
-
|
|
350
|
+
let dt;
|
|
374
351
|
if (DateTime.isDateTime(date)) {
|
|
375
352
|
dt = date;
|
|
376
353
|
}
|
|
@@ -397,7 +374,7 @@ export function _formatInternationalDate(date, options) {
|
|
|
397
374
|
if (options.timezone) {
|
|
398
375
|
dt = dt.setZone(options.timezone);
|
|
399
376
|
if (!dt.isValid) {
|
|
400
|
-
throw new Error(
|
|
377
|
+
throw new Error(`Invalid timezone: ${options.timezone}`);
|
|
401
378
|
}
|
|
402
379
|
}
|
|
403
380
|
else if (options.fallbackTimezone) {
|
|
@@ -409,17 +386,17 @@ export function _formatInternationalDate(date, options) {
|
|
|
409
386
|
dt = dt.setZone(options.fallbackTimezone);
|
|
410
387
|
}
|
|
411
388
|
else {
|
|
412
|
-
throw new Error(
|
|
389
|
+
throw new Error(`Timezone error: ${timezoneError instanceof Error ? timezoneError.message : 'Unknown timezone error'}`);
|
|
413
390
|
}
|
|
414
391
|
}
|
|
415
392
|
// Determine locale with fallback
|
|
416
|
-
|
|
393
|
+
let locale;
|
|
417
394
|
try {
|
|
418
395
|
if (options.locale) {
|
|
419
396
|
locale = options.locale;
|
|
420
397
|
}
|
|
421
398
|
else if (options.country) {
|
|
422
|
-
|
|
399
|
+
const upperCountry = options.country.toUpperCase();
|
|
423
400
|
locale = countryToLocaleMap[upperCountry] || options.fallbackLocale;
|
|
424
401
|
}
|
|
425
402
|
if (locale) {
|
|
@@ -440,7 +417,7 @@ export function _formatInternationalDate(date, options) {
|
|
|
440
417
|
}
|
|
441
418
|
else {
|
|
442
419
|
// Custom format string
|
|
443
|
-
|
|
420
|
+
const formatted = dt.toFormat(options.format);
|
|
444
421
|
if (!formatted) {
|
|
445
422
|
throw new Error('Invalid format string');
|
|
446
423
|
}
|
|
@@ -457,126 +434,117 @@ export function _formatInternationalDate(date, options) {
|
|
|
457
434
|
}
|
|
458
435
|
catch (error) {
|
|
459
436
|
// Provide a meaningful error message
|
|
460
|
-
|
|
437
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown date formatting error';
|
|
461
438
|
if (options.fallbackLocale) {
|
|
462
439
|
// Try to return at least something in the requested locale
|
|
463
440
|
return DateTime.now()
|
|
464
441
|
.setLocale(options.fallbackLocale)
|
|
465
|
-
.toLocaleString(
|
|
442
|
+
.toLocaleString(Object.assign(Object.assign({}, DateTime.DATETIME_MED), (options.fallbackTimezone ? { timeZone: options.fallbackTimezone } : {})));
|
|
466
443
|
}
|
|
467
|
-
throw new Error(
|
|
444
|
+
throw new Error(`Date formatting failed: ${errorMessage}`);
|
|
468
445
|
}
|
|
469
446
|
}
|
|
470
|
-
export
|
|
447
|
+
export const _isEmptyArray = (value) => {
|
|
471
448
|
return Array.isArray(value) && value.length === 0;
|
|
472
449
|
};
|
|
473
|
-
export
|
|
450
|
+
export const _isEmptyObject = (obj) => {
|
|
474
451
|
if (obj == null || typeof obj !== 'object') {
|
|
475
452
|
throw new TypeError('The provided argument is not a valid object.');
|
|
476
453
|
}
|
|
477
454
|
return Object.keys(obj).length === 0;
|
|
478
455
|
};
|
|
479
|
-
export
|
|
456
|
+
export const _isValueInArray = (array, value) => {
|
|
480
457
|
if (!Array.isArray(array)) {
|
|
481
458
|
console.error("The first argument must be an array.");
|
|
482
459
|
return false;
|
|
483
460
|
}
|
|
484
461
|
return array.includes(value);
|
|
485
462
|
};
|
|
486
|
-
export
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
fileSize: fileSize,
|
|
511
|
-
fileExtension: fileExtension,
|
|
512
|
-
}];
|
|
513
|
-
}
|
|
514
|
-
if (!(resultType === 'buffer' || resultType === 'unitarray')) return [3 /*break*/, 2];
|
|
515
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
516
|
-
var reader = new FileReader();
|
|
517
|
-
reader.onload = function (event) {
|
|
518
|
-
var _a;
|
|
519
|
-
var result = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
520
|
-
if (result instanceof ArrayBuffer) {
|
|
521
|
-
resolve(result);
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
reject(new Error('Failed to read file as buffer'));
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
reader.onerror = function () { return reject(new Error('File reading failed')); };
|
|
528
|
-
reader.readAsArrayBuffer(file);
|
|
529
|
-
})];
|
|
530
|
-
case 1:
|
|
531
|
-
buffer = _a.sent();
|
|
532
|
-
return [2 /*return*/, {
|
|
533
|
-
result: resultType === 'unitarray' ? new Uint8Array(buffer) : buffer,
|
|
534
|
-
fileName: fileName,
|
|
535
|
-
fileSize: fileSize,
|
|
536
|
-
fileExtension: fileExtension,
|
|
537
|
-
}];
|
|
538
|
-
case 2:
|
|
539
|
-
if (!(resultType === 'base64')) return [3 /*break*/, 4];
|
|
540
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
541
|
-
var reader = new FileReader();
|
|
542
|
-
reader.onload = function (event) {
|
|
543
|
-
var _a;
|
|
544
|
-
var result = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
545
|
-
if (typeof result === 'string') {
|
|
546
|
-
resolve(result);
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
reject(new Error('Failed to read file as base64'));
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
reader.onerror = function () { return reject(new Error('File reading failed')); };
|
|
553
|
-
reader.readAsDataURL(file);
|
|
554
|
-
})];
|
|
555
|
-
case 3:
|
|
556
|
-
base64 = _a.sent();
|
|
557
|
-
return [2 /*return*/, {
|
|
558
|
-
result: base64,
|
|
559
|
-
fileName: fileName,
|
|
560
|
-
fileSize: fileSize,
|
|
561
|
-
fileExtension: fileExtension,
|
|
562
|
-
}];
|
|
563
|
-
case 4: throw new Error("Unsupported resultType: ".concat(resultType));
|
|
564
|
-
case 5:
|
|
565
|
-
error_1 = _a.sent();
|
|
566
|
-
return [2 /*return*/, {
|
|
567
|
-
error: error_1 instanceof Error ? error_1 : new Error('File processing failed'),
|
|
568
|
-
}];
|
|
569
|
-
case 6: return [2 /*return*/];
|
|
463
|
+
export const _importFile = async (file, resultType) => {
|
|
464
|
+
try {
|
|
465
|
+
if (!file) {
|
|
466
|
+
throw new Error('No file selected');
|
|
467
|
+
}
|
|
468
|
+
const maxFileSize = 10 * 1024 * 1024; // 10MB
|
|
469
|
+
if (file.size > maxFileSize) {
|
|
470
|
+
throw new Error(`File too large (${Math.round(file.size / (1024 * 1024))}MB). Max size is 10MB.`);
|
|
471
|
+
}
|
|
472
|
+
const allowedTypes = ['application/pdf', 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml'];
|
|
473
|
+
if (!allowedTypes.includes(file.type)) {
|
|
474
|
+
throw new Error('Only PDF, JPEG, PNG, GIF, WEBP, and SVG files are allowed');
|
|
475
|
+
}
|
|
476
|
+
// Common metadata
|
|
477
|
+
const fileName = file.name;
|
|
478
|
+
const fileExtension = `.${file.type.split('/')[1]}`;
|
|
479
|
+
const fileSize = `${(file.size / 1024).toFixed(2)} KB`;
|
|
480
|
+
if (resultType === 'file') {
|
|
481
|
+
return {
|
|
482
|
+
result: file,
|
|
483
|
+
fileName,
|
|
484
|
+
fileSize,
|
|
485
|
+
fileExtension,
|
|
486
|
+
};
|
|
570
487
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
488
|
+
if (resultType === 'buffer' || resultType === 'unitarray') {
|
|
489
|
+
const buffer = await new Promise((resolve, reject) => {
|
|
490
|
+
const reader = new FileReader();
|
|
491
|
+
reader.onload = (event) => {
|
|
492
|
+
var _a;
|
|
493
|
+
const result = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
494
|
+
if (result instanceof ArrayBuffer) {
|
|
495
|
+
resolve(result);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
reject(new Error('Failed to read file as buffer'));
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
reader.onerror = () => reject(new Error('File reading failed'));
|
|
502
|
+
reader.readAsArrayBuffer(file);
|
|
503
|
+
});
|
|
504
|
+
return {
|
|
505
|
+
result: resultType === 'unitarray' ? new Uint8Array(buffer) : buffer,
|
|
506
|
+
fileName,
|
|
507
|
+
fileSize,
|
|
508
|
+
fileExtension,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (resultType === 'base64') {
|
|
512
|
+
const base64 = await new Promise((resolve, reject) => {
|
|
513
|
+
const reader = new FileReader();
|
|
514
|
+
reader.onload = (event) => {
|
|
515
|
+
var _a;
|
|
516
|
+
const result = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
517
|
+
if (typeof result === 'string') {
|
|
518
|
+
resolve(result);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
reject(new Error('Failed to read file as base64'));
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
reader.onerror = () => reject(new Error('File reading failed'));
|
|
525
|
+
reader.readAsDataURL(file);
|
|
526
|
+
});
|
|
527
|
+
return {
|
|
528
|
+
result: base64,
|
|
529
|
+
fileName,
|
|
530
|
+
fileSize,
|
|
531
|
+
fileExtension,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
throw new Error(`Unsupported resultType: ${resultType}`);
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
return {
|
|
538
|
+
error: error instanceof Error ? error : new Error('File processing failed'),
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
export const _exportExcel = ({ data, filename, extension = '.xlsx' }) => {
|
|
543
|
+
return new Promise((resolve, reject) => {
|
|
544
|
+
let objectUrl = null;
|
|
545
|
+
let a = null;
|
|
578
546
|
if (!Array.isArray(data) ||
|
|
579
|
-
data.some(
|
|
547
|
+
data.some((item) => typeof item !== 'object' || item === null || Array.isArray(item))) {
|
|
580
548
|
throw new Error('Invalid data: data must be an array of objects');
|
|
581
549
|
}
|
|
582
550
|
try {
|
|
@@ -586,25 +554,25 @@ export var _exportExcel = function (_a) {
|
|
|
586
554
|
if (!extension || typeof extension !== 'string') {
|
|
587
555
|
throw new Error('Extension must be a non-empty string');
|
|
588
556
|
}
|
|
589
|
-
|
|
590
|
-
|
|
557
|
+
const ws = X.utils.json_to_sheet(data);
|
|
558
|
+
const wb = {
|
|
591
559
|
Sheets: { Sheet1: ws },
|
|
592
560
|
SheetNames: ['Sheet1'],
|
|
593
561
|
};
|
|
594
|
-
|
|
562
|
+
const excelBuffer = X.write(wb, {
|
|
595
563
|
bookType: 'xlsx',
|
|
596
564
|
type: 'array',
|
|
597
565
|
});
|
|
598
|
-
|
|
566
|
+
const blob = new Blob([excelBuffer], {
|
|
599
567
|
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
600
568
|
});
|
|
601
569
|
objectUrl = window.URL.createObjectURL(blob);
|
|
602
570
|
a = document.createElement('a');
|
|
603
571
|
a.href = objectUrl;
|
|
604
|
-
a.download =
|
|
572
|
+
a.download = `${filename}${extension}`;
|
|
605
573
|
document.body.appendChild(a);
|
|
606
574
|
a.click();
|
|
607
|
-
setTimeout(
|
|
575
|
+
setTimeout(() => {
|
|
608
576
|
if (a) {
|
|
609
577
|
document.body.removeChild(a);
|
|
610
578
|
}
|
|
@@ -622,7 +590,7 @@ export var _exportExcel = function (_a) {
|
|
|
622
590
|
window.URL.revokeObjectURL(objectUrl);
|
|
623
591
|
}
|
|
624
592
|
if (error instanceof Error) {
|
|
625
|
-
reject(new Error(
|
|
593
|
+
reject(new Error(`Excel export failed: ${error.message}`));
|
|
626
594
|
}
|
|
627
595
|
else {
|
|
628
596
|
reject(new Error('Excel export failed due to an unknown error'));
|
|
@@ -630,90 +598,80 @@ export var _exportExcel = function (_a) {
|
|
|
630
598
|
}
|
|
631
599
|
});
|
|
632
600
|
};
|
|
633
|
-
export
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
601
|
+
export const _importExcel = async (file) => {
|
|
602
|
+
try {
|
|
603
|
+
if (!file) {
|
|
604
|
+
throw new Error('No file selected');
|
|
605
|
+
}
|
|
606
|
+
const maxFileSize = 10 * 1024 * 1024;
|
|
607
|
+
if (file.size > maxFileSize) {
|
|
608
|
+
throw new Error(`File too large (${Math.round(file.size / (1024 * 1024))}MB). Max size is 10MB.`);
|
|
609
|
+
}
|
|
610
|
+
const allowedTypes = [
|
|
611
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
612
|
+
'application/vnd.ms-excel',
|
|
613
|
+
'text/csv',
|
|
614
|
+
];
|
|
615
|
+
if (!allowedTypes.includes(file.type)) {
|
|
616
|
+
throw new Error('Only Excel (.xlsx, .xls) and CSV files are allowed');
|
|
617
|
+
}
|
|
618
|
+
const data = await new Promise((resolve, reject) => {
|
|
619
|
+
const reader = new FileReader();
|
|
620
|
+
reader.onload = (event) => {
|
|
621
|
+
var _a;
|
|
622
|
+
try {
|
|
623
|
+
const buffer = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
624
|
+
if (!buffer)
|
|
625
|
+
throw new Error('Failed to read file');
|
|
626
|
+
const workbook = X.read(buffer, { type: 'buffer' });
|
|
627
|
+
const firstSheetName = workbook.SheetNames[0];
|
|
628
|
+
const firstSheet = workbook.Sheets[firstSheetName];
|
|
629
|
+
const jsonData = X.utils.sheet_to_json(firstSheet, {
|
|
630
|
+
defval: null,
|
|
631
|
+
raw: false,
|
|
632
|
+
});
|
|
633
|
+
resolve(jsonData);
|
|
645
634
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
'application/vnd.ms-excel',
|
|
649
|
-
'text/csv',
|
|
650
|
-
];
|
|
651
|
-
if (!allowedTypes.includes(file.type)) {
|
|
652
|
-
throw new Error('Only Excel (.xlsx, .xls) and CSV files are allowed');
|
|
635
|
+
catch (err) {
|
|
636
|
+
reject(err);
|
|
653
637
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
resolve(jsonData);
|
|
670
|
-
}
|
|
671
|
-
catch (err) {
|
|
672
|
-
reject(err);
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
reader.onerror = function () { return reject(new Error('File reading failed')); };
|
|
676
|
-
reader.readAsArrayBuffer(file);
|
|
677
|
-
})];
|
|
678
|
-
case 1:
|
|
679
|
-
data = _a.sent();
|
|
680
|
-
return [2 /*return*/, { data: data }];
|
|
681
|
-
case 2:
|
|
682
|
-
error_2 = _a.sent();
|
|
683
|
-
return [2 /*return*/, {
|
|
684
|
-
error: error_2 instanceof Error ? error_2 : new Error('File processing failed'),
|
|
685
|
-
}];
|
|
686
|
-
case 3: return [2 /*return*/];
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
}); };
|
|
690
|
-
export var _promise = function (time) { return new Promise(function (res) { return setTimeout(res, time); }); };
|
|
691
|
-
export var _sleep = function (time) { return new Promise(function (res) { return setTimeout(res, time); }); };
|
|
692
|
-
export var _hasItem = function (menuItems, path, key) {
|
|
638
|
+
};
|
|
639
|
+
reader.onerror = () => reject(new Error('File reading failed'));
|
|
640
|
+
reader.readAsArrayBuffer(file);
|
|
641
|
+
});
|
|
642
|
+
return { data };
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
return {
|
|
646
|
+
error: error instanceof Error ? error : new Error('File processing failed'),
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
export const _promise = (time) => new Promise((res) => setTimeout(res, time));
|
|
651
|
+
export const _sleep = (time) => new Promise((res) => setTimeout(res, time));
|
|
652
|
+
export const _hasItem = (menuItems, path, key) => {
|
|
693
653
|
var _a;
|
|
694
654
|
if (!menuItems)
|
|
695
655
|
return {};
|
|
696
|
-
for (
|
|
697
|
-
var item = menuItems_1[_i];
|
|
656
|
+
for (const item of menuItems) {
|
|
698
657
|
if ((item === null || item === void 0 ? void 0 : item.path) === path)
|
|
699
658
|
return key ? item[key] : item;
|
|
700
|
-
|
|
659
|
+
const result = ((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.length) && _hasItem(item.data, path, key);
|
|
701
660
|
if (result)
|
|
702
661
|
return result;
|
|
703
662
|
}
|
|
704
663
|
return null;
|
|
705
664
|
};
|
|
706
|
-
export
|
|
665
|
+
export const _hasElement = (arr, key, value) => {
|
|
707
666
|
var _a;
|
|
708
667
|
if (!arr)
|
|
709
668
|
return {};
|
|
710
|
-
for (
|
|
711
|
-
var ele = arr_1[_i];
|
|
669
|
+
for (const ele of arr) {
|
|
712
670
|
if (ele[key] === value) {
|
|
713
671
|
return ele;
|
|
714
672
|
}
|
|
715
673
|
if ((_a = ele === null || ele === void 0 ? void 0 : ele.data) === null || _a === void 0 ? void 0 : _a.length) {
|
|
716
|
-
|
|
674
|
+
const result = _hasElement(ele.data, key, value);
|
|
717
675
|
if (result) {
|
|
718
676
|
return result;
|
|
719
677
|
}
|
|
@@ -721,15 +679,14 @@ export var _hasElement = function (arr, key, value) {
|
|
|
721
679
|
}
|
|
722
680
|
return null;
|
|
723
681
|
};
|
|
724
|
-
export
|
|
682
|
+
export const _flattenArray = (arr) => {
|
|
725
683
|
var _a;
|
|
726
684
|
if (!arr)
|
|
727
685
|
return [];
|
|
728
|
-
|
|
729
|
-
for (
|
|
730
|
-
var item = arr_2[_i];
|
|
686
|
+
let result = [];
|
|
687
|
+
for (const item of arr) {
|
|
731
688
|
if ((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.length) {
|
|
732
|
-
result.push
|
|
689
|
+
result.push(..._flattenArray(item.data));
|
|
733
690
|
}
|
|
734
691
|
else {
|
|
735
692
|
result.push(item);
|
|
@@ -737,15 +694,13 @@ export var _flattenArray = function (arr) {
|
|
|
737
694
|
}
|
|
738
695
|
return result;
|
|
739
696
|
};
|
|
740
|
-
export
|
|
741
|
-
if (key === void 0) { key = "data"; }
|
|
697
|
+
export const _flattenArrayByKey = (arr, key = "data") => {
|
|
742
698
|
if (!arr)
|
|
743
699
|
return [];
|
|
744
|
-
|
|
745
|
-
for (
|
|
746
|
-
var item = arr_3[_i];
|
|
700
|
+
const result = [];
|
|
701
|
+
for (const item of arr) {
|
|
747
702
|
if (item && Array.isArray(item[key]) && item[key].length) {
|
|
748
|
-
result.push
|
|
703
|
+
result.push(..._flattenArrayByKey(item[key], key));
|
|
749
704
|
}
|
|
750
705
|
else {
|
|
751
706
|
result.push(item);
|
|
@@ -753,39 +708,34 @@ export var _flattenArrayByKey = function (arr, key) {
|
|
|
753
708
|
}
|
|
754
709
|
return result;
|
|
755
710
|
};
|
|
756
|
-
export
|
|
757
|
-
return routes.find(
|
|
711
|
+
export const _findExactRoute = (routes, pathname) => {
|
|
712
|
+
return routes.find((r) => pathname === r.path);
|
|
758
713
|
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
var key = action.type;
|
|
714
|
+
const genericActionHandler = (state, action) => {
|
|
715
|
+
const key = action.type;
|
|
762
716
|
if (Object.prototype.hasOwnProperty.call(state, key)) {
|
|
763
|
-
return
|
|
717
|
+
return Object.assign(Object.assign({}, state), { [key]: action.payload });
|
|
764
718
|
}
|
|
765
719
|
return state;
|
|
766
720
|
};
|
|
767
|
-
export
|
|
768
|
-
return
|
|
769
|
-
if (state === void 0) { state = initialState; }
|
|
770
|
-
return genericActionHandler(state, action);
|
|
771
|
-
};
|
|
721
|
+
export const _dynamicReducer = (initialState) => {
|
|
722
|
+
return (state = initialState, action) => genericActionHandler(state, action);
|
|
772
723
|
};
|
|
773
|
-
export
|
|
774
|
-
if (state === void 0) { state = initialState; }
|
|
724
|
+
export const _genericReducer = (initialState, actions) => (state = initialState, action) => {
|
|
775
725
|
if (actions[action.type]) {
|
|
776
726
|
return actions[action.type](state, action);
|
|
777
727
|
}
|
|
778
728
|
return state;
|
|
779
|
-
};
|
|
780
|
-
export
|
|
729
|
+
};
|
|
730
|
+
export const _thousandSeparator = (num) => {
|
|
781
731
|
try {
|
|
782
732
|
if (typeof num !== "number" || isNaN(num)) {
|
|
783
733
|
console.error("The value must be a valid number.");
|
|
784
734
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
735
|
+
const parts = num.toFixed(2).split(".");
|
|
736
|
+
const numberPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
737
|
+
const decimalPart = `.${parts[1]}`;
|
|
738
|
+
const twoDecimalPart = `.${parts[1].slice(0, 2)}`;
|
|
789
739
|
return {
|
|
790
740
|
allDecimal: numberPart + decimalPart,
|
|
791
741
|
twoDecimal: numberPart + twoDecimalPart,
|
|
@@ -795,34 +745,33 @@ export var _thousandSeparator = function (num) {
|
|
|
795
745
|
return { allDecimal: "0.00", twoDecimal: "0.00" }; // Safe fallback value
|
|
796
746
|
}
|
|
797
747
|
};
|
|
798
|
-
export
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
return
|
|
748
|
+
export const _getFinancialYear = () => {
|
|
749
|
+
const currentDate = new Date();
|
|
750
|
+
const currentYear = currentDate.getFullYear();
|
|
751
|
+
const month = currentDate.getMonth();
|
|
752
|
+
const startYear = month >= 3 ? currentYear : currentYear - 1;
|
|
753
|
+
const endYear = startYear + 1;
|
|
754
|
+
return `${startYear}-${endYear}`;
|
|
805
755
|
};
|
|
806
|
-
export
|
|
807
|
-
var action = _a.action, type = _a.type, key = _a.key, value = _a.value;
|
|
756
|
+
export const _getStorage = ({ action, type, key, value }) => {
|
|
808
757
|
if (typeof window === 'undefined') {
|
|
809
758
|
return null;
|
|
810
759
|
}
|
|
811
760
|
if (type !== 'local' && type !== 'session') {
|
|
812
761
|
throw new Error("Invalid storage type. Use 'local' or 'session'.");
|
|
813
762
|
}
|
|
814
|
-
|
|
815
|
-
|
|
763
|
+
let result = null;
|
|
764
|
+
const storage = type === 'local' ? localStorage : sessionStorage;
|
|
816
765
|
try {
|
|
817
766
|
if (action === 'CLEAR') {
|
|
818
767
|
storage.clear();
|
|
819
768
|
}
|
|
820
769
|
else if (action === 'SET' && value !== undefined && value !== null) {
|
|
821
|
-
|
|
770
|
+
const storageValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
822
771
|
storage.setItem(key, storageValue);
|
|
823
772
|
}
|
|
824
773
|
else if (action === 'GET' && key) {
|
|
825
|
-
|
|
774
|
+
const storedValue = storage.getItem(key);
|
|
826
775
|
if (storedValue !== null) {
|
|
827
776
|
try {
|
|
828
777
|
result = JSON.parse(storedValue);
|
|
@@ -842,8 +791,8 @@ export var _getStorage = function (_a) {
|
|
|
842
791
|
}
|
|
843
792
|
return result;
|
|
844
793
|
};
|
|
845
|
-
export
|
|
846
|
-
export
|
|
794
|
+
export const _deepClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
795
|
+
export const _getCookie = (name) => {
|
|
847
796
|
var _a, _b;
|
|
848
797
|
try {
|
|
849
798
|
if (!name) {
|
|
@@ -854,8 +803,8 @@ export var _getCookie = function (name) {
|
|
|
854
803
|
console.error("document is not available (probably running in a non-browser environment).");
|
|
855
804
|
return null;
|
|
856
805
|
}
|
|
857
|
-
|
|
858
|
-
|
|
806
|
+
const value = `; ${document.cookie}`;
|
|
807
|
+
const parts = value.split(`; ${name}=`);
|
|
859
808
|
if (parts.length === 2) {
|
|
860
809
|
return (_b = (_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.split(";").shift()) !== null && _b !== void 0 ? _b : null;
|
|
861
810
|
}
|
|
@@ -866,13 +815,13 @@ export var _getCookie = function (name) {
|
|
|
866
815
|
return null;
|
|
867
816
|
}
|
|
868
817
|
};
|
|
869
|
-
export
|
|
870
|
-
|
|
818
|
+
export const _setCookie = (name, value, days) => {
|
|
819
|
+
const date = new Date();
|
|
871
820
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
872
|
-
|
|
873
|
-
document.cookie =
|
|
821
|
+
const expires = `expires=${date.toUTCString()}`;
|
|
822
|
+
document.cookie = `${name}=${value}; ${expires}; path=/`;
|
|
874
823
|
};
|
|
875
|
-
export
|
|
824
|
+
export const _mergeObjects = (obj1, obj2) => {
|
|
876
825
|
if (typeof obj1 !== "object" || obj1 === null) {
|
|
877
826
|
console.error("First argument must be a non-null object.");
|
|
878
827
|
return obj2;
|
|
@@ -881,41 +830,40 @@ export var _mergeObjects = function (obj1, obj2) {
|
|
|
881
830
|
console.error("Second argument must be a non-null object.");
|
|
882
831
|
return obj1;
|
|
883
832
|
}
|
|
884
|
-
return
|
|
833
|
+
return Object.assign(Object.assign({}, obj1), obj2);
|
|
885
834
|
};
|
|
886
|
-
export
|
|
887
|
-
return Object.keys(obj).map(
|
|
835
|
+
export const _mapObject = (obj, callback) => {
|
|
836
|
+
return Object.keys(obj).map(key => callback(key, obj[key]));
|
|
888
837
|
};
|
|
889
|
-
export
|
|
838
|
+
export const _isEqual = (value1, value2) => {
|
|
890
839
|
if (value1 == null || value2 == null) {
|
|
891
840
|
console.error("One or both values are null or undefined.");
|
|
892
841
|
return false;
|
|
893
842
|
}
|
|
894
843
|
return JSON.stringify(value1) === JSON.stringify(value2);
|
|
895
844
|
};
|
|
896
|
-
export
|
|
845
|
+
export const _capitalize = (str) => {
|
|
897
846
|
if (!str) {
|
|
898
847
|
console.error("Empty string.");
|
|
899
848
|
return "";
|
|
900
849
|
}
|
|
901
850
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
902
851
|
};
|
|
903
|
-
export
|
|
904
|
-
|
|
905
|
-
return new Intl.NumberFormat('en-US', { style: 'currency', currency: currency }).format(amount);
|
|
852
|
+
export const _convertToCurrency = (amount, currency = 'USD') => {
|
|
853
|
+
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount);
|
|
906
854
|
};
|
|
907
|
-
export
|
|
908
|
-
|
|
855
|
+
export const _getBrowserInfo = () => {
|
|
856
|
+
const { userAgent } = navigator;
|
|
909
857
|
if (userAgent.includes('Chrome'))
|
|
910
858
|
return 'Chrome';
|
|
911
859
|
if (userAgent.includes('Firefox'))
|
|
912
860
|
return 'Firefox';
|
|
913
861
|
return 'Unknown';
|
|
914
862
|
};
|
|
915
|
-
export
|
|
863
|
+
export const _isMobile = () => {
|
|
916
864
|
return /Mobi|Android/i.test(navigator.userAgent);
|
|
917
865
|
};
|
|
918
|
-
export
|
|
866
|
+
export const _parseJSON = (json) => {
|
|
919
867
|
try {
|
|
920
868
|
return JSON.parse(json);
|
|
921
869
|
}
|
|
@@ -924,7 +872,7 @@ export var _parseJSON = function (json) {
|
|
|
924
872
|
return null;
|
|
925
873
|
}
|
|
926
874
|
};
|
|
927
|
-
export
|
|
875
|
+
export const _stringifyJSON = (value) => {
|
|
928
876
|
try {
|
|
929
877
|
return JSON.stringify(value);
|
|
930
878
|
}
|