tuijs-util 1.4.1 → 1.4.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/package.json +3 -3
- package/src/cjs/index.cjs +69 -30
- package/src/esm/index.js +8 -1
- package/src/esm/lib/util.check.js +12 -12
- package/src/esm/lib/util.dom.js +4 -4
- package/src/esm/lib/util.http.js +7 -7
- package/src/esm/lib/util.lists.js +5 -1
- package/src/esm/lib/util.misc.js +4 -4
- package/src/esm/lib/util.parse.js +32 -0
- package/src/esm/lib/util.regex.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuijs-util",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"module": "src/esm/index.js",
|
|
5
5
|
"main": "src/cjs/index.cjs",
|
|
6
6
|
"exports": {
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"repository": "github:TechTB-OpenSource/tuijs-util",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"
|
|
18
|
+
"build": "rollup -c rollup.config.js"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@rollup/plugin-babel": "^6.0.4",
|
|
22
22
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
23
|
-
"rollup": "^4.
|
|
23
|
+
"rollup": "^4.28.1"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/src/cjs/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ function removeChar(string, regEx) {
|
|
|
41
41
|
}
|
|
42
42
|
return string.replace(regEx, '');
|
|
43
43
|
} catch (er) {
|
|
44
|
-
|
|
44
|
+
console.error(er);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -58,7 +58,7 @@ function checkFqdn(string) {
|
|
|
58
58
|
}
|
|
59
59
|
return regExFqdn.test(string);
|
|
60
60
|
} catch (er) {
|
|
61
|
-
|
|
61
|
+
console.error(er);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -76,7 +76,7 @@ function checkUrl(string) {
|
|
|
76
76
|
;
|
|
77
77
|
return regExUrl.test(string); // Returns false if the url is invalid
|
|
78
78
|
} catch (er) {
|
|
79
|
-
|
|
79
|
+
console.error(er);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -94,7 +94,7 @@ function checkSpecialChar(string) {
|
|
|
94
94
|
;
|
|
95
95
|
return regExSpecial.test(string);
|
|
96
96
|
} catch (er) {
|
|
97
|
-
|
|
97
|
+
console.error(er);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -112,7 +112,7 @@ function checkNum(string) {
|
|
|
112
112
|
;
|
|
113
113
|
return regExNumbers.test(string);
|
|
114
114
|
} catch (er) {
|
|
115
|
-
|
|
115
|
+
console.error(er);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -130,7 +130,7 @@ function checkLowercase(string) {
|
|
|
130
130
|
;
|
|
131
131
|
return regExLettersLower.test(string);
|
|
132
132
|
} catch (er) {
|
|
133
|
-
|
|
133
|
+
console.error(er);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -148,7 +148,7 @@ function checkUppercase(string) {
|
|
|
148
148
|
;
|
|
149
149
|
return regExLettersUpper.test(string);
|
|
150
150
|
} catch (er) {
|
|
151
|
-
|
|
151
|
+
console.error(er);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -166,7 +166,7 @@ function checkEmail(string) {
|
|
|
166
166
|
;
|
|
167
167
|
return regExEmail.test(string);
|
|
168
168
|
} catch (er) {
|
|
169
|
-
|
|
169
|
+
console.error(er);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -184,7 +184,7 @@ function checkSpaces(string) {
|
|
|
184
184
|
;
|
|
185
185
|
return str.indexOf(' ') >= 0;
|
|
186
186
|
} catch (er) {
|
|
187
|
-
|
|
187
|
+
console.error(er);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -198,7 +198,7 @@ function checkIsArray(input) {
|
|
|
198
198
|
try {
|
|
199
199
|
return Array.isArray(input);
|
|
200
200
|
} catch (er) {
|
|
201
|
-
|
|
201
|
+
console.error(er);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -212,7 +212,7 @@ function checkIsObject(input) {
|
|
|
212
212
|
try {
|
|
213
213
|
return input !== null && typeof input === 'object' && input.constructor === Object;
|
|
214
214
|
} catch (er) {
|
|
215
|
-
|
|
215
|
+
console.error(er);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -240,7 +240,7 @@ function checkIsElement(input) {
|
|
|
240
240
|
try {
|
|
241
241
|
return input instanceof Element || input instanceof Document || input instanceof Window || input instanceof DocumentFragment || input instanceof ShadowRoot;
|
|
242
242
|
} catch (er) {
|
|
243
|
-
|
|
243
|
+
console.error(er);
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
|
|
@@ -254,7 +254,7 @@ function checkIsFunction(input) {
|
|
|
254
254
|
try {
|
|
255
255
|
return typeof input === 'function';
|
|
256
256
|
} catch (er) {
|
|
257
|
-
|
|
257
|
+
console.error(er);
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -276,7 +276,7 @@ function parseTemplate(templateLit) {
|
|
|
276
276
|
}
|
|
277
277
|
return template.content;
|
|
278
278
|
} catch (er) {
|
|
279
|
-
|
|
279
|
+
console.error(er);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -294,7 +294,7 @@ function elmCleaner(templateLit) {
|
|
|
294
294
|
let elms = elmBody.body.querySelectorAll("*");
|
|
295
295
|
return elms[0];
|
|
296
296
|
} catch (er) {
|
|
297
|
-
|
|
297
|
+
console.error(er);
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -315,7 +315,7 @@ function elmCleanerTr(templateLit) {
|
|
|
315
315
|
elmTemp.remove();
|
|
316
316
|
return elms;
|
|
317
317
|
} catch (er) {
|
|
318
|
-
|
|
318
|
+
console.error(er);
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
|
|
@@ -335,7 +335,7 @@ function elmCleanerArray(templateLit) {
|
|
|
335
335
|
let elms = elmBody.body.querySelectorAll("*");
|
|
336
336
|
return Array.from(elms);
|
|
337
337
|
} catch (er) {
|
|
338
|
-
|
|
338
|
+
console.error(er);
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
@@ -356,7 +356,7 @@ function urlAddHttp(url) {
|
|
|
356
356
|
}
|
|
357
357
|
return url;
|
|
358
358
|
} catch (er) {
|
|
359
|
-
|
|
359
|
+
console.error(er);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
|
|
@@ -377,7 +377,7 @@ function urlAddHttps(url) {
|
|
|
377
377
|
}
|
|
378
378
|
return url;
|
|
379
379
|
} catch (er) {
|
|
380
|
-
|
|
380
|
+
console.error(er);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
@@ -395,7 +395,7 @@ async function reqGet(url) {
|
|
|
395
395
|
});
|
|
396
396
|
return res;
|
|
397
397
|
} catch (er) {
|
|
398
|
-
|
|
398
|
+
console.error(er);
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
|
|
@@ -414,7 +414,7 @@ async function reqGetJson(url) {
|
|
|
414
414
|
const data = await res.json();
|
|
415
415
|
return data;
|
|
416
416
|
} catch (er) {
|
|
417
|
-
|
|
417
|
+
console.error(er);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
|
|
@@ -433,7 +433,7 @@ async function reqGetText(url) {
|
|
|
433
433
|
const data = await res.text();
|
|
434
434
|
return data;
|
|
435
435
|
} catch (er) {
|
|
436
|
-
|
|
436
|
+
console.error(er);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
|
|
@@ -462,7 +462,7 @@ async function reqPostJson(url, dataJson) {
|
|
|
462
462
|
});
|
|
463
463
|
return res;
|
|
464
464
|
} catch (er) {
|
|
465
|
-
|
|
465
|
+
console.error(er);
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
|
|
@@ -484,11 +484,15 @@ async function reqPostForm(url, dataForm) {
|
|
|
484
484
|
});
|
|
485
485
|
return res;
|
|
486
486
|
} catch (er) {
|
|
487
|
-
|
|
487
|
+
console.error(er);
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
const
|
|
491
|
+
const listNumChar = '1234567890';
|
|
492
|
+
const listUpChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
493
|
+
const listLowChar = 'abcdefghijklmnopqrstuvwxyz';
|
|
494
|
+
const listSpecChar = '!@#$%^&*()';
|
|
495
|
+
const listHtmlTags = ["html", "body", "div", "span", "applet", "object", "iframe", "h1", "h2", "h3", "h4", "h5", "h6", "p", "blockquote", "pre", "a", "abbr", "acronym", "address", "big", "cite", "code", "del", "dfn", "em", "img", "ins", "kbd", "q", "s", "samp", "small", "strike", "strong", "sub", "sup", "tt", "var", "b", "u", "i", "center", "dl", "dt", "dd", "ol", "ul", "li", "fieldset", "form", "label", "legend", "table", "caption", "tbody", "tfoot", "thead", "tr", "th", "td", "article", "aside", "canvas", "details", "embed", "figure", "figcaption", "footer", "header", "hgroup", "menu", "nav", "output", "ruby", "section", "summary", "time", "mark", "audio", "video"];
|
|
492
496
|
|
|
493
497
|
/**
|
|
494
498
|
* Adds zero in front of numbers less than 10 and returns as a string.
|
|
@@ -505,7 +509,7 @@ function addLeadZero(num) {
|
|
|
505
509
|
return "0" + num;
|
|
506
510
|
;
|
|
507
511
|
} catch (er) {
|
|
508
|
-
|
|
512
|
+
console.error(er);
|
|
509
513
|
}
|
|
510
514
|
}
|
|
511
515
|
|
|
@@ -524,7 +528,7 @@ function generateUID(length = 16) {
|
|
|
524
528
|
const randomPart = Math.random().toString(36).slice(2, 2 + length);
|
|
525
529
|
return 'uid-' + timestampPart + '-' + randomPart;
|
|
526
530
|
} catch (er) {
|
|
527
|
-
|
|
531
|
+
console.error(er);
|
|
528
532
|
}
|
|
529
533
|
}
|
|
530
534
|
|
|
@@ -548,7 +552,7 @@ async function preloadImages(imageUrls) {
|
|
|
548
552
|
};
|
|
549
553
|
await Promise.all(imageUrls.map(loadImage));
|
|
550
554
|
} catch (er) {
|
|
551
|
-
|
|
555
|
+
console.error(er);
|
|
552
556
|
}
|
|
553
557
|
}
|
|
554
558
|
|
|
@@ -562,7 +566,7 @@ function sleep(ms) {
|
|
|
562
566
|
}
|
|
563
567
|
|
|
564
568
|
/**
|
|
565
|
-
*
|
|
569
|
+
* NEED TO ADD NAME AND JSDOC
|
|
566
570
|
*/
|
|
567
571
|
function scrollIntoView() {
|
|
568
572
|
let allObservers = [];
|
|
@@ -604,6 +608,36 @@ function scrollIntoView() {
|
|
|
604
608
|
};
|
|
605
609
|
}
|
|
606
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Parses a function and its parameters when it is in the form of a string.
|
|
613
|
+
* This can be used to embed function strings into custom HTML elements.
|
|
614
|
+
* The Function MUST exist in the window object.
|
|
615
|
+
* @param {string} string
|
|
616
|
+
* @returns {Function} - Returns an executable function with its parameters
|
|
617
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
618
|
+
*/
|
|
619
|
+
function parseFunctionString(string) {
|
|
620
|
+
try {
|
|
621
|
+
if (typeof string !== 'string' || string.trim() === '') {
|
|
622
|
+
throw new Error('Input must be a non-empty string.');
|
|
623
|
+
}
|
|
624
|
+
const match = string.match(/^(\w+)\((.*)\)$/); // Match "functionName(args)"
|
|
625
|
+
if (!match) {
|
|
626
|
+
throw new Error('Input does not match the expected pattern "functionName(args)".');
|
|
627
|
+
}
|
|
628
|
+
const [_, funcName, args] = match;
|
|
629
|
+
const func = window[funcName];
|
|
630
|
+
if (typeof func !== 'function') {
|
|
631
|
+
throw new Error(`"${funcName}" is not a valid function.`);
|
|
632
|
+
}
|
|
633
|
+
const parsedArgs = args.split(',').map(arg => arg.trim().replace(/^['"]|['"]$/g, '')) // Trim and remove quotes
|
|
634
|
+
.filter(arg => arg !== ''); // Remove empty strings from args
|
|
635
|
+
return () => func(...parsedArgs);
|
|
636
|
+
} catch (er) {
|
|
637
|
+
console.error(er);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
607
641
|
exports.addLeadZero = addLeadZero;
|
|
608
642
|
exports.checkEmail = checkEmail;
|
|
609
643
|
exports.checkFqdn = checkFqdn;
|
|
@@ -622,7 +656,12 @@ exports.elmCleaner = elmCleaner;
|
|
|
622
656
|
exports.elmCleanerArray = elmCleanerArray;
|
|
623
657
|
exports.elmCleanerTr = elmCleanerTr;
|
|
624
658
|
exports.generateUID = generateUID;
|
|
625
|
-
exports.
|
|
659
|
+
exports.listHtmlTags = listHtmlTags;
|
|
660
|
+
exports.listLowChar = listLowChar;
|
|
661
|
+
exports.listNumChar = listNumChar;
|
|
662
|
+
exports.listSpecChar = listSpecChar;
|
|
663
|
+
exports.listUpChar = listUpChar;
|
|
664
|
+
exports.parseFunctionString = parseFunctionString;
|
|
626
665
|
exports.parseTemplate = parseTemplate;
|
|
627
666
|
exports.preloadImages = preloadImages;
|
|
628
667
|
exports.regExBinary = regExBinary;
|
package/src/esm/index.js
CHANGED
|
@@ -29,7 +29,11 @@ export {
|
|
|
29
29
|
urlAddHttps
|
|
30
30
|
} from './lib/util.http.js';
|
|
31
31
|
export {
|
|
32
|
-
|
|
32
|
+
listHtmlTags,
|
|
33
|
+
listLowChar,
|
|
34
|
+
listNumChar,
|
|
35
|
+
listSpecChar,
|
|
36
|
+
listUpChar
|
|
33
37
|
} from './lib/util.lists.js';
|
|
34
38
|
export {
|
|
35
39
|
addLeadZero,
|
|
@@ -38,6 +42,9 @@ export {
|
|
|
38
42
|
sleep,
|
|
39
43
|
scrollIntoView
|
|
40
44
|
} from './lib/util.misc.js';
|
|
45
|
+
export {
|
|
46
|
+
parseFunctionString
|
|
47
|
+
} from './lib/util.parse.js';
|
|
41
48
|
export {
|
|
42
49
|
regExLetters,
|
|
43
50
|
regExLettersLower,
|
|
@@ -13,7 +13,7 @@ export function checkFqdn(string) {
|
|
|
13
13
|
}
|
|
14
14
|
return regExFqdn.test(string);
|
|
15
15
|
} catch (er) {
|
|
16
|
-
|
|
16
|
+
console.error(er);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ export function checkUrl(string) {
|
|
|
31
31
|
};
|
|
32
32
|
return regExUrl.test(string); // Returns false if the url is invalid
|
|
33
33
|
} catch (er) {
|
|
34
|
-
|
|
34
|
+
console.error(er);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -48,7 +48,7 @@ export function checkSpecialChar(string) {
|
|
|
48
48
|
};
|
|
49
49
|
return regExSpecial.test(string);
|
|
50
50
|
} catch (er) {
|
|
51
|
-
|
|
51
|
+
console.error(er);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -65,7 +65,7 @@ export function checkNum(string) {
|
|
|
65
65
|
};
|
|
66
66
|
return regExNumbers.test(string);
|
|
67
67
|
} catch (er) {
|
|
68
|
-
|
|
68
|
+
console.error(er);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -82,7 +82,7 @@ export function checkLowercase(string) {
|
|
|
82
82
|
};
|
|
83
83
|
return regExLettersLower.test(string);
|
|
84
84
|
} catch (er) {
|
|
85
|
-
|
|
85
|
+
console.error(er);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -99,7 +99,7 @@ export function checkUppercase(string) {
|
|
|
99
99
|
};
|
|
100
100
|
return regExLettersUpper.test(string);
|
|
101
101
|
} catch (er) {
|
|
102
|
-
|
|
102
|
+
console.error(er);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -116,7 +116,7 @@ export function checkEmail(string) {
|
|
|
116
116
|
};
|
|
117
117
|
return regExEmail.test(string);
|
|
118
118
|
} catch (er) {
|
|
119
|
-
|
|
119
|
+
console.error(er);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -133,7 +133,7 @@ export function checkSpaces(string) {
|
|
|
133
133
|
};
|
|
134
134
|
return str.indexOf(' ') >= 0;
|
|
135
135
|
} catch (er) {
|
|
136
|
-
|
|
136
|
+
console.error(er);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -147,7 +147,7 @@ export function checkIsArray(input) {
|
|
|
147
147
|
try {
|
|
148
148
|
return Array.isArray(input);
|
|
149
149
|
} catch (er) {
|
|
150
|
-
|
|
150
|
+
console.error(er);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -161,7 +161,7 @@ export function checkIsObject(input) {
|
|
|
161
161
|
try {
|
|
162
162
|
return input !== null && typeof input === 'object' && input.constructor === Object;
|
|
163
163
|
} catch (er) {
|
|
164
|
-
|
|
164
|
+
console.error(er);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -195,7 +195,7 @@ export function checkIsElement(input) {
|
|
|
195
195
|
input instanceof ShadowRoot
|
|
196
196
|
);
|
|
197
197
|
} catch (er) {
|
|
198
|
-
|
|
198
|
+
console.error(er);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
@@ -209,6 +209,6 @@ export function checkIsFunction(input) {
|
|
|
209
209
|
try {
|
|
210
210
|
return typeof input === 'function';
|
|
211
211
|
} catch (er) {
|
|
212
|
-
|
|
212
|
+
console.error(er);
|
|
213
213
|
}
|
|
214
214
|
}
|
package/src/esm/lib/util.dom.js
CHANGED
|
@@ -16,7 +16,7 @@ export function parseTemplate(templateLit) {
|
|
|
16
16
|
}
|
|
17
17
|
return template.content;
|
|
18
18
|
} catch (er) {
|
|
19
|
-
|
|
19
|
+
console.error(er);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -34,7 +34,7 @@ export function elmCleaner(templateLit) {
|
|
|
34
34
|
let elms = elmBody.body.querySelectorAll("*");
|
|
35
35
|
return elms[0];
|
|
36
36
|
} catch (er) {
|
|
37
|
-
|
|
37
|
+
console.error(er);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -55,7 +55,7 @@ export function elmCleanerTr(templateLit) {
|
|
|
55
55
|
elmTemp.remove();
|
|
56
56
|
return elms;
|
|
57
57
|
} catch (er) {
|
|
58
|
-
|
|
58
|
+
console.error(er);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -75,6 +75,6 @@ export function elmCleanerArray(templateLit) {
|
|
|
75
75
|
let elms = elmBody.body.querySelectorAll("*");
|
|
76
76
|
return Array.from(elms);
|
|
77
77
|
} catch (er) {
|
|
78
|
-
|
|
78
|
+
console.error(er);
|
|
79
79
|
}
|
|
80
80
|
}
|
package/src/esm/lib/util.http.js
CHANGED
|
@@ -16,7 +16,7 @@ export function urlAddHttp(url) {
|
|
|
16
16
|
}
|
|
17
17
|
return url;
|
|
18
18
|
} catch (er) {
|
|
19
|
-
|
|
19
|
+
console.error(er);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -36,7 +36,7 @@ export function urlAddHttps(url) {
|
|
|
36
36
|
}
|
|
37
37
|
return url;
|
|
38
38
|
} catch (er) {
|
|
39
|
-
|
|
39
|
+
console.error(er);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ export async function reqGet(url) {
|
|
|
52
52
|
const res = await fetch(url, { method: 'GET' });
|
|
53
53
|
return res;
|
|
54
54
|
} catch (er) {
|
|
55
|
-
|
|
55
|
+
console.error(er);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -69,7 +69,7 @@ export async function reqGetJson(url) {
|
|
|
69
69
|
const data = await res.json();
|
|
70
70
|
return data;
|
|
71
71
|
} catch (er) {
|
|
72
|
-
|
|
72
|
+
console.error(er);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -86,7 +86,7 @@ export async function reqGetText(url) {
|
|
|
86
86
|
const data = await res.text();
|
|
87
87
|
return data;
|
|
88
88
|
} catch (er) {
|
|
89
|
-
|
|
89
|
+
console.error(er);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -115,7 +115,7 @@ export async function reqPostJson(url, dataJson) {
|
|
|
115
115
|
});
|
|
116
116
|
return res;
|
|
117
117
|
} catch (er) {
|
|
118
|
-
|
|
118
|
+
console.error(er);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -137,6 +137,6 @@ export async function reqPostForm(url, dataForm) {
|
|
|
137
137
|
});
|
|
138
138
|
return res;
|
|
139
139
|
} catch (er) {
|
|
140
|
-
|
|
140
|
+
console.error(er);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const listNumChar = '1234567890';
|
|
2
|
+
export const listUpChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
3
|
+
export const listLowChar = 'abcdefghijklmnopqrstuvwxyz';
|
|
4
|
+
export const listSpecChar = '!@#$%^&*()';
|
|
5
|
+
export const listHtmlTags = [
|
|
2
6
|
"html",
|
|
3
7
|
"body",
|
|
4
8
|
"div",
|
package/src/esm/lib/util.misc.js
CHANGED
|
@@ -11,7 +11,7 @@ export function addLeadZero(num) {
|
|
|
11
11
|
};
|
|
12
12
|
return "0" + num;;
|
|
13
13
|
} catch (er) {
|
|
14
|
-
|
|
14
|
+
console.error(er);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -30,7 +30,7 @@ export function generateUID(length = 16) {
|
|
|
30
30
|
const randomPart = Math.random().toString(36).slice(2, 2 + length);
|
|
31
31
|
return 'uid-' + timestampPart + '-' + randomPart;
|
|
32
32
|
} catch (er) {
|
|
33
|
-
|
|
33
|
+
console.error(er);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -54,7 +54,7 @@ export async function preloadImages(imageUrls) {
|
|
|
54
54
|
};
|
|
55
55
|
await Promise.all(imageUrls.map(loadImage));
|
|
56
56
|
} catch (er) {
|
|
57
|
-
|
|
57
|
+
console.error(er);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ export function sleep(ms) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* NEED TO ADD NAME AND JSDOC
|
|
72
72
|
*/
|
|
73
73
|
export function scrollIntoView() {
|
|
74
74
|
let allObservers = [];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Parses a function and its parameters when it is in the form of a string.
|
|
4
|
+
* This can be used to embed function strings into custom HTML elements.
|
|
5
|
+
* The Function MUST exist in the window object.
|
|
6
|
+
* @param {string} string
|
|
7
|
+
* @returns {Function} - Returns an executable function with its parameters
|
|
8
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
9
|
+
*/
|
|
10
|
+
export function parseFunctionString(string) {
|
|
11
|
+
try {
|
|
12
|
+
if (typeof string !== 'string' || string.trim() === '') {
|
|
13
|
+
throw new Error('Input must be a non-empty string.');
|
|
14
|
+
}
|
|
15
|
+
const match = string.match(/^(\w+)\((.*)\)$/); // Match "functionName(args)"
|
|
16
|
+
if (!match) {
|
|
17
|
+
throw new Error('Input does not match the expected pattern "functionName(args)".');
|
|
18
|
+
}
|
|
19
|
+
const [_, funcName, args] = match;
|
|
20
|
+
const func = window[funcName];
|
|
21
|
+
if (typeof func !== 'function') {
|
|
22
|
+
throw new Error(`"${funcName}" is not a valid function.`);
|
|
23
|
+
}
|
|
24
|
+
const parsedArgs = args
|
|
25
|
+
.split(',')
|
|
26
|
+
.map(arg => arg.trim().replace(/^['"]|['"]$/g, '')) // Trim and remove quotes
|
|
27
|
+
.filter(arg => arg !== ''); // Remove empty strings from args
|
|
28
|
+
return () => func(...parsedArgs);
|
|
29
|
+
} catch (er) {
|
|
30
|
+
console.error(er);
|
|
31
|
+
}
|
|
32
|
+
}
|