sf-i-events 1.0.856 → 1.0.857

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/util.js CHANGED
@@ -1,431 +1,431 @@
1
- const validateName = (name) => {
2
- if ((name + "").length > 2) {
3
- return true;
4
- }
5
- return false;
6
- };
7
- function createDiagonalPattern1(color) {
8
- // create a 10x10 px canvas for the pattern's base shape
9
- let shape = document.createElement('canvas');
10
- shape.width = 10;
11
- shape.height = 10;
12
- // get the context for drawing
13
- let c = shape.getContext('2d');
14
- // draw 1st line of the shape
15
- c.strokeStyle = color;
16
- c.lineWidth = 3;
17
- c.beginPath();
18
- c.moveTo(2, 0);
19
- c.lineTo(10, 8);
20
- c.stroke();
21
- // draw 2nd line of the shape
22
- c.beginPath();
23
- c.moveTo(2, 10);
24
- c.lineTo(0, 8);
25
- c.stroke();
26
- // create the pattern from the shape
27
- return c.createPattern(shape, 'repeat');
28
- }
29
- // function createDiagonalPattern2(color: string) {
30
- // let shape = document.createElement('canvas')
31
- // shape.width = 10
32
- // shape.height = 10
33
- // // get the context for drawing
34
- // let c = shape.getContext('2d')
35
- // // draw 1st line of the shape
36
- // c!.beginPath();
37
- // c!.rect(2, 2, 8, 8)
38
- // c!.fillStyle = color;
39
- // c!.fill();
40
- // // create the pattern from the shape
41
- // return c!.createPattern(shape, 'repeat')
42
- // }
43
- function createDiagonalPattern2(color) {
44
- // create a 10x10 px canvas for the pattern's base shape
45
- let shape = document.createElement('canvas');
46
- shape.width = 10;
47
- shape.height = 10;
48
- // get the context for drawing
49
- let c = shape.getContext('2d');
50
- // draw 1st line of the shape
51
- c.beginPath();
52
- c.rect(1, 1, 9, 9);
53
- c.fillStyle = color;
54
- c.fill();
55
- c.lineWidth = 1;
56
- c.strokeStyle = color;
57
- c.stroke();
58
- // create the pattern from the shape
59
- // create tick
60
- //draw tick
61
- c.beginPath();
62
- c.moveTo(2, 2);
63
- c.lineTo(8, 8);
64
- c.moveTo(2, 8);
65
- c.lineTo(8, 2);
66
- c.lineWidth = 2;
67
- c.strokeStyle = '#fff';
68
- c.stroke();
69
- return c.createPattern(shape, 'repeat');
70
- }
71
- function createDiagonalPattern3(color) {
72
- // create a 10x10 px canvas for the pattern's base shape
73
- let shape = document.createElement('canvas');
74
- shape.width = 10;
75
- shape.height = 10;
76
- // get the context for drawing
77
- let c = shape.getContext('2d');
78
- // draw 1st line of the shape
79
- c.beginPath();
80
- c.rect(1, 1, 9, 9);
81
- c.fillStyle = color;
82
- c.fill();
83
- c.lineWidth = 1;
84
- c.strokeStyle = color;
85
- c.stroke();
86
- // create the pattern from the shape
87
- // create tick
88
- //draw tick
89
- c.beginPath();
90
- c.moveTo(2, 5);
91
- c.lineTo(4, 7);
92
- c.lineTo(8, 2);
93
- c.lineWidth = 2;
94
- c.strokeStyle = '#fff';
95
- c.stroke();
96
- return c.createPattern(shape, 'repeat');
97
- }
98
- // function createDiagonalPattern3(color: string) {
99
- // // create a 10x10 px canvas for the pattern's base shape
100
- // let shape = document.createElement('canvas')
101
- // shape.width = 14
102
- // shape.height = 14
103
- // // get the context for drawing
104
- // let c = shape.getContext('2d')
105
- // // draw 1st line of the shape
106
- // c!.beginPath();
107
- // c!.arc(7, 7, 6, 0, 2 * Math.PI, false);
108
- // c!.fillStyle = color;
109
- // c!.fill();
110
- // c!.lineWidth = 1;
111
- // c!.strokeStyle = color;
112
- // c!.stroke();
113
- // // create the pattern from the shape
114
- // // create tick
115
- // //draw tick
116
- // c!.beginPath();
117
- // c!.moveTo(4,6);
118
- // c!.lineTo(6,9);
119
- // c!.lineTo(10,4);
120
- // c!.lineWidth = 2;
121
- // c!.strokeStyle = '#fff';
122
- // c!.stroke();
123
- // return c!.createPattern(shape, 'repeat')
124
- // }
125
- // function createDiagonalPattern3(color: string) {
126
- // // create a 10x10 px canvas for the pattern's base shape
127
- // let shape = document.createElement('canvas')
128
- // shape.width = 10
129
- // shape.height = 10
130
- // // get the context for drawing
131
- // let c = shape.getContext('2d')
132
- // // draw 1st line of the shape
133
- // c!.beginPath();
134
- // c!.arc(5, 5, 4, 0, 2 * Math.PI, false);
135
- // c!.fillStyle = color;
136
- // c!.fill();
137
- // c!.lineWidth = 1;
138
- // c!.strokeStyle = color;
139
- // c!.stroke();
140
- // // create the pattern from the shape
141
- // return c!.createPattern(shape, 'repeat')
142
- // }
143
- const timeSince = (date) => {
144
- var seconds = Math.floor((new Date().getTime() - date) / 1000);
145
- if (seconds > 0) {
146
- var interval = seconds / 31536000;
147
- if (interval > 1) {
148
- return Math.floor(interval) + " years ago";
149
- }
150
- interval = seconds / 2592000;
151
- if (interval > 1) {
152
- return Math.floor(interval) + " months ago";
153
- }
154
- interval = seconds / 86400;
155
- if (interval > 1) {
156
- return Math.floor(interval) + " days ago";
157
- }
158
- interval = seconds / 3600;
159
- if (interval > 1) {
160
- return Math.floor(interval) + " hours ago";
161
- }
162
- interval = seconds / 60;
163
- if (interval > 1) {
164
- return Math.floor(interval) + " minutes ago";
165
- }
166
- return Math.floor(seconds) + " seconds ago";
167
- }
168
- else {
169
- var interval = Math.abs(seconds) / 31536000;
170
- console.log('timesince', seconds);
171
- console.log('interval year', interval);
172
- if (interval > 1) {
173
- return Math.floor(interval) + " years later";
174
- }
175
- interval = Math.abs(seconds) / 2592000;
176
- console.log('interval months', interval);
177
- if (interval > 1) {
178
- return Math.floor(interval) + " months later";
179
- }
180
- interval = Math.abs(seconds) / 86400;
181
- console.log('interval days', interval);
182
- if (interval > 1) {
183
- return Math.floor(interval) + " days later";
184
- }
185
- interval = Math.abs(seconds) / 3600;
186
- console.log('interval hours', interval);
187
- if (interval > 1) {
188
- return Math.floor(interval) + " hours later";
189
- }
190
- interval = Math.abs(seconds) / 60;
191
- if (interval > 1) {
192
- return Math.floor(interval) + " minutes later";
193
- }
194
- return Math.floor(Math.abs(seconds)) + " seconds";
195
- }
196
- };
197
- function readCookie(key) {
198
- let name = key + "=";
199
- let decodedCookie = decodeURIComponent(document.cookie);
200
- let ca = decodedCookie.split(';');
201
- for (let i = 0; i < ca.length; i++) {
202
- let c = ca[i];
203
- while (c.charAt(0) == ' ') {
204
- c = c.substring(1);
205
- }
206
- if (c.indexOf(name) == 0) {
207
- return c.substring(name.length, c.length);
208
- }
209
- }
210
- return "";
211
- }
212
- async function callApi(url, data, authorization) {
213
- return new Promise((resolve) => {
214
- const jsonData = JSON.stringify(data);
215
- var xhr = new XMLHttpRequest();
216
- xhr.addEventListener("readystatechange", () => {
217
- if (xhr != null) {
218
- if (xhr.readyState === 4) {
219
- resolve(xhr);
220
- }
221
- }
222
- });
223
- xhr.open("POST", url);
224
- xhr.timeout = 1800000;
225
- xhr.setRequestHeader("Content-Type", "application/json");
226
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
227
- if (authorization != null) {
228
- xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
229
- }
230
- xhr.send(jsonData);
231
- return xhr;
232
- });
233
- }
234
- async function callApiPresignedDelete(url) {
235
- return new Promise((resolve) => {
236
- var xhr = new XMLHttpRequest();
237
- xhr.addEventListener("readystatechange", () => {
238
- if (xhr != null) {
239
- if (xhr.readyState === 4) {
240
- resolve(xhr);
241
- }
242
- }
243
- });
244
- xhr.open("DELETE", url);
245
- xhr.timeout = 1800000;
246
- xhr.setRequestHeader("Content-Type", "application/json");
247
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
248
- xhr.send(null);
249
- return xhr;
250
- });
251
- }
252
- async function callApiPresignedGet(url) {
253
- return new Promise((resolve) => {
254
- var xhr = new XMLHttpRequest();
255
- xhr.addEventListener("readystatechange", () => {
256
- if (xhr != null) {
257
- if (xhr.readyState === 4) {
258
- resolve(xhr);
259
- }
260
- }
261
- });
262
- xhr.open("GET", url);
263
- xhr.timeout = 1800000;
264
- xhr.setRequestHeader("Content-Type", "application/json");
265
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
266
- xhr.send(null);
267
- return xhr;
268
- });
269
- }
270
- async function callApiPresigned(url, data) {
271
- return new Promise((resolve) => {
272
- const jsonData = JSON.stringify(data);
273
- var xhr = new XMLHttpRequest();
274
- xhr.addEventListener("readystatechange", () => {
275
- if (xhr != null) {
276
- if (xhr.readyState === 4) {
277
- resolve(xhr);
278
- }
279
- }
280
- });
281
- xhr.open("PUT", url);
282
- xhr.timeout = 1800000;
283
- xhr.setRequestHeader("Content-Type", "application/json");
284
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
285
- xhr.send(jsonData);
286
- return xhr;
287
- });
288
- }
289
- function getRandomColor() {
290
- var letters = '0123456789ABCDEF';
291
- var color = '#';
292
- for (var i = 0; i < 6; i++) {
293
- color += letters[Math.floor(Math.random() * 16)];
294
- }
295
- return color;
296
- }
297
- function isInteger(value) {
298
- return /^-?\d+$/.test(value);
299
- }
300
- function clearListeners(old_element) {
301
- var _a;
302
- var new_element = old_element.cloneNode(true);
303
- (_a = old_element.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(new_element, old_element);
304
- return new_element;
305
- }
306
- function jsonObjectToHtml(json) {
307
- var html = '';
308
- for (var i = 0; i < Object.keys(json).length; i++) {
309
- var key = Object.keys(json)[i];
310
- html += '<div>';
311
- html += ('<span style="margin-left: 0px; padding-left: 0px">' + key + ':</span>&nbsp;');
312
- html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g, '') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
313
- html += '</div>';
314
- }
315
- return html;
316
- }
317
- function convertToCSV(arr) {
318
- const array = [Object.keys(arr[0])].concat(arr);
319
- let fieldsArr = Object.keys(arr[0]);
320
- return array.map((it, index) => {
321
- var _a;
322
- let strIt = "";
323
- for (let [i, objkey] of Object.keys(it).entries()) {
324
- if (index == 0) {
325
- strIt += "\"" + it[objkey].replace(/"/g, "\"\"") + "\"";
326
- }
327
- else {
328
- strIt += "\"" + JSON.stringify((_a = it[fieldsArr[i]]) !== null && _a !== void 0 ? _a : "").replace(/"/g, "\"\"") + "\"";
329
- }
330
- if (i < (Object.keys(it).length - 1)) {
331
- strIt += ",";
332
- }
333
- }
334
- return strIt;
335
- }).join('\n');
336
- }
337
- function parseCsv(csv) {
338
- const re = /(,|\r?\n|\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\r\n]*))/gi;
339
- const result = [[]];
340
- let matches;
341
- while ((matches = re.exec(csv))) {
342
- if (matches[1].length && matches[1] !== ',')
343
- result.push([]);
344
- result[result.length - 1].push(matches[2] !== undefined ? matches[2].replace(/""/g, '"') : matches[3]);
345
- }
346
- console.log('csv arr result', result, result.length);
347
- let csvResult = arrayToObject(result);
348
- return csvResult;
349
- }
350
- function arrayToObject(csvArray) {
351
- //Take the first line (headers) from the array and remove it from the array.
352
- const headers = csvArray.shift();
353
- // Iterate through the rows and reduce each column to an object
354
- return csvArray.filter((row) => {
355
- console.log('csv object keys lngth', Object.keys(row).length);
356
- return Object.keys(row).length > 1;
357
- }).map((row, index) => {
358
- return headers.reduce((acc, currentHeader, i) => {
359
- console.log('parsing row', row[i], index);
360
- return ((currentHeader.indexOf('cols_') >= 0 || currentHeader == '') ? acc : ((row[i] != '' && row[i] != null) ? { ...acc, ...{ [currentHeader]: JSON.parse(row[i] == "TRUE" ? "true" : row[i]) } } : acc));
361
- }, {});
362
- });
363
- }
364
- function titleCase(str) {
365
- var splitStr = str.toLowerCase().split(' ');
366
- for (var i = 0; i < splitStr.length; i++) {
367
- // You do not need to check if i is larger than splitStr length, as your for does that for you
368
- // Assign it back to the array
369
- splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
370
- }
371
- // Directly return the joined string
372
- return splitStr.join(' ');
373
- }
374
- function alphabeticalSort(arr) {
375
- let arrSorted = arr.sort((a, b) => {
376
- return a.trim().toLowerCase().localeCompare(b.trim().toLowerCase());
377
- });
378
- return arrSorted;
379
- }
380
- function percentageString(val, valTotal) {
381
- if (valTotal == 0) {
382
- return "";
383
- }
384
- let num = (100 * val) / valTotal;
385
- return " (" + (Math.round((num + Number.EPSILON) * 100) / 100) + "%)";
386
- }
387
- function getCurrentFiscal() {
388
- let date = new Date();
389
- if (date.getMonth() < 4) {
390
- return (date.getFullYear() - 1);
391
- }
392
- return date.getFullYear();
393
- }
394
- function getDateTimeStrings(unixTimestamp) {
395
- // Convert to milliseconds if the timestamp is in seconds
396
- if (unixTimestamp.toString().length === 10) {
397
- unixTimestamp *= 1000;
398
- }
399
- const date = new Date(unixTimestamp);
400
- const options = {
401
- year: 'numeric',
402
- month: '2-digit',
403
- day: '2-digit',
404
- hour: '2-digit',
405
- minute: '2-digit',
406
- second: '2-digit',
407
- hour12: false,
408
- };
409
- const estFormatter = new Intl.DateTimeFormat('en-US', {
410
- ...options,
411
- timeZone: 'America/New_York',
412
- });
413
- const istFormatter = new Intl.DateTimeFormat('en-IN', {
414
- ...options,
415
- timeZone: 'Asia/Kolkata',
416
- });
417
- const [estDate, estTime] = estFormatter.format(date).split(', ');
418
- const [istDate, istTime] = istFormatter.format(date).split(', ');
419
- return `${estDate} ${estTime} EST, ${istDate} ${istTime} IST`;
420
- }
421
- function getUsermap() {
422
- var _a;
423
- let userinfo = JSON.parse((_a = localStorage.getItem('userinfo')) !== null && _a !== void 0 ? _a : "{}");
424
- let userMapHome = JSON.parse(JSON.parse((userinfo.user.usermap.S).replace(/_QUOTES_/g, "\\\"")));
425
- return userMapHome;
426
- }
427
- const exportFunctions = {
428
- callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap
429
- };
430
- export default exportFunctions;
1
+ const validateName = (name) => {
2
+ if ((name + "").length > 2) {
3
+ return true;
4
+ }
5
+ return false;
6
+ };
7
+ function createDiagonalPattern1(color) {
8
+ // create a 10x10 px canvas for the pattern's base shape
9
+ let shape = document.createElement('canvas');
10
+ shape.width = 10;
11
+ shape.height = 10;
12
+ // get the context for drawing
13
+ let c = shape.getContext('2d');
14
+ // draw 1st line of the shape
15
+ c.strokeStyle = color;
16
+ c.lineWidth = 3;
17
+ c.beginPath();
18
+ c.moveTo(2, 0);
19
+ c.lineTo(10, 8);
20
+ c.stroke();
21
+ // draw 2nd line of the shape
22
+ c.beginPath();
23
+ c.moveTo(2, 10);
24
+ c.lineTo(0, 8);
25
+ c.stroke();
26
+ // create the pattern from the shape
27
+ return c.createPattern(shape, 'repeat');
28
+ }
29
+ // function createDiagonalPattern2(color: string) {
30
+ // let shape = document.createElement('canvas')
31
+ // shape.width = 10
32
+ // shape.height = 10
33
+ // // get the context for drawing
34
+ // let c = shape.getContext('2d')
35
+ // // draw 1st line of the shape
36
+ // c!.beginPath();
37
+ // c!.rect(2, 2, 8, 8)
38
+ // c!.fillStyle = color;
39
+ // c!.fill();
40
+ // // create the pattern from the shape
41
+ // return c!.createPattern(shape, 'repeat')
42
+ // }
43
+ function createDiagonalPattern2(color) {
44
+ // create a 10x10 px canvas for the pattern's base shape
45
+ let shape = document.createElement('canvas');
46
+ shape.width = 10;
47
+ shape.height = 10;
48
+ // get the context for drawing
49
+ let c = shape.getContext('2d');
50
+ // draw 1st line of the shape
51
+ c.beginPath();
52
+ c.rect(1, 1, 9, 9);
53
+ c.fillStyle = color;
54
+ c.fill();
55
+ c.lineWidth = 1;
56
+ c.strokeStyle = color;
57
+ c.stroke();
58
+ // create the pattern from the shape
59
+ // create tick
60
+ //draw tick
61
+ c.beginPath();
62
+ c.moveTo(2, 2);
63
+ c.lineTo(8, 8);
64
+ c.moveTo(2, 8);
65
+ c.lineTo(8, 2);
66
+ c.lineWidth = 2;
67
+ c.strokeStyle = '#fff';
68
+ c.stroke();
69
+ return c.createPattern(shape, 'repeat');
70
+ }
71
+ function createDiagonalPattern3(color) {
72
+ // create a 10x10 px canvas for the pattern's base shape
73
+ let shape = document.createElement('canvas');
74
+ shape.width = 10;
75
+ shape.height = 10;
76
+ // get the context for drawing
77
+ let c = shape.getContext('2d');
78
+ // draw 1st line of the shape
79
+ c.beginPath();
80
+ c.rect(1, 1, 9, 9);
81
+ c.fillStyle = color;
82
+ c.fill();
83
+ c.lineWidth = 1;
84
+ c.strokeStyle = color;
85
+ c.stroke();
86
+ // create the pattern from the shape
87
+ // create tick
88
+ //draw tick
89
+ c.beginPath();
90
+ c.moveTo(2, 5);
91
+ c.lineTo(4, 7);
92
+ c.lineTo(8, 2);
93
+ c.lineWidth = 2;
94
+ c.strokeStyle = '#fff';
95
+ c.stroke();
96
+ return c.createPattern(shape, 'repeat');
97
+ }
98
+ // function createDiagonalPattern3(color: string) {
99
+ // // create a 10x10 px canvas for the pattern's base shape
100
+ // let shape = document.createElement('canvas')
101
+ // shape.width = 14
102
+ // shape.height = 14
103
+ // // get the context for drawing
104
+ // let c = shape.getContext('2d')
105
+ // // draw 1st line of the shape
106
+ // c!.beginPath();
107
+ // c!.arc(7, 7, 6, 0, 2 * Math.PI, false);
108
+ // c!.fillStyle = color;
109
+ // c!.fill();
110
+ // c!.lineWidth = 1;
111
+ // c!.strokeStyle = color;
112
+ // c!.stroke();
113
+ // // create the pattern from the shape
114
+ // // create tick
115
+ // //draw tick
116
+ // c!.beginPath();
117
+ // c!.moveTo(4,6);
118
+ // c!.lineTo(6,9);
119
+ // c!.lineTo(10,4);
120
+ // c!.lineWidth = 2;
121
+ // c!.strokeStyle = '#fff';
122
+ // c!.stroke();
123
+ // return c!.createPattern(shape, 'repeat')
124
+ // }
125
+ // function createDiagonalPattern3(color: string) {
126
+ // // create a 10x10 px canvas for the pattern's base shape
127
+ // let shape = document.createElement('canvas')
128
+ // shape.width = 10
129
+ // shape.height = 10
130
+ // // get the context for drawing
131
+ // let c = shape.getContext('2d')
132
+ // // draw 1st line of the shape
133
+ // c!.beginPath();
134
+ // c!.arc(5, 5, 4, 0, 2 * Math.PI, false);
135
+ // c!.fillStyle = color;
136
+ // c!.fill();
137
+ // c!.lineWidth = 1;
138
+ // c!.strokeStyle = color;
139
+ // c!.stroke();
140
+ // // create the pattern from the shape
141
+ // return c!.createPattern(shape, 'repeat')
142
+ // }
143
+ const timeSince = (date) => {
144
+ var seconds = Math.floor((new Date().getTime() - date) / 1000);
145
+ if (seconds > 0) {
146
+ var interval = seconds / 31536000;
147
+ if (interval > 1) {
148
+ return Math.floor(interval) + " years ago";
149
+ }
150
+ interval = seconds / 2592000;
151
+ if (interval > 1) {
152
+ return Math.floor(interval) + " months ago";
153
+ }
154
+ interval = seconds / 86400;
155
+ if (interval > 1) {
156
+ return Math.floor(interval) + " days ago";
157
+ }
158
+ interval = seconds / 3600;
159
+ if (interval > 1) {
160
+ return Math.floor(interval) + " hours ago";
161
+ }
162
+ interval = seconds / 60;
163
+ if (interval > 1) {
164
+ return Math.floor(interval) + " minutes ago";
165
+ }
166
+ return Math.floor(seconds) + " seconds ago";
167
+ }
168
+ else {
169
+ var interval = Math.abs(seconds) / 31536000;
170
+ console.log('timesince', seconds);
171
+ console.log('interval year', interval);
172
+ if (interval > 1) {
173
+ return Math.floor(interval) + " years later";
174
+ }
175
+ interval = Math.abs(seconds) / 2592000;
176
+ console.log('interval months', interval);
177
+ if (interval > 1) {
178
+ return Math.floor(interval) + " months later";
179
+ }
180
+ interval = Math.abs(seconds) / 86400;
181
+ console.log('interval days', interval);
182
+ if (interval > 1) {
183
+ return Math.floor(interval) + " days later";
184
+ }
185
+ interval = Math.abs(seconds) / 3600;
186
+ console.log('interval hours', interval);
187
+ if (interval > 1) {
188
+ return Math.floor(interval) + " hours later";
189
+ }
190
+ interval = Math.abs(seconds) / 60;
191
+ if (interval > 1) {
192
+ return Math.floor(interval) + " minutes later";
193
+ }
194
+ return Math.floor(Math.abs(seconds)) + " seconds";
195
+ }
196
+ };
197
+ function readCookie(key) {
198
+ let name = key + "=";
199
+ let decodedCookie = decodeURIComponent(document.cookie);
200
+ let ca = decodedCookie.split(';');
201
+ for (let i = 0; i < ca.length; i++) {
202
+ let c = ca[i];
203
+ while (c.charAt(0) == ' ') {
204
+ c = c.substring(1);
205
+ }
206
+ if (c.indexOf(name) == 0) {
207
+ return c.substring(name.length, c.length);
208
+ }
209
+ }
210
+ return "";
211
+ }
212
+ async function callApi(url, data, authorization) {
213
+ return new Promise((resolve) => {
214
+ const jsonData = JSON.stringify(data);
215
+ var xhr = new XMLHttpRequest();
216
+ xhr.addEventListener("readystatechange", () => {
217
+ if (xhr != null) {
218
+ if (xhr.readyState === 4) {
219
+ resolve(xhr);
220
+ }
221
+ }
222
+ });
223
+ xhr.open("POST", url);
224
+ xhr.timeout = 1800000;
225
+ xhr.setRequestHeader("Content-Type", "application/json");
226
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
227
+ if (authorization != null) {
228
+ xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
229
+ }
230
+ xhr.send(jsonData);
231
+ return xhr;
232
+ });
233
+ }
234
+ async function callApiPresignedDelete(url) {
235
+ return new Promise((resolve) => {
236
+ var xhr = new XMLHttpRequest();
237
+ xhr.addEventListener("readystatechange", () => {
238
+ if (xhr != null) {
239
+ if (xhr.readyState === 4) {
240
+ resolve(xhr);
241
+ }
242
+ }
243
+ });
244
+ xhr.open("DELETE", url);
245
+ xhr.timeout = 1800000;
246
+ xhr.setRequestHeader("Content-Type", "application/json");
247
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
248
+ xhr.send(null);
249
+ return xhr;
250
+ });
251
+ }
252
+ async function callApiPresignedGet(url) {
253
+ return new Promise((resolve) => {
254
+ var xhr = new XMLHttpRequest();
255
+ xhr.addEventListener("readystatechange", () => {
256
+ if (xhr != null) {
257
+ if (xhr.readyState === 4) {
258
+ resolve(xhr);
259
+ }
260
+ }
261
+ });
262
+ xhr.open("GET", url);
263
+ xhr.timeout = 1800000;
264
+ xhr.setRequestHeader("Content-Type", "application/json");
265
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
266
+ xhr.send(null);
267
+ return xhr;
268
+ });
269
+ }
270
+ async function callApiPresigned(url, data) {
271
+ return new Promise((resolve) => {
272
+ const jsonData = JSON.stringify(data);
273
+ var xhr = new XMLHttpRequest();
274
+ xhr.addEventListener("readystatechange", () => {
275
+ if (xhr != null) {
276
+ if (xhr.readyState === 4) {
277
+ resolve(xhr);
278
+ }
279
+ }
280
+ });
281
+ xhr.open("PUT", url);
282
+ xhr.timeout = 1800000;
283
+ xhr.setRequestHeader("Content-Type", "application/json");
284
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
285
+ xhr.send(jsonData);
286
+ return xhr;
287
+ });
288
+ }
289
+ function getRandomColor() {
290
+ var letters = '0123456789ABCDEF';
291
+ var color = '#';
292
+ for (var i = 0; i < 6; i++) {
293
+ color += letters[Math.floor(Math.random() * 16)];
294
+ }
295
+ return color;
296
+ }
297
+ function isInteger(value) {
298
+ return /^-?\d+$/.test(value);
299
+ }
300
+ function clearListeners(old_element) {
301
+ var _a;
302
+ var new_element = old_element.cloneNode(true);
303
+ (_a = old_element.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(new_element, old_element);
304
+ return new_element;
305
+ }
306
+ function jsonObjectToHtml(json) {
307
+ var html = '';
308
+ for (var i = 0; i < Object.keys(json).length; i++) {
309
+ var key = Object.keys(json)[i];
310
+ html += '<div>';
311
+ html += ('<span style="margin-left: 0px; padding-left: 0px">' + key + ':</span>&nbsp;');
312
+ html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g, '') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
313
+ html += '</div>';
314
+ }
315
+ return html;
316
+ }
317
+ function convertToCSV(arr) {
318
+ const array = [Object.keys(arr[0])].concat(arr);
319
+ let fieldsArr = Object.keys(arr[0]);
320
+ return array.map((it, index) => {
321
+ var _a;
322
+ let strIt = "";
323
+ for (let [i, objkey] of Object.keys(it).entries()) {
324
+ if (index == 0) {
325
+ strIt += "\"" + it[objkey].replace(/"/g, "\"\"") + "\"";
326
+ }
327
+ else {
328
+ strIt += "\"" + JSON.stringify((_a = it[fieldsArr[i]]) !== null && _a !== void 0 ? _a : "").replace(/"/g, "\"\"") + "\"";
329
+ }
330
+ if (i < (Object.keys(it).length - 1)) {
331
+ strIt += ",";
332
+ }
333
+ }
334
+ return strIt;
335
+ }).join('\n');
336
+ }
337
+ function parseCsv(csv) {
338
+ const re = /(,|\r?\n|\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\r\n]*))/gi;
339
+ const result = [[]];
340
+ let matches;
341
+ while ((matches = re.exec(csv))) {
342
+ if (matches[1].length && matches[1] !== ',')
343
+ result.push([]);
344
+ result[result.length - 1].push(matches[2] !== undefined ? matches[2].replace(/""/g, '"') : matches[3]);
345
+ }
346
+ console.log('csv arr result', result, result.length);
347
+ let csvResult = arrayToObject(result);
348
+ return csvResult;
349
+ }
350
+ function arrayToObject(csvArray) {
351
+ //Take the first line (headers) from the array and remove it from the array.
352
+ const headers = csvArray.shift();
353
+ // Iterate through the rows and reduce each column to an object
354
+ return csvArray.filter((row) => {
355
+ console.log('csv object keys lngth', Object.keys(row).length);
356
+ return Object.keys(row).length > 1;
357
+ }).map((row, index) => {
358
+ return headers.reduce((acc, currentHeader, i) => {
359
+ console.log('parsing row', row[i], index);
360
+ return ((currentHeader.indexOf('cols_') >= 0 || currentHeader == '') ? acc : ((row[i] != '' && row[i] != null) ? { ...acc, ...{ [currentHeader]: JSON.parse(row[i] == "TRUE" ? "true" : row[i]) } } : acc));
361
+ }, {});
362
+ });
363
+ }
364
+ function titleCase(str) {
365
+ var splitStr = str.toLowerCase().split(' ');
366
+ for (var i = 0; i < splitStr.length; i++) {
367
+ // You do not need to check if i is larger than splitStr length, as your for does that for you
368
+ // Assign it back to the array
369
+ splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
370
+ }
371
+ // Directly return the joined string
372
+ return splitStr.join(' ');
373
+ }
374
+ function alphabeticalSort(arr) {
375
+ let arrSorted = arr.sort((a, b) => {
376
+ return a.trim().toLowerCase().localeCompare(b.trim().toLowerCase());
377
+ });
378
+ return arrSorted;
379
+ }
380
+ function percentageString(val, valTotal) {
381
+ if (valTotal == 0) {
382
+ return "";
383
+ }
384
+ let num = (100 * val) / valTotal;
385
+ return " (" + (Math.round((num + Number.EPSILON) * 100) / 100) + "%)";
386
+ }
387
+ function getCurrentFiscal() {
388
+ let date = new Date();
389
+ if (date.getMonth() < 4) {
390
+ return (date.getFullYear() - 1);
391
+ }
392
+ return date.getFullYear();
393
+ }
394
+ function getDateTimeStrings(unixTimestamp) {
395
+ // Convert to milliseconds if the timestamp is in seconds
396
+ if (unixTimestamp.toString().length === 10) {
397
+ unixTimestamp *= 1000;
398
+ }
399
+ const date = new Date(unixTimestamp);
400
+ const options = {
401
+ year: 'numeric',
402
+ month: '2-digit',
403
+ day: '2-digit',
404
+ hour: '2-digit',
405
+ minute: '2-digit',
406
+ second: '2-digit',
407
+ hour12: false,
408
+ };
409
+ const estFormatter = new Intl.DateTimeFormat('en-US', {
410
+ ...options,
411
+ timeZone: 'America/New_York',
412
+ });
413
+ const istFormatter = new Intl.DateTimeFormat('en-IN', {
414
+ ...options,
415
+ timeZone: 'Asia/Kolkata',
416
+ });
417
+ const [estDate, estTime] = estFormatter.format(date).split(', ');
418
+ const [istDate, istTime] = istFormatter.format(date).split(', ');
419
+ return `${estDate} ${estTime} EST, ${istDate} ${istTime} IST`;
420
+ }
421
+ function getUsermap() {
422
+ var _a;
423
+ let userinfo = JSON.parse((_a = localStorage.getItem('userinfo')) !== null && _a !== void 0 ? _a : "{}");
424
+ let userMapHome = JSON.parse(JSON.parse((userinfo.user.usermap.S).replace(/_QUOTES_/g, "\\\"")));
425
+ return userMapHome;
426
+ }
427
+ const exportFunctions = {
428
+ callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap
429
+ };
430
+ export default exportFunctions;
431
431
  //# sourceMappingURL=util.js.map