@leafer/debug 1.0.0-rc.2 → 1.0.0-rc.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/debug",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.20",
4
4
  "description": "@leafer/debug",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.2"
25
+ "@leafer/math": "1.0.0-rc.20"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.2"
28
+ "@leafer/interface": "1.0.0-rc.20"
29
29
  }
30
30
  }
package/src/Debug.ts CHANGED
@@ -25,15 +25,11 @@ export class Debug {
25
25
  }
26
26
 
27
27
  static set filter(name: string | string[]) {
28
- if (!name) name = []
29
- else if (typeof name === 'string') name = [name]
30
- this.filterList = name
28
+ this.filterList = getNameList(name)
31
29
  }
32
30
 
33
31
  static set exclude(name: string | string[]) {
34
- if (!name) name = []
35
- else if (typeof name === 'string') name = [name]
36
- this.excludeList = name
32
+ this.excludeList = getNameList(name)
37
33
  }
38
34
 
39
35
 
@@ -45,8 +41,12 @@ export class Debug {
45
41
  }
46
42
  }
47
43
 
44
+ tip(...messages: unknown[]): void {
45
+ if (D.enable) this.warn(...messages)
46
+ }
47
+
48
48
  warn(...messages: unknown[]): void {
49
- if (D.enable) console.warn(this.name, ...messages)
49
+ console.warn(this.name, ...messages)
50
50
  }
51
51
 
52
52
  repeat(name: string, ...messages: unknown[]) {
@@ -65,4 +65,10 @@ export class Debug {
65
65
  }
66
66
  }
67
67
 
68
+ function getNameList(name: string | string[]): string[] {
69
+ if (!name) name = []
70
+ else if (typeof name === 'string') name = [name]
71
+ return name
72
+ }
73
+
68
74
  const D = Debug
package/src/Run.ts CHANGED
@@ -12,37 +12,31 @@ interface names {
12
12
 
13
13
  const debug = Debug.get('RunTime')
14
14
 
15
- export class Run {
15
+ export const Run = {
16
16
 
17
- static currentId: number
18
- static currentTime: number
19
- static currentName: string
17
+ currentId: 0,
18
+ currentName: '',
20
19
 
21
- static idMap: ids = {}
22
- static nameMap: names = {}
23
- static nameToIdMap: ids = {}
20
+ idMap: {} as ids,
21
+ nameMap: {} as names,
22
+ nameToIdMap: {} as ids,
24
23
 
25
- static start(name: string, microsecond?: boolean): number {
24
+ start(name: string, microsecond?: boolean): number {
26
25
  const id = IncrementId.create(IncrementId.RUNTIME)
27
26
  R.currentId = R.idMap[id] = microsecond ? performance.now() : Date.now()
28
27
  R.currentName = R.nameMap[id] = name
29
28
  R.nameToIdMap[name] = id
30
29
  return id
31
- }
30
+ },
32
31
 
33
- static end(id: number, microsecond?: boolean): void {
34
- const time = R.idMap[id]
35
- const name = R.nameMap[id]
32
+ end(id: number, microsecond?: boolean): void {
33
+ const time = R.idMap[id], name = R.nameMap[id]
34
+ const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time
36
35
  R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined
36
+ debug.log(name, duration, 'ms')
37
+ },
37
38
 
38
- if (microsecond) {
39
- debug.log(name, performance.now() - time, 'µs')
40
- } else {
41
- debug.log(name, Date.now() - time, 'ms')
42
- }
43
- }
44
-
45
- static endOfName(name: string, microsecond?: boolean): void {
39
+ endOfName(name: string, microsecond?: boolean): void {
46
40
  const id = R.nameToIdMap[name]
47
41
  if (id !== undefined) R.end(id, microsecond)
48
42
  }
package/types/index.d.ts CHANGED
@@ -6,17 +6,16 @@ interface ids {
6
6
  interface names {
7
7
  [name: string]: string;
8
8
  }
9
- declare class Run {
10
- static currentId: number;
11
- static currentTime: number;
12
- static currentName: string;
13
- static idMap: ids;
14
- static nameMap: names;
15
- static nameToIdMap: ids;
16
- static start(name: string, microsecond?: boolean): number;
17
- static end(id: number, microsecond?: boolean): void;
18
- static endOfName(name: string, microsecond?: boolean): void;
19
- }
9
+ declare const Run: {
10
+ currentId: number;
11
+ currentName: string;
12
+ idMap: ids;
13
+ nameMap: names;
14
+ nameToIdMap: ids;
15
+ start(name: string, microsecond?: boolean): number;
16
+ end(id: number, microsecond?: boolean): void;
17
+ endOfName(name: string, microsecond?: boolean): void;
18
+ };
20
19
 
21
20
  declare class Debug {
22
21
  static enable: boolean;
@@ -32,6 +31,7 @@ declare class Debug {
32
31
  static set filter(name: string | string[]);
33
32
  static set exclude(name: string | string[]);
34
33
  log(...messages: unknown[]): void;
34
+ tip(...messages: unknown[]): void;
35
35
  warn(...messages: unknown[]): void;
36
36
  repeat(name: string, ...messages: unknown[]): void;
37
37
  error(...messages: unknown[]): void;