@ixfx/debug 0.36.0
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/dist/__tests__/test.d.ts +2 -0
- package/dist/__tests__/test.d.ts.map +1 -0
- package/dist/__tests__/test.js +1 -0
- package/dist/src/fps-counter.d.ts +2 -0
- package/dist/src/fps-counter.d.ts.map +1 -0
- package/dist/src/fps-counter.js +16 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +11 -0
- package/dist/src/logger.d.ts +77 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +142 -0
- package/dist/src/types.d.ts +13 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/util.d.ts +2 -0
- package/dist/src/util.d.ts.map +1 -0
- package/dist/src/util.js +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../__tests__/test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fps-counter.d.ts","sourceRoot":"","sources":["../../src/fps-counter.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,qBAAkB,EAAE,2BAAwB,iBAetE,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const fpsCounter = (autoDisplay = true, computeAfterFrames = 500) => {
|
|
2
|
+
let count = 0;
|
|
3
|
+
let lastFps = 0;
|
|
4
|
+
let countStart = performance.now();
|
|
5
|
+
return () => {
|
|
6
|
+
if (count++ >= computeAfterFrames) {
|
|
7
|
+
const elapsed = performance.now() - countStart;
|
|
8
|
+
countStart = performance.now();
|
|
9
|
+
count = 0;
|
|
10
|
+
lastFps = Math.floor((computeAfterFrames / elapsed) * 1000);
|
|
11
|
+
if (autoDisplay)
|
|
12
|
+
console.log(`fps: ${lastFps}`);
|
|
13
|
+
}
|
|
14
|
+
return lastFps;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,eAAe,GAAI,IAAI,OAAO,KAAG,MAM7C,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { MessageLogger } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a console logging function which prefixes messages. This is
|
|
4
|
+
* useful for tracing messages from different components. Each prefix
|
|
5
|
+
* is assigned a colour, further helping to distinguish messages.
|
|
6
|
+
*
|
|
7
|
+
* Use {@link logSet} to get a bundled set.
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* // Initialise once
|
|
11
|
+
* const log = logger(`a`);
|
|
12
|
+
* const error = logger(`a`, `error`);
|
|
13
|
+
* const warn = logger(`a`, `warn);
|
|
14
|
+
*
|
|
15
|
+
* // And then use
|
|
16
|
+
* log(`Hello`); // console.log(`a Hello`);
|
|
17
|
+
* error(`Uh-oh`); // console.error(`a Uh-oh`);
|
|
18
|
+
* warn(`Eek!`); // console.warn(`a Eeek!`);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Provide the `colourKey` parameter to make log messages
|
|
22
|
+
* be coloured the same, even though the prefix is different.
|
|
23
|
+
* ```js
|
|
24
|
+
* // Both loggers will use the same colour because they
|
|
25
|
+
* // share the colour key `system`
|
|
26
|
+
* const log = logger(`a`,`log`,`system`);
|
|
27
|
+
* const log2 = logger(`b`, `log`, `system`);
|
|
28
|
+
* ```
|
|
29
|
+
* @param prefix
|
|
30
|
+
* @param kind
|
|
31
|
+
* @param colourKey Optional key to colour log lines by instead of prefix
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare const logger: (prefix: string, kind?: `log` | `warn` | `error`, colourKey?: string) => MessageLogger;
|
|
35
|
+
/**
|
|
36
|
+
* Returns a bundled collection of {@link logger}s
|
|
37
|
+
*
|
|
38
|
+
* ```js
|
|
39
|
+
* const con = logSet(`a`);
|
|
40
|
+
* con.log(`Hello`); // console.log(`a Hello`);
|
|
41
|
+
* con.warn(`Uh-oh`); // console.warn(`a Uh-oh`);
|
|
42
|
+
* con.error(`Eek!`); // console.error(`a Eek!`);
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* By default each prefix is assigned a colour. To use
|
|
46
|
+
* another logic, provide the `colourKey` parameter.
|
|
47
|
+
*
|
|
48
|
+
* ```js
|
|
49
|
+
* // Both set of loggers will use same colour
|
|
50
|
+
* const con = logSet(`a`, true, `system`);
|
|
51
|
+
* const con2 = logSet(`b`, true, `system`);
|
|
52
|
+
* ```
|
|
53
|
+
* @param prefix Prefix for log messages
|
|
54
|
+
* @param verbose True by default. If false, log() messages are a no-op
|
|
55
|
+
* @param colourKey If specified, log messages will be coloured by this key instead of prefix (default)
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
export declare const logSet: (prefix: string, verbose?: boolean, colourKey?: string) => {
|
|
59
|
+
log: MessageLogger;
|
|
60
|
+
warn: MessageLogger;
|
|
61
|
+
error: MessageLogger;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Either a flag for default console logging, or a simple log function
|
|
65
|
+
*/
|
|
66
|
+
export type LogOption = boolean | MessageLogger;
|
|
67
|
+
/**
|
|
68
|
+
* Resolve a LogOption to a function
|
|
69
|
+
* @param l
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
export declare const resolveLogOption: (l?: LogOption, defaults?: {
|
|
73
|
+
readonly category?: string;
|
|
74
|
+
readonly kind?: string;
|
|
75
|
+
}) => MessageLogger;
|
|
76
|
+
export declare const logColours: (key: string, args?: unknown) => string;
|
|
77
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAKH,eAAO,MAAM,MAAM,GAEf,QAAQ,MAAM,EACd,OAAM,KAAK,GAAG,MAAM,GAAG,OAAe,EACtC,YAAY,MAAM,KACjB,aAuBA,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;EAsBE;AACF,eAAO,MAAM,MAAM,GAAI,QAAQ,MAAM,EAAE,iBAAc,EAAE,YAAY,MAAM;;;;CAgBxE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,IAAI,SAAS,EACb,WAAU;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,KACpE,aAqCF,CAAC;AAIF,eAAO,MAAM,UAAU,yCAGrB,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { getOrGenerateSync } from "./util.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a console logging function which prefixes messages. This is
|
|
4
|
+
* useful for tracing messages from different components. Each prefix
|
|
5
|
+
* is assigned a colour, further helping to distinguish messages.
|
|
6
|
+
*
|
|
7
|
+
* Use {@link logSet} to get a bundled set.
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* // Initialise once
|
|
11
|
+
* const log = logger(`a`);
|
|
12
|
+
* const error = logger(`a`, `error`);
|
|
13
|
+
* const warn = logger(`a`, `warn);
|
|
14
|
+
*
|
|
15
|
+
* // And then use
|
|
16
|
+
* log(`Hello`); // console.log(`a Hello`);
|
|
17
|
+
* error(`Uh-oh`); // console.error(`a Uh-oh`);
|
|
18
|
+
* warn(`Eek!`); // console.warn(`a Eeek!`);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Provide the `colourKey` parameter to make log messages
|
|
22
|
+
* be coloured the same, even though the prefix is different.
|
|
23
|
+
* ```js
|
|
24
|
+
* // Both loggers will use the same colour because they
|
|
25
|
+
* // share the colour key `system`
|
|
26
|
+
* const log = logger(`a`,`log`,`system`);
|
|
27
|
+
* const log2 = logger(`b`, `log`, `system`);
|
|
28
|
+
* ```
|
|
29
|
+
* @param prefix
|
|
30
|
+
* @param kind
|
|
31
|
+
* @param colourKey Optional key to colour log lines by instead of prefix
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export const logger = (prefix, kind = `log`, colourKey) => (m) => {
|
|
35
|
+
if (m === undefined) {
|
|
36
|
+
m = `(undefined)`;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof m === `object`) {
|
|
39
|
+
m = JSON.stringify(m);
|
|
40
|
+
}
|
|
41
|
+
const colour = colourKey ?? prefix;
|
|
42
|
+
switch (kind) {
|
|
43
|
+
case `log`: {
|
|
44
|
+
console.log(`%c${prefix} ${m}`, `color: ${logColours(colour)}`);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case `warn`: {
|
|
48
|
+
console.warn(prefix, m);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case `error`: {
|
|
52
|
+
console.error(prefix, m);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Returns a bundled collection of {@link logger}s
|
|
59
|
+
*
|
|
60
|
+
* ```js
|
|
61
|
+
* const con = logSet(`a`);
|
|
62
|
+
* con.log(`Hello`); // console.log(`a Hello`);
|
|
63
|
+
* con.warn(`Uh-oh`); // console.warn(`a Uh-oh`);
|
|
64
|
+
* con.error(`Eek!`); // console.error(`a Eek!`);
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* By default each prefix is assigned a colour. To use
|
|
68
|
+
* another logic, provide the `colourKey` parameter.
|
|
69
|
+
*
|
|
70
|
+
* ```js
|
|
71
|
+
* // Both set of loggers will use same colour
|
|
72
|
+
* const con = logSet(`a`, true, `system`);
|
|
73
|
+
* const con2 = logSet(`b`, true, `system`);
|
|
74
|
+
* ```
|
|
75
|
+
* @param prefix Prefix for log messages
|
|
76
|
+
* @param verbose True by default. If false, log() messages are a no-op
|
|
77
|
+
* @param colourKey If specified, log messages will be coloured by this key instead of prefix (default)
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
export const logSet = (prefix, verbose = true, colourKey) => {
|
|
81
|
+
if (verbose) {
|
|
82
|
+
return {
|
|
83
|
+
log: logger(prefix, `log`, colourKey),
|
|
84
|
+
warn: logger(prefix, `warn`, colourKey),
|
|
85
|
+
error: logger(prefix, `error`, colourKey),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
log: (_) => {
|
|
90
|
+
/** no-op */
|
|
91
|
+
},
|
|
92
|
+
warn: logger(prefix, `warn`, colourKey),
|
|
93
|
+
error: logger(prefix, `error`, colourKey),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Resolve a LogOption to a function
|
|
98
|
+
* @param l
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export const resolveLogOption = (l, defaults = {}) => {
|
|
102
|
+
if (l === undefined || (typeof l === `boolean` && !l)) {
|
|
103
|
+
return (_) => {
|
|
104
|
+
/** no-op */
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const defaultCat = defaults.category ?? ``;
|
|
108
|
+
const defaultKind = defaults.kind ?? undefined;
|
|
109
|
+
if (typeof l === `boolean`) {
|
|
110
|
+
return (messageOrString) => {
|
|
111
|
+
const m = typeof messageOrString === `string` ? { msg: messageOrString } : messageOrString;
|
|
112
|
+
const kind = m.kind ?? defaultKind;
|
|
113
|
+
const category = m.category ?? defaultCat;
|
|
114
|
+
let message = m.msg;
|
|
115
|
+
if (category)
|
|
116
|
+
message = `[${category}] ${message}`;
|
|
117
|
+
switch (kind) {
|
|
118
|
+
case `error`: {
|
|
119
|
+
console.error(message);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case `warn`: {
|
|
123
|
+
console.warn(message);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case `info`: {
|
|
127
|
+
console.info(message);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default: {
|
|
131
|
+
console.log(message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return l;
|
|
137
|
+
};
|
|
138
|
+
let logColourCount = 0;
|
|
139
|
+
export const logColours = getOrGenerateSync(new Map(), () => {
|
|
140
|
+
const hue = ++logColourCount * 137.508; // use golden angle approximation
|
|
141
|
+
return `hsl(${hue},50%,75%)`;
|
|
142
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type LogSet = {
|
|
2
|
+
readonly log: MessageLogger;
|
|
3
|
+
readonly warn: MessageLogger;
|
|
4
|
+
readonly error: MessageLogger;
|
|
5
|
+
};
|
|
6
|
+
export type MessageLogger = (message: LogMessage | string) => void;
|
|
7
|
+
export type LogKind = `info` | `debug` | `error` | `warn`;
|
|
8
|
+
export type LogMessage = {
|
|
9
|
+
readonly kind?: LogKind;
|
|
10
|
+
readonly msg: any;
|
|
11
|
+
readonly category?: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B,CAAA;AACD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,KAAK,IAAI,CAAC;AACnE,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAC3B,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,MAClD,KAAK,CAAC,EAAE,OAAO,CAAC,KAAG,CAMnB,CAAC"}
|
package/dist/src/util.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/fps-counter.ts","../src/index.ts","../src/logger.ts","../src/types.ts","../src/util.ts","../__tests__/test.ts"],"version":"5.8.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ixfx/debug",
|
|
3
|
+
"version": "0.36.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"import": "./src/index.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"main": "dist/src/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/src/index.d.ts",
|
|
22
|
+
"import": "./dist/src/index.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|