utilitas 1989.9.44 → 1989.9.45
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.mjs +18 -10
- package/package.json +5 -5
package/lib/utilitas.mjs
CHANGED
|
@@ -83,7 +83,7 @@ const mapKeys = (any, map, strict, path) => {
|
|
|
83
83
|
|
|
84
84
|
const pad = (any, len, options) => {
|
|
85
85
|
options = options || {};
|
|
86
|
-
options.pad = options.pad
|
|
86
|
+
options.pad = options.pad ?? ' ';
|
|
87
87
|
any = String(any);
|
|
88
88
|
while (any.length < ~~len) {
|
|
89
89
|
any = !!options.right ? `${any}${options.pad}` : `${options.pad}${any}`;
|
|
@@ -108,7 +108,7 @@ const rawEnsureString = (any, options) => {
|
|
|
108
108
|
if (isObject(any)) { return JSON.stringify(any); }
|
|
109
109
|
else if (isDate(any)) { return any.toISOString(); }
|
|
110
110
|
else if (isError(any)) { return options?.trace ? any.stack : any.message; }
|
|
111
|
-
return String(any
|
|
111
|
+
return String(any ?? '');
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
const ensureString = (str, options) => {
|
|
@@ -128,11 +128,12 @@ const ensureString = (str, options) => {
|
|
|
128
128
|
throwError(`Invalid case option: '${options?.case}'.`, 500);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
options?.trim && (str = str.trim());
|
|
131
132
|
return str;
|
|
132
133
|
};
|
|
133
134
|
|
|
134
135
|
const trim = (str, options) => {
|
|
135
|
-
return ensureString(str, options)
|
|
136
|
+
return ensureString(str, { trim: true, ...options || {} });
|
|
136
137
|
};
|
|
137
138
|
|
|
138
139
|
const ensureDate = (dt, options) => {
|
|
@@ -221,7 +222,7 @@ const verifyUuid = (uuid) => {
|
|
|
221
222
|
|
|
222
223
|
// https://github.com/validatorjs/validator.js
|
|
223
224
|
const verifyUrl = (url) => {
|
|
224
|
-
const str = String(url
|
|
225
|
+
const str = String(url ?? '');
|
|
225
226
|
const reg = '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?'
|
|
226
227
|
+ ':(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d'
|
|
227
228
|
+ '|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a'
|
|
@@ -325,7 +326,7 @@ const parseJson = (any, fallback = {}) => {
|
|
|
325
326
|
const extract = function() {
|
|
326
327
|
let r = null;
|
|
327
328
|
for (let i = 0; i < arguments.length; i++) {
|
|
328
|
-
if (i) { r = r
|
|
329
|
+
if (i) { r = r?.[arguments[i]] ?? null; } else { r = arguments[i]; }
|
|
329
330
|
}
|
|
330
331
|
return r;
|
|
331
332
|
};
|
|
@@ -417,7 +418,7 @@ const uniqueArray = (arr) => {
|
|
|
417
418
|
|
|
418
419
|
const basename = (filename) => {
|
|
419
420
|
return path.basename(String(filename
|
|
420
|
-
|
|
421
|
+
?? __filename)).replace(/\.[^\.]*$/, '').trim();
|
|
421
422
|
};
|
|
422
423
|
|
|
423
424
|
const modLog = (content, filename, options) => {
|
|
@@ -470,7 +471,7 @@ const insensitiveCompare = (strA, strB, options) => {
|
|
|
470
471
|
};
|
|
471
472
|
|
|
472
473
|
const makeStringByLength = (string, length) => {
|
|
473
|
-
string = String(string
|
|
474
|
+
string = String(string ?? '')[0] ?? '';
|
|
474
475
|
length = parseInt(length) || 0;
|
|
475
476
|
let result = '';
|
|
476
477
|
while (string && length && result.length < length) {
|
|
@@ -553,9 +554,9 @@ const matchVersion = (curVer, tgtVer) => {
|
|
|
553
554
|
|
|
554
555
|
const fullLengthLog = (string, options) => {
|
|
555
556
|
options = options || {};
|
|
556
|
-
string = String(string
|
|
557
|
+
string = String(string ?? '');
|
|
557
558
|
const maxLength = ensureInt(options.maxLength) || process.stdout.columns;
|
|
558
|
-
const pad = options.padding
|
|
559
|
+
const pad = options.padding ?? '=';
|
|
559
560
|
if (string.length + 4 > maxLength) {
|
|
560
561
|
const full = makeStringByLength(pad, maxLength);
|
|
561
562
|
console.log(`${full} \n${string} \n${full} `);
|
|
@@ -583,7 +584,7 @@ const range = (from, to, options) => {
|
|
|
583
584
|
};
|
|
584
585
|
|
|
585
586
|
const shiftTime = (diff, baseTime) => {
|
|
586
|
-
return new Date((baseTime
|
|
587
|
+
return new Date((baseTime ?? new Date()).getTime() + diff);
|
|
587
588
|
};
|
|
588
589
|
|
|
589
590
|
const checkInterval = (itv, sed) => {
|
|
@@ -609,6 +610,12 @@ const tryUntil = async (fnTry, options) => {
|
|
|
609
610
|
return result;
|
|
610
611
|
};
|
|
611
612
|
|
|
613
|
+
const split = (str, options) => {
|
|
614
|
+
return trim(str, options).split(
|
|
615
|
+
options?.separator ?? /[,|;\ \t\n]+/
|
|
616
|
+
).map(x => x.trim()).filter(x => x.length);
|
|
617
|
+
};
|
|
618
|
+
|
|
612
619
|
// https://www.unicode.org/Public/13.0.0/ucd/emoji/emoji-data.txt
|
|
613
620
|
// https://stackoverflow.com/questions/10992921/how-to-remove-emoji-code-using-javascript
|
|
614
621
|
// https://twitter.com/_cxa/status/1384304473493831681?s=20
|
|
@@ -689,6 +696,7 @@ export {
|
|
|
689
696
|
range,
|
|
690
697
|
rotate,
|
|
691
698
|
shiftTime,
|
|
699
|
+
split,
|
|
692
700
|
throwError,
|
|
693
701
|
timeout,
|
|
694
702
|
toExponential,
|
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.9.
|
|
4
|
+
"version": "1989.9.45",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.mjs",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"url": "https://github.com/Leask/utilitas.git"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sentry/node": "^6.18.
|
|
28
|
+
"@sentry/node": "^6.18.2",
|
|
29
29
|
"base64url": "^3.0.1",
|
|
30
30
|
"colors": "1.4.0",
|
|
31
|
-
"fast-geoip": "^1.1.
|
|
31
|
+
"fast-geoip": "^1.1.62",
|
|
32
32
|
"file-type": "^17.1.1",
|
|
33
33
|
"ini": "github:Leask/ini",
|
|
34
34
|
"ioredis": "^4.28.5",
|
|
35
35
|
"jsonwebtoken": "^8.5.1",
|
|
36
36
|
"mailgun-js": "^0.22.0",
|
|
37
|
-
"mathjs": "^10.
|
|
37
|
+
"mathjs": "^10.4.0",
|
|
38
38
|
"mysql2": "^2.3.3",
|
|
39
39
|
"node-fetch": "^2.6.7",
|
|
40
40
|
"node-mailjet": "^3.3.7",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tail": "^2.2.4",
|
|
44
44
|
"telegraf": "^4.7.0",
|
|
45
45
|
"telesignsdk": "^2.2.1",
|
|
46
|
-
"twilio": "^3.75.
|
|
46
|
+
"twilio": "^3.75.1",
|
|
47
47
|
"uuid": "^8.3.2"
|
|
48
48
|
}
|
|
49
49
|
}
|