@steve02081504/virtual-console 0.1.4 → 0.1.6
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/browser.mjs +8 -3
- package/package.json +1 -1
- package/util.mjs +1 -1
package/browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FullProxy } from 'full-proxy'
|
|
2
2
|
|
|
3
|
-
import { argsToHtml, safeString, circularToString } from './util.mjs'
|
|
3
|
+
import { argsToHtml, safeString, circularToString, escapeHtml } from './util.mjs'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 存储原始的浏览器 console 对象。
|
|
@@ -123,7 +123,7 @@ export class VirtualConsole {
|
|
|
123
123
|
...options,
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
const methods = ['log', 'info', 'warn', 'debug', 'error', 'table', 'dir', 'assert', 'count', 'countReset', 'time', 'timeLog', 'timeEnd', 'group', 'groupCollapsed', 'groupEnd']
|
|
126
|
+
const methods = ['log', 'info', 'warn', 'debug', 'error', 'table', 'dir', 'assert', 'count', 'countReset', 'time', 'timeLog', 'timeEnd', 'group', 'groupCollapsed', 'groupEnd', 'trace']
|
|
127
127
|
for (const method of methods)
|
|
128
128
|
if (this.#base_console[method] instanceof Function)
|
|
129
129
|
/**
|
|
@@ -138,6 +138,12 @@ export class VirtualConsole {
|
|
|
138
138
|
if (this.options.recordOutput) {
|
|
139
139
|
this.outputs += formatArgs(args) + '\n'
|
|
140
140
|
this.outputsHtml += argsToHtml(args) + '<br/>\n'
|
|
141
|
+
|
|
142
|
+
if (method == 'trace') {
|
|
143
|
+
const stack = new Error().stack || '\nNot available'
|
|
144
|
+
this.outputs += stack.slice(stack.indexOf('\n') + 1) + '\n'
|
|
145
|
+
this.outputsHtml += escapeHtml(stack.slice(stack.indexOf('\n') + 1)) + '<br/>\n'
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
// 实际输出
|
|
@@ -202,7 +208,6 @@ export class VirtualConsole {
|
|
|
202
208
|
this.outputsHtml = ''
|
|
203
209
|
if (this.options.realConsoleOutput)
|
|
204
210
|
this.#base_console.clear()
|
|
205
|
-
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
|
package/package.json
CHANGED
package/util.mjs
CHANGED
|
@@ -7,7 +7,7 @@ const ansi_up = new AnsiUp()
|
|
|
7
7
|
* @param {string} str - 要转义的字符串。
|
|
8
8
|
* @returns {string} 转义后的字符串。
|
|
9
9
|
*/
|
|
10
|
-
function escapeHtml(str) {
|
|
10
|
+
export function escapeHtml(str) {
|
|
11
11
|
return str.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>')
|
|
12
12
|
}
|
|
13
13
|
|