@steve02081504/virtual-console 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. package/browser.mjs +8 -3
  2. package/package.json +1 -1
  3. 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
  /**
@@ -140,6 +140,12 @@ export class VirtualConsole {
140
140
  this.outputsHtml += argsToHtml(args) + '<br/>\n'
141
141
  }
142
142
 
143
+ if (method == 'trace') {
144
+ const stack = new Error().stack
145
+ this.outputs += stack.slice(stack.indexOf('\n') + 1) + '\n'
146
+ this.outputsHtml += escapeHtml(stack.slice(stack.indexOf('\n') + 1)) + '<br/>\n'
147
+ }
148
+
143
149
  // 实际输出
144
150
  if (this.options.realConsoleOutput)
145
151
  this.#base_console[method](...args)
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/virtual-console",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A virtual console for capturing and manipulating terminal output.",
5
5
  "main": "main.mjs",
6
6
  "type": "module",
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('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
12
12
  }
13
13