-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
64 lines (64 loc) · 2.22 KB
/
index.ts
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
type options = (content:string) => string
let NormalConsole = console.log
class color {
static black(content: string): string {
return `\x1b[30m${content}\x1b[0m`
}
static red(content: string): string {
return `\x1b[31m${content}\x1b[0m`
}
static green(content: string): string {
return `\x1b[32m${content}\x1b[0m`
}
static yellow(content: string): string {
return `\x1b[33m${content}\x1b[0m`
}
static blue(content: string): string {
return `\x1b[34m${content}\x1b[0m`
}
static magenta(content: string): string {
return `\x1b[35m${content}\x1b[0m`
}
static cyan(content: string): string {
return `\x1b[36m${content}\x1b[0m`
}
static white(content: string): string {
return `\x1b[37m${content}\x1b[0m`
}
}
export default class log4debug {
static set(...func:options[]) {
let newConsole = console.log
console.log = (...data: any[]) => {
let content = data.join(" ")
if (func.length !== 0) for (let i = func.length-1; -1 < i; i--) if (typeof func[i] === "function") content = func[i](content)
newConsole(content)
}
}
static setClear(timeout:number|null,content:string|null,...func:options[]) {
let newClear = console.clear
console.clear = () => {
if (content !== null) if (func.length !== 0) {
for (let i = func.length-1; -1 < i; i--) content = func[i](content)
NormalConsole(content)
} else console.log(content)
setTimeout(() => {
newClear()
}, timeout === null ? 0 : timeout);
}
}
static defaultTemplate(content:string):string {
let date = new Date
let year = date.getFullYear()
let month = date.getMonth()-1
let day = date.getDay()
let time = date.getTime()
return `${color.magenta(`[${year}-${month}-${day}:${time}]`)}${color.green("[LOG]")}: ${content}`
}
static defaultFrameTemplate(content:string):string {
let line = ""
for (let i = 0; i < content.split("").length+4; i++) line += "-"
return `${line}\n| ${content} |\n${line}`
}
static color = color
}