This repository was archived by the owner on Jun 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutilities.js
More file actions
77 lines (67 loc) · 1.56 KB
/
Copy pathutilities.js
File metadata and controls
77 lines (67 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { isMainThread, parentPort } = require("worker_threads");
// Date formatting function
function dateFormatter(date) {
let d = new Date(date);
return `${d.getFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}-${String(d.getUTCDate()).padStart(2, "0")} ${String(d.getUTCHours()).padStart(2, "0")}:${String(d.getUTCMinutes()).padStart(2, "0")}:${String(d.getUTCSeconds()).padStart(2, "0")}`;
}
function hexToANSI(hex) {
var r = (hex >> 16) & 255;
var g = (hex >> 8) & 255;
var b = hex & 255;
return `\x1b[38;2;${r};${g};${b}m`;
}
function parseColorPlaceholders(text) {
const colors = [
{
key: "%c",
value: hexToANSI(0xff5555),
},
{
key: "%a",
value: hexToANSI(0x55ff55),
},
{
key: "%b",
value: hexToANSI(0x55ffff),
},
{
key: "%d",
value: hexToANSI(0xff55ff),
},
{
key: "%e",
value: hexToANSI(0xffff55),
},
{
key: "%l",
value: hexToANSI(0xae70ff),
},
{
key: "%y",
value: hexToANSI(0xf5e342),
},
{
key: "%t",
value: hexToANSI(0xb0f542),
},
{
key: "%r",
value: "\x1b[0m",
},
];
for (let i = 0; i < colors.length; i++) {
const placeholder = colors[i].key;
const value = colors[i].value;
text = text.replaceAll(placeholder, value);
}
return text;
}
function log(text) {
if (!isMainThread) parentPort.postMessage("SUB_LOG");
console.log("\x1b[0m" + parseColorPlaceholders(text) + "\x1b[0m");
}
module.exports = {
log,
dateFormatter,
parseColorPlaceholders,
};