utilitas 1989.9.37 → 1989.9.41
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/storage.mjs +3 -3
- package/lib/tape.mjs +3 -1
- package/lib/utilitas.mjs +7 -4
- package/package.json +4 -4
package/lib/storage.mjs
CHANGED
|
@@ -85,10 +85,10 @@ const assertPath = async (path, type, mode, message, status = 500, options = {})
|
|
|
85
85
|
case '*': case '':
|
|
86
86
|
break;
|
|
87
87
|
case 'R':
|
|
88
|
-
fs.promises.access(path, fs.constants.R_OK);
|
|
88
|
+
await fs.promises.access(path, fs.constants.R_OK);
|
|
89
89
|
break;
|
|
90
90
|
case 'W':
|
|
91
|
-
fs.promises.access(path, fs.constants.R_OK | fs.constants.W_OK);
|
|
91
|
+
await fs.promises.access(path, fs.constants.R_OK | fs.constants.W_OK);
|
|
92
92
|
break;
|
|
93
93
|
default:
|
|
94
94
|
modeErr = message || `Unsupported access mode: '${mode}'.`;
|
|
@@ -100,7 +100,7 @@ const assertPath = async (path, type, mode, message, status = 500, options = {})
|
|
|
100
100
|
|
|
101
101
|
const isTextFile = async (filename, options) => {
|
|
102
102
|
let [fh, result] = [await fs.promises.open(filename, 'r'), true];
|
|
103
|
-
for (
|
|
103
|
+
for (let i = 0; i < (~~options?.length || 1000); i++) {
|
|
104
104
|
const buf = Buffer.alloc(1);
|
|
105
105
|
const bytes = fs.readSync(fh.fd, buf, 0, 1, i);
|
|
106
106
|
if (bytes === 0) { break; } else if (
|
package/lib/tape.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import * as event from './event.mjs';
|
|
|
3
3
|
import * as utilitas from './utilitas.mjs';
|
|
4
4
|
|
|
5
5
|
const consoleMap = ['log', 'info', 'debug', 'warn', 'error'];
|
|
6
|
+
const trace = { trace: true };
|
|
6
7
|
const [TAPE, BOT, maxLength, defBufCycle, maxBufCycle] = ['TAPE', 'BOT', 4096, 10, 100];
|
|
7
8
|
const stdout = (message) => { return process.stdout.write(`${message}\n`); };
|
|
8
9
|
const modLog = (c, o) => { utilitas.modLog(c, TAPE, { time: true, ...o || {} }); };
|
|
@@ -10,6 +11,7 @@ const getSendTxt = (arr) => { return arr.map(x => x[1]).join('\n'); };
|
|
|
10
11
|
const getSndSize = (arr) => { return getSendTxt(arr).length; };
|
|
11
12
|
const getBufSize = () => { return maxLength * bufferCycle; };
|
|
12
13
|
const nextLen = () => { return botBuffer?.[0]?.[1].length || (maxLength + 1); };
|
|
14
|
+
const stringify = any => utilitas.ensureString(any, trace);
|
|
13
15
|
|
|
14
16
|
let botBuffer, bufferCycle, chatIds, log, tarLevel;
|
|
15
17
|
|
|
@@ -19,7 +21,7 @@ const hookConsole = () => {
|
|
|
19
21
|
console[bakTar] = console[tar];
|
|
20
22
|
console[tar] = function() {
|
|
21
23
|
console[bakTar].apply(console, arguments);
|
|
22
|
-
const str = [...arguments].map(
|
|
24
|
+
const str = [...arguments].map(stringify).join(' ')
|
|
23
25
|
.replace(/\u001b\[\d+m/g, '')
|
|
24
26
|
.split('\n').filter(x => x.length).join('\n').split('');
|
|
25
27
|
while (str.length) {
|
package/lib/utilitas.mjs
CHANGED
|
@@ -104,14 +104,15 @@ const ensureArray = (array) => {
|
|
|
104
104
|
return isSet(array, true) ? (Array.isArray(array) ? array : [array]) : []
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
const rawEnsureString = (any) => {
|
|
107
|
+
const rawEnsureString = (any, options) => {
|
|
108
108
|
if (isObject(any)) { return JSON.stringify(any); }
|
|
109
109
|
else if (isDate(any)) { return any.toISOString(); }
|
|
110
|
+
else if (isError(any)) { return options?.trace ? any.stack : any.message; }
|
|
110
111
|
return String(any || '');
|
|
111
112
|
};
|
|
112
113
|
|
|
113
114
|
const ensureString = (str, options) => {
|
|
114
|
-
str = rawEnsureString(str);
|
|
115
|
+
str = rawEnsureString(str, options);
|
|
115
116
|
if (options?.case) {
|
|
116
117
|
switch (rawEnsureString(options?.case).trim().toUpperCase()) {
|
|
117
118
|
case 'UP':
|
|
@@ -423,9 +424,11 @@ const modLog = (content, filename, options) => {
|
|
|
423
424
|
options = options || [];
|
|
424
425
|
const isErr = isError(content);
|
|
425
426
|
content = isObject(content) ? JSON.stringify(content) : content;
|
|
427
|
+
const strTime = options.time ? ` ${(isDate(
|
|
428
|
+
options.time, true
|
|
429
|
+
) ? options.time : new Date()).toISOString()}` : '';
|
|
426
430
|
const args = ['['
|
|
427
|
-
+ colors.red(basename(filename).toUpperCase())
|
|
428
|
-
+ colors.yellow(options.time ? ` ${new Date().toISOString()}` : '')
|
|
431
|
+
+ colors.red(basename(filename).toUpperCase()) + colors.yellow(strTime)
|
|
429
432
|
+ ']' + (isErr ? '' : ` ${content}`)];
|
|
430
433
|
if (isErr) { args.push(content); }
|
|
431
434
|
return console.info.apply(null, args);
|
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.41",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.mjs",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"url": "https://github.com/Leask/utilitas.git"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sentry/node": "^6.17.
|
|
28
|
+
"@sentry/node": "^6.17.9",
|
|
29
29
|
"base64url": "^3.0.1",
|
|
30
30
|
"colors": "1.4.0",
|
|
31
|
-
"fast-geoip": "^1.1.
|
|
31
|
+
"fast-geoip": "^1.1.59",
|
|
32
32
|
"file-type": "^17.1.1",
|
|
33
33
|
"ini": "github:Leask/ini",
|
|
34
34
|
"ioredis": "^4.28.5",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"mathjs": "^10.1.1",
|
|
38
38
|
"mysql2": "^2.3.3",
|
|
39
39
|
"node-fetch": "^2.6.7",
|
|
40
|
-
"node-mailjet": "^3.3.
|
|
40
|
+
"node-mailjet": "^3.3.7",
|
|
41
41
|
"ping": "^0.4.1",
|
|
42
42
|
"qs": "^6.10.3",
|
|
43
43
|
"tail": "^2.2.4",
|