-
Notifications
You must be signed in to change notification settings - Fork 4
/
debug.ts
162 lines (130 loc) · 5.37 KB
/
debug.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
export class Debugger implements Console {
public Console: any;
protected console: Console;
protected isEnabled: boolean;
protected prefix: string = '';
public constructor(console: Console, isEnabled: boolean = true, prefix: string = '') {
this.console = console;
this.isEnabled = isEnabled;
this.prefix = prefix;
}
public get memory(): any {
return this.doIfEnabled(() => console.hasOwnProperty('memory') && console.memory);
}
public assert(value: any, message?: string, ...optionalParams: any[]): void;
public assert(test?: boolean, message?: string, ...optionalParams: any[]): void;
public assert(value?, message?: string, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.assert(value, message, ...optionalParams));
}
public countReset(label?: string): void {
return this.doIfEnabled(() => this.console.countReset(label));
}
public dir(obj: any, options?: { showHidden?: boolean; depth?: number; colors?: boolean }): void;
public dir(value?: any, ...optionalParams: any[]): void;
public dir(obj?: any, ...options): void {
return this.doIfEnabled(() => this.console.dir(obj, ...options));
}
public error(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.error(this.addPrefix(message), ...optionalParams));
}
public info(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.info(this.addPrefix(message), ...optionalParams));
}
public log(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.log(this.addPrefix(message), ...optionalParams));
}
public time(label: string): void;
public time(timerName?: string): void;
public time(label?: string): void {
return this.doIfEnabled(() => this.console.time(label));
}
public timeEnd(label: string): void;
public timeEnd(timerName?: string): void;
public timeEnd(label?: string): void {
return this.doIfEnabled(() => this.console.timeEnd(label));
}
public timeLog(label: string, ...data: any[]): void {
return this.doIfEnabled(() => this.console.timeLog(label, data));
}
public timeStamp(label: string): void;
public timeStamp(timerName?: string): void;
public timeStamp(label?: string): void {
return this.doIfEnabled(() => this.console.timeStamp(label));
}
public timeline(label: string): void;
public timeline(timerName?: string): void;
public timeline(label?: string): void {
return this.doIfEnabled(() => this.console.timeline(label));
}
public timelineEnd(label: string): void;
public timelineEnd(timerName?: string): void;
public timelineEnd(label?: string): void {
return this.doIfEnabled(() => this.console.timelineEnd(label));
}
public trace(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.trace(this.addPrefix(message), ...optionalParams));
}
public warn(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.warn(this.addPrefix(message), ...optionalParams));
}
public clear(): void {
return this.doIfEnabled(() => this.console.clear());
}
public count(countTitle?: string): void {
return this.doIfEnabled(() => this.console.count());
}
public debug(message?: any, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.debug(this.addPrefix(message), ...optionalParams));
}
public dirxml(value: any): void {
return this.doIfEnabled(() => this.console.dirxml(value));
}
public exception(message?: string, ...optionalParams: any[]): void {
return this.doIfEnabled(() => this.console.exception(this.addPrefix(message), ...optionalParams));
}
public group(groupTitle?: string): void {
return this.doIfEnabled(() => this.console.group(groupTitle));
}
public groupCollapsed(groupTitle?: string): void {
return this.doIfEnabled(() => this.console.groupCollapsed(groupTitle));
}
public groupEnd(): void {
return this.doIfEnabled(() => this.console.groupEnd());
}
public markTimeline(label?: string): void {
return this.doIfEnabled(() => this.console.markTimeline(label));
}
public profile(reportName?: string): void {
return this.doIfEnabled(() => this.console.profile(reportName));
}
public profileEnd(): void {
return this.doIfEnabled(() => this.console.profileEnd());
}
public table(...data: any[]): void {
return this.doIfEnabled(() => this.console.table(...data));
}
/**
* Throws usual error in debug mode and non-blocking otherwise
* @param {Error} error
*/
public throw(error: Error) {
error.message = this.addPrefix(error.message);
if (this.isEnabled) {
throw error;
}
setTimeout(() => {
throw error;
});
}
protected doIfEnabled(action: Function): any {
if (this.isEnabled) {
return action();
}
}
protected addPrefix(message: any): any {
if (this.prefix && (typeof message === 'string' || !message)) {
return this.prefix + message;
}
return message;
}
}