@leafer/debug 1.0.0-rc.3 → 1.0.0-rc.30

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.3",
3
+ "version": "1.0.0-rc.30",
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.3"
25
+ "@leafer/math": "1.0.0-rc.30"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.3"
28
+ "@leafer/interface": "1.0.0-rc.30"
29
29
  }
30
30
  }
package/src/Debug.ts CHANGED
@@ -8,6 +8,7 @@ export class Debug {
8
8
  static excludeList: string[] = []
9
9
 
10
10
  // other
11
+ static showWarn = true
11
12
  static showRepaint: boolean
12
13
  static showHitView: boolean | string | string[]
13
14
  static showBoundsView: boolean | string | string[]
@@ -25,15 +26,11 @@ export class Debug {
25
26
  }
26
27
 
27
28
  static set filter(name: string | string[]) {
28
- if (!name) name = []
29
- else if (typeof name === 'string') name = [name]
30
- this.filterList = name
29
+ this.filterList = getNameList(name)
31
30
  }
32
31
 
33
32
  static set exclude(name: string | string[]) {
34
- if (!name) name = []
35
- else if (typeof name === 'string') name = [name]
36
- this.excludeList = name
33
+ this.excludeList = getNameList(name)
37
34
  }
38
35
 
39
36
 
@@ -45,8 +42,12 @@ export class Debug {
45
42
  }
46
43
  }
47
44
 
45
+ tip(...messages: unknown[]): void {
46
+ if (D.enable) this.warn(...messages)
47
+ }
48
+
48
49
  warn(...messages: unknown[]): void {
49
- if (D.enable) console.warn(this.name, ...messages)
50
+ if (D.showWarn) console.warn(this.name, ...messages)
50
51
  }
51
52
 
52
53
  repeat(name: string, ...messages: unknown[]) {
@@ -65,4 +66,10 @@ export class Debug {
65
66
  }
66
67
  }
67
68
 
69
+ function getNameList(name: string | string[]): string[] {
70
+ if (!name) name = []
71
+ else if (typeof name === 'string') name = [name]
72
+ return name
73
+ }
74
+
68
75
  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,22 +6,22 @@ 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;
23
22
  static filterList: string[];
24
23
  static excludeList: string[];
24
+ static showWarn: boolean;
25
25
  static showRepaint: boolean;
26
26
  static showHitView: boolean | string | string[];
27
27
  static showBoundsView: boolean | string | string[];
@@ -32,6 +32,7 @@ declare class Debug {
32
32
  static set filter(name: string | string[]);
33
33
  static set exclude(name: string | string[]);
34
34
  log(...messages: unknown[]): void;
35
+ tip(...messages: unknown[]): void;
35
36
  warn(...messages: unknown[]): void;
36
37
  repeat(name: string, ...messages: unknown[]): void;
37
38
  error(...messages: unknown[]): void;