refactor: rewrite on typescript

This commit is contained in:
2026-10-12 21:10:16 +03:00
parent be54ce5d25
commit 259a5808b7
38 changed files with 2282 additions and 2172 deletions
+61
View File
@@ -0,0 +1,61 @@
import colors from "ansi-colors";
import timestamp from "time-stamp";
const Level = {
VERBOSE: -1,
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
};
const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
export class Log {
static level = level;
static colorize(pattern: string) {
for (const item of [
["_", colors.cyan],
["\\*", colors.magenta],
["!", colors.red],
]) {
const r = new RegExp(item[0] + "(.*?)" + item[0], "g");
pattern = pattern.replace(r, item[1]("$1"));
}
return pattern;
}
static write(level: number, tag: string, pattern: string, ...args: any) {
if (level >= this.level) {
const message = `[${colors.gray(timestamp("HH:mm:ss"))}] ${colors.green(tag)} ${this.colorize(pattern)}`;
console.log(message, ...args);
}
}
public tag: string;
constructor(tag: string) {
this.tag = tag;
}
v(...args: any) {
Log.write(-1, this.tag, ...args);
}
d(...args: any) {
Log.write(0, this.tag, ...args);
}
i(...args: any) {
Log.write(1, this.tag, ...args);
}
w(...args: any) {
Log.write(2, this.tag, ...args);
}
e(...args: any) {
Log.write(3, this.tag, ...args);
}
}