utilitas 1989.8.74 → 1989.8.75
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/lib/utilitas.js +23 -0
- package/package.json +3 -3
package/lib/utilitas.js
CHANGED
|
@@ -12,6 +12,11 @@ RegExp.escape = RegExp.escape || ((str) => { //$& means the whole matched string
|
|
|
12
12
|
|
|
13
13
|
const invalidTime = 'Invalid time.';
|
|
14
14
|
|
|
15
|
+
const tryOpts = {
|
|
16
|
+
interval: 1000 * 1, maxTry: 10, log: false,
|
|
17
|
+
verify: async (err, res) => { return !err && res; },
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
const clone = (any) => {
|
|
16
21
|
let resp = any; // typeof Object === 'function' || etc
|
|
17
22
|
switch (getType(any)) {
|
|
@@ -577,6 +582,23 @@ const ignoreErrFunc = async (fn, args, options) => {
|
|
|
577
582
|
catch (err) { return options?.log ? console.error(err) : err; }
|
|
578
583
|
};
|
|
579
584
|
|
|
585
|
+
const tryUntil = async (fnTry, options) => {
|
|
586
|
+
options = { ...tryOpts, ...options || {} };
|
|
587
|
+
let [curTry, result, err] = [0, null, null];
|
|
588
|
+
while (curTry++ < options.maxTry && !(await options.verify(err, result))) {
|
|
589
|
+
try {
|
|
590
|
+
result = await fnTry();
|
|
591
|
+
err = null;
|
|
592
|
+
} catch (e) {
|
|
593
|
+
err = e;
|
|
594
|
+
options?.log && console.error(e);
|
|
595
|
+
await timeout(options.interval);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
err && throwError(err, 500);
|
|
599
|
+
return result;
|
|
600
|
+
};
|
|
601
|
+
|
|
580
602
|
// https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
|
|
581
603
|
// https://stackoverflow.com/questions/10992921/how-to-remove-emoji-code-using-javascript
|
|
582
604
|
// https://twitter.com/_cxa/status/1384304473493831681?s=20
|
|
@@ -660,6 +682,7 @@ module.exports = {
|
|
|
660
682
|
timeout,
|
|
661
683
|
toExponential,
|
|
662
684
|
trim,
|
|
685
|
+
tryUntil,
|
|
663
686
|
uniqueArray,
|
|
664
687
|
verifyEmail,
|
|
665
688
|
verifyPhone,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilitas",
|
|
3
3
|
"description": "Just another common utility for Node.js.",
|
|
4
|
-
"version": "1989.8.
|
|
4
|
+
"version": "1989.8.75",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@sentry/node": "^6.16.1",
|
|
25
25
|
"base64url": "^3.0.1",
|
|
26
|
-
"colors": "^1.4.
|
|
26
|
+
"colors": "^1.4.2",
|
|
27
27
|
"fast-geoip": "^1.1.53",
|
|
28
28
|
"file-type": "^16.5.3",
|
|
29
29
|
"ini": "github:Leask/ini",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"telesignsdk": "^2.2.1",
|
|
41
41
|
"twilio": "^3.72.0",
|
|
42
42
|
"uuid": "^8.3.2",
|
|
43
|
-
"winston": "^3.3.
|
|
43
|
+
"winston": "^3.3.4",
|
|
44
44
|
"winston-papertrail-mproved": "^1.0.7"
|
|
45
45
|
}
|
|
46
46
|
}
|