happy-dom 10.11.2 → 11.0.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.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (160) hide show
  1. package/.eslintrc.cjs +1 -1
  2. package/cjs/console/VirtualConsole.cjs +351 -0
  3. package/cjs/console/VirtualConsole.cjs.map +1 -0
  4. package/cjs/console/VirtualConsole.d.ts +163 -0
  5. package/cjs/console/VirtualConsole.d.ts.map +1 -0
  6. package/cjs/console/VirtualConsolePrinter.cjs +101 -0
  7. package/cjs/console/VirtualConsolePrinter.cjs.map +1 -0
  8. package/cjs/console/VirtualConsolePrinter.d.ts +55 -0
  9. package/cjs/console/VirtualConsolePrinter.d.ts.map +1 -0
  10. package/cjs/console/enums/VirtualConsoleLogLevelEnum.cjs +16 -0
  11. package/cjs/console/enums/VirtualConsoleLogLevelEnum.cjs.map +1 -0
  12. package/cjs/console/enums/VirtualConsoleLogLevelEnum.d.ts +13 -0
  13. package/cjs/console/enums/VirtualConsoleLogLevelEnum.d.ts.map +1 -0
  14. package/cjs/console/enums/VirtualConsoleLogTypeEnum.cjs +30 -0
  15. package/cjs/console/enums/VirtualConsoleLogTypeEnum.cjs.map +1 -0
  16. package/cjs/console/enums/VirtualConsoleLogTypeEnum.d.ts +23 -0
  17. package/cjs/console/enums/VirtualConsoleLogTypeEnum.d.ts.map +1 -0
  18. package/cjs/console/types/IVirtualConsoleLogEntry.cjs +3 -0
  19. package/cjs/console/types/IVirtualConsoleLogEntry.cjs.map +1 -0
  20. package/cjs/console/types/IVirtualConsoleLogEntry.d.ts +10 -0
  21. package/cjs/console/types/IVirtualConsoleLogEntry.d.ts.map +1 -0
  22. package/cjs/console/types/IVirtualConsoleLogGroup.cjs +3 -0
  23. package/cjs/console/types/IVirtualConsoleLogGroup.cjs.map +1 -0
  24. package/cjs/console/types/IVirtualConsoleLogGroup.d.ts +7 -0
  25. package/cjs/console/types/IVirtualConsoleLogGroup.d.ts.map +1 -0
  26. package/cjs/console/types/IVirtualConsolePrinter.cjs +3 -0
  27. package/cjs/console/types/IVirtualConsolePrinter.cjs.map +1 -0
  28. package/cjs/console/types/IVirtualConsolePrinter.d.ts +52 -0
  29. package/cjs/console/types/IVirtualConsolePrinter.d.ts.map +1 -0
  30. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.cjs +97 -0
  31. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.cjs.map +1 -0
  32. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.d.ts +35 -0
  33. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.d.ts.map +1 -0
  34. package/cjs/event/EventTarget.cjs +23 -5
  35. package/cjs/event/EventTarget.cjs.map +1 -1
  36. package/cjs/event/EventTarget.d.ts.map +1 -1
  37. package/cjs/nodes/element/Element.cjs.map +1 -1
  38. package/cjs/nodes/element/Element.d.ts +1 -1
  39. package/cjs/nodes/element/Element.d.ts.map +1 -1
  40. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs +8 -31
  41. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs.map +1 -1
  42. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts +0 -7
  43. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  44. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +2 -1
  45. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
  46. package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  47. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs +10 -55
  48. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs.map +1 -1
  49. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts +0 -14
  50. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  51. package/cjs/window/GlobalWindow.cjs +1 -9
  52. package/cjs/window/GlobalWindow.cjs.map +1 -1
  53. package/cjs/window/GlobalWindow.d.ts +1 -7
  54. package/cjs/window/GlobalWindow.d.ts.map +1 -1
  55. package/cjs/window/IHappyDOMOptions.d.ts +2 -0
  56. package/cjs/window/IHappyDOMOptions.d.ts.map +1 -1
  57. package/cjs/window/IWindow.d.ts +2 -7
  58. package/cjs/window/IWindow.d.ts.map +1 -1
  59. package/cjs/window/VMGlobalPropertyScript.cjs +1 -0
  60. package/cjs/window/VMGlobalPropertyScript.cjs.map +1 -1
  61. package/cjs/window/VMGlobalPropertyScript.d.ts +1 -1
  62. package/cjs/window/VMGlobalPropertyScript.d.ts.map +1 -1
  63. package/cjs/window/Window.cjs +51 -64
  64. package/cjs/window/Window.cjs.map +1 -1
  65. package/cjs/window/Window.d.ts +6 -23
  66. package/cjs/window/Window.d.ts.map +1 -1
  67. package/cjs/window/WindowErrorUtility.cjs +84 -0
  68. package/cjs/window/WindowErrorUtility.cjs.map +1 -0
  69. package/cjs/window/WindowErrorUtility.d.ts +38 -0
  70. package/cjs/window/WindowErrorUtility.d.ts.map +1 -0
  71. package/lib/console/VirtualConsole.d.ts +163 -0
  72. package/lib/console/VirtualConsole.d.ts.map +1 -0
  73. package/lib/console/VirtualConsole.js +322 -0
  74. package/lib/console/VirtualConsole.js.map +1 -0
  75. package/lib/console/VirtualConsolePrinter.d.ts +55 -0
  76. package/lib/console/VirtualConsolePrinter.d.ts.map +1 -0
  77. package/lib/console/VirtualConsolePrinter.js +95 -0
  78. package/lib/console/VirtualConsolePrinter.js.map +1 -0
  79. package/lib/console/enums/VirtualConsoleLogLevelEnum.d.ts +13 -0
  80. package/lib/console/enums/VirtualConsoleLogLevelEnum.d.ts.map +1 -0
  81. package/lib/console/enums/VirtualConsoleLogLevelEnum.js +14 -0
  82. package/lib/console/enums/VirtualConsoleLogLevelEnum.js.map +1 -0
  83. package/lib/console/enums/VirtualConsoleLogTypeEnum.d.ts +23 -0
  84. package/lib/console/enums/VirtualConsoleLogTypeEnum.d.ts.map +1 -0
  85. package/lib/console/enums/VirtualConsoleLogTypeEnum.js +28 -0
  86. package/lib/console/enums/VirtualConsoleLogTypeEnum.js.map +1 -0
  87. package/lib/console/types/IVirtualConsoleLogEntry.d.ts +10 -0
  88. package/lib/console/types/IVirtualConsoleLogEntry.d.ts.map +1 -0
  89. package/lib/console/types/IVirtualConsoleLogEntry.js +2 -0
  90. package/lib/console/types/IVirtualConsoleLogEntry.js.map +1 -0
  91. package/lib/console/types/IVirtualConsoleLogGroup.d.ts +7 -0
  92. package/lib/console/types/IVirtualConsoleLogGroup.d.ts.map +1 -0
  93. package/lib/console/types/IVirtualConsoleLogGroup.js +2 -0
  94. package/lib/console/types/IVirtualConsoleLogGroup.js.map +1 -0
  95. package/lib/console/types/IVirtualConsolePrinter.d.ts +52 -0
  96. package/lib/console/types/IVirtualConsolePrinter.d.ts.map +1 -0
  97. package/lib/console/types/IVirtualConsolePrinter.js +2 -0
  98. package/lib/console/types/IVirtualConsolePrinter.js.map +1 -0
  99. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.d.ts +35 -0
  100. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.d.ts.map +1 -0
  101. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.js +91 -0
  102. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.js.map +1 -0
  103. package/lib/event/EventTarget.d.ts.map +1 -1
  104. package/lib/event/EventTarget.js +23 -5
  105. package/lib/event/EventTarget.js.map +1 -1
  106. package/lib/nodes/element/Element.d.ts +1 -1
  107. package/lib/nodes/element/Element.d.ts.map +1 -1
  108. package/lib/nodes/element/Element.js.map +1 -1
  109. package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts +0 -7
  110. package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  111. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +8 -31
  112. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -1
  113. package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  114. package/lib/nodes/html-script-element/HTMLScriptElement.js +2 -1
  115. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  116. package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts +0 -14
  117. package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  118. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js +10 -55
  119. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -1
  120. package/lib/window/GlobalWindow.d.ts +1 -7
  121. package/lib/window/GlobalWindow.d.ts.map +1 -1
  122. package/lib/window/GlobalWindow.js +1 -9
  123. package/lib/window/GlobalWindow.js.map +1 -1
  124. package/lib/window/IHappyDOMOptions.d.ts +2 -0
  125. package/lib/window/IHappyDOMOptions.d.ts.map +1 -1
  126. package/lib/window/IWindow.d.ts +2 -7
  127. package/lib/window/IWindow.d.ts.map +1 -1
  128. package/lib/window/VMGlobalPropertyScript.d.ts +1 -1
  129. package/lib/window/VMGlobalPropertyScript.d.ts.map +1 -1
  130. package/lib/window/VMGlobalPropertyScript.js +1 -0
  131. package/lib/window/VMGlobalPropertyScript.js.map +1 -1
  132. package/lib/window/Window.d.ts +6 -23
  133. package/lib/window/Window.d.ts.map +1 -1
  134. package/lib/window/Window.js +51 -64
  135. package/lib/window/Window.js.map +1 -1
  136. package/lib/window/WindowErrorUtility.d.ts +38 -0
  137. package/lib/window/WindowErrorUtility.d.ts.map +1 -0
  138. package/lib/window/WindowErrorUtility.js +78 -0
  139. package/lib/window/WindowErrorUtility.js.map +1 -0
  140. package/package.json +2 -2
  141. package/src/console/VirtualConsole.ts +356 -0
  142. package/src/console/VirtualConsolePrinter.ts +107 -0
  143. package/src/console/enums/VirtualConsoleLogLevelEnum.ts +12 -0
  144. package/src/console/enums/VirtualConsoleLogTypeEnum.ts +29 -0
  145. package/src/console/types/IVirtualConsoleLogEntry.ts +10 -0
  146. package/src/console/types/IVirtualConsoleLogGroup.ts +6 -0
  147. package/src/console/types/IVirtualConsolePrinter.ts +58 -0
  148. package/src/console/utilities/VirtualConsoleLogEntryStringifier.ts +100 -0
  149. package/src/event/EventTarget.ts +27 -5
  150. package/src/nodes/element/Element.ts +1 -1
  151. package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +13 -35
  152. package/src/nodes/html-script-element/HTMLScriptElement.ts +4 -1
  153. package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +19 -62
  154. package/src/window/GlobalWindow.ts +1 -10
  155. package/src/window/IHappyDOMOptions.ts +1 -0
  156. package/src/window/IWindow.ts +2 -8
  157. package/src/window/VMGlobalPropertyScript.ts +1 -0
  158. package/src/window/Window.ts +77 -70
  159. package/src/window/WindowErrorUtility.ts +94 -0
  160. package/tsconfig.json +2 -3
package/.eslintrc.cjs CHANGED
@@ -137,7 +137,7 @@ module.exports = {
137
137
  ],
138
138
  '@typescript-eslint/ban-ts-comment': OFF,
139
139
  'jsdoc/no-types': WARN,
140
- 'import/named': WARN,
140
+ 'import/named': OFF,
141
141
  'import/no-named-as-default': WARN,
142
142
  'import/no-extraneous-dependencies': WARN,
143
143
  'import/no-absolute-path': WARN,
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const VirtualConsoleLogLevelEnum_js_1 = __importDefault(require("./enums/VirtualConsoleLogLevelEnum.cjs"));
30
+ const VirtualConsoleLogTypeEnum_js_1 = __importDefault(require("./enums/VirtualConsoleLogTypeEnum.cjs"));
31
+ const PerfHooks = __importStar(require("perf_hooks"));
32
+ /**
33
+ * Virtual Console.
34
+ *
35
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Console
36
+ */
37
+ class VirtualConsole {
38
+ /**
39
+ * Constructor.
40
+ *
41
+ * @param printer Console printer.
42
+ */
43
+ constructor(printer) {
44
+ this._count = {};
45
+ this._time = {};
46
+ this._groupID = 0;
47
+ this._groups = [];
48
+ this._printer = printer;
49
+ }
50
+ /**
51
+ * Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
52
+ *
53
+ * @param assertion Assertion.
54
+ * @param args Arguments.
55
+ */
56
+ assert(assertion, ...args) {
57
+ if (!assertion) {
58
+ this._printer.print({
59
+ type: VirtualConsoleLogTypeEnum_js_1.default.assert,
60
+ level: VirtualConsoleLogLevelEnum_js_1.default.error,
61
+ message: ['Assertion failed:', ...args],
62
+ group: this._groups[this._groups.length - 1] || null
63
+ });
64
+ }
65
+ }
66
+ /**
67
+ * Clears the console.
68
+ */
69
+ clear() {
70
+ this._printer.clear();
71
+ }
72
+ /**
73
+ * Logs the number of times that this particular call to count() has been called.
74
+ *
75
+ * @param [label='default'] Label.
76
+ */
77
+ count(label = 'default') {
78
+ if (!this._count[label]) {
79
+ this._count[label] = 0;
80
+ }
81
+ this._count[label]++;
82
+ this._printer.print({
83
+ type: VirtualConsoleLogTypeEnum_js_1.default.count,
84
+ level: VirtualConsoleLogLevelEnum_js_1.default.info,
85
+ message: [`${label}: ${this._count[label]}`],
86
+ group: this._groups[this._groups.length - 1] || null
87
+ });
88
+ }
89
+ /**
90
+ * Resets the counter.
91
+ *
92
+ * @param [label='default'] Label.
93
+ */
94
+ countReset(label = 'default') {
95
+ delete this._count[label];
96
+ this._printer.print({
97
+ type: VirtualConsoleLogTypeEnum_js_1.default.countReset,
98
+ level: VirtualConsoleLogLevelEnum_js_1.default.warn,
99
+ message: [`${label}: 0`],
100
+ group: this._groups[this._groups.length - 1] || null
101
+ });
102
+ }
103
+ /**
104
+ * Outputs a message to the web console at the "debug" log level.
105
+ *
106
+ * @param args Arguments.
107
+ */
108
+ debug(...args) {
109
+ this._printer.print({
110
+ type: VirtualConsoleLogTypeEnum_js_1.default.debug,
111
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
112
+ message: args,
113
+ group: this._groups[this._groups.length - 1] || null
114
+ });
115
+ }
116
+ /**
117
+ * Displays an interactive list of the properties of the specified JavaScript object.
118
+ *
119
+ * @param data Data.
120
+ */
121
+ dir(data) {
122
+ this._printer.print({
123
+ type: VirtualConsoleLogTypeEnum_js_1.default.dir,
124
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
125
+ message: [data],
126
+ group: this._groups[this._groups.length - 1] || null
127
+ });
128
+ }
129
+ /**
130
+ * Displays an interactive tree of the descendant elements of the specified XML/HTML element.
131
+ *
132
+ * @param data Data.
133
+ */
134
+ dirxml(data) {
135
+ this._printer.print({
136
+ type: VirtualConsoleLogTypeEnum_js_1.default.dirxml,
137
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
138
+ message: [data],
139
+ group: this._groups[this._groups.length - 1] || null
140
+ });
141
+ }
142
+ /**
143
+ * Outputs an error message to the console.
144
+ *
145
+ * @param args Arguments.
146
+ */
147
+ error(...args) {
148
+ this._printer.print({
149
+ type: VirtualConsoleLogTypeEnum_js_1.default.error,
150
+ level: VirtualConsoleLogLevelEnum_js_1.default.error,
151
+ message: args,
152
+ group: this._groups[this._groups.length - 1] || null
153
+ });
154
+ }
155
+ /**
156
+ * Alias for error().
157
+ *
158
+ * @deprecated
159
+ * @alias error()
160
+ * @param args Arguments.
161
+ */
162
+ exception(...args) {
163
+ this.error(...args);
164
+ }
165
+ /**
166
+ * Creates a new inline group in the console, causing any subsequent console messages to be indented by an additional level, until console.groupEnd() is called.
167
+ *
168
+ * @param [label] Label.
169
+ */
170
+ group(label) {
171
+ this._groupID++;
172
+ const group = {
173
+ id: this._groupID,
174
+ label: label || 'default',
175
+ collapsed: false,
176
+ parent: this._groups[this._groups.length - 1] || null
177
+ };
178
+ this._groups.push(group);
179
+ this._printer.print({
180
+ type: VirtualConsoleLogTypeEnum_js_1.default.group,
181
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
182
+ message: [label || 'default'],
183
+ group
184
+ });
185
+ }
186
+ /**
187
+ * Creates a new inline group in the console, but prints it as collapsed, requiring the use of a disclosure button to expand it.
188
+ *
189
+ * @param [label] Label.
190
+ */
191
+ groupCollapsed(label) {
192
+ this._groupID++;
193
+ const group = {
194
+ id: this._groupID,
195
+ label: label || 'default',
196
+ collapsed: true,
197
+ parent: this._groups[this._groups.length - 1] || null
198
+ };
199
+ this._groups.push(group);
200
+ this._printer.print({
201
+ type: VirtualConsoleLogTypeEnum_js_1.default.groupCollapsed,
202
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
203
+ message: [label || 'default'],
204
+ group
205
+ });
206
+ }
207
+ /**
208
+ * Exits the current inline group in the console.
209
+ */
210
+ groupEnd() {
211
+ if (this._groups.length === 0) {
212
+ return;
213
+ }
214
+ this._groups.pop();
215
+ }
216
+ /**
217
+ *
218
+ * @param args
219
+ */
220
+ info(...args) {
221
+ this._printer.print({
222
+ type: VirtualConsoleLogTypeEnum_js_1.default.info,
223
+ level: VirtualConsoleLogLevelEnum_js_1.default.info,
224
+ message: args,
225
+ group: this._groups[this._groups.length - 1] || null
226
+ });
227
+ }
228
+ /**
229
+ * Outputs a message to the console.
230
+ *
231
+ * @param args Arguments.
232
+ */
233
+ log(...args) {
234
+ this._printer.print({
235
+ type: VirtualConsoleLogTypeEnum_js_1.default.log,
236
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
237
+ message: args,
238
+ group: this._groups[this._groups.length - 1] || null
239
+ });
240
+ }
241
+ /**
242
+ * Starts recording a performance profile.
243
+ *
244
+ * TODO: Implement this.
245
+ */
246
+ profile() {
247
+ throw new Error('Method not implemented.');
248
+ }
249
+ /**
250
+ * Stops recording a performance profile.
251
+ *
252
+ * TODO: Implement this.
253
+ */
254
+ profileEnd() {
255
+ throw new Error('Method not implemented.');
256
+ }
257
+ /**
258
+ * Displays tabular data as a table.
259
+ *
260
+ * @param data Data.
261
+ */
262
+ table(data) {
263
+ this._printer.print({
264
+ type: VirtualConsoleLogTypeEnum_js_1.default.table,
265
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
266
+ message: [data],
267
+ group: this._groups[this._groups.length - 1] || null
268
+ });
269
+ }
270
+ /**
271
+ * Starts a timer you can use to track how long an operation takes.
272
+ *
273
+ * @param [label=default] Label.
274
+ */
275
+ time(label = 'default') {
276
+ this._time[label] = PerfHooks.performance.now();
277
+ }
278
+ /**
279
+ * Stops a timer that was previously started by calling console.time().
280
+ * The method logs the elapsed time in milliseconds.
281
+ *
282
+ * @param [label=default] Label.
283
+ */
284
+ timeEnd(label = 'default') {
285
+ const time = this._time[label];
286
+ if (time) {
287
+ const duration = PerfHooks.performance.now() - time;
288
+ this._printer.print({
289
+ type: VirtualConsoleLogTypeEnum_js_1.default.timeEnd,
290
+ level: VirtualConsoleLogLevelEnum_js_1.default.info,
291
+ message: [`${label}: ${duration}ms - timer ended`],
292
+ group: this._groups[this._groups.length - 1] || null
293
+ });
294
+ }
295
+ }
296
+ /**
297
+ * Logs the current value of a timer that was previously started by calling console.time().
298
+ * The method logs the elapsed time in milliseconds.
299
+ *
300
+ * @param [label=default] Label.
301
+ * @param [args] Arguments.
302
+ */
303
+ timeLog(label = 'default', ...args) {
304
+ const time = this._time[label];
305
+ if (time) {
306
+ const duration = PerfHooks.performance.now() - time;
307
+ this._printer.print({
308
+ type: VirtualConsoleLogTypeEnum_js_1.default.timeLog,
309
+ level: VirtualConsoleLogLevelEnum_js_1.default.info,
310
+ message: [`${label}: ${duration}ms`, ...args],
311
+ group: this._groups[this._groups.length - 1] || null
312
+ });
313
+ }
314
+ }
315
+ /**
316
+ * Adds a single marker to the browser's Performance tool.
317
+ *
318
+ * TODO: Implement this.
319
+ */
320
+ timeStamp() {
321
+ throw new Error('Method not implemented.');
322
+ }
323
+ /**
324
+ * Outputs a stack trace to the console.
325
+ *
326
+ * @param args Arguments.
327
+ */
328
+ trace(...args) {
329
+ this._printer.print({
330
+ type: VirtualConsoleLogTypeEnum_js_1.default.trace,
331
+ level: VirtualConsoleLogLevelEnum_js_1.default.log,
332
+ message: [...args, new Error('stack').stack.replace('Error: stack', '')],
333
+ group: this._groups[this._groups.length - 1] || null
334
+ });
335
+ }
336
+ /**
337
+ * Outputs a warning message to the console.
338
+ *
339
+ * @param args Arguments.
340
+ */
341
+ warn(...args) {
342
+ this._printer.print({
343
+ type: VirtualConsoleLogTypeEnum_js_1.default.warn,
344
+ level: VirtualConsoleLogLevelEnum_js_1.default.warn,
345
+ message: args,
346
+ group: this._groups[this._groups.length - 1] || null
347
+ });
348
+ }
349
+ }
350
+ exports.default = VirtualConsole;
351
+ //# sourceMappingURL=VirtualConsole.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsole.cjs","sourceRoot":"","sources":["../../src/console/VirtualConsole.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0GAA+E;AAC/E,wGAA6E;AAE7E,sDAAwC;AAExC;;;;GAIG;AACH,MAAqB,cAAc;IAWlC;;;;OAIG;IACH,YAAY,OAA+B;QAVnC,WAAM,GAAgC,EAAE,CAAC;QACzC,UAA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,CAAC,IAAI;YACpC,KAAK,EAAE,uCAA0B,CAAC,IAAI;YACtC,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI;SACpD,CAAC,CAAC;IACJ,CAAC;CACD;AAxVD,iCAwVC"}
@@ -0,0 +1,163 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import IVirtualConsolePrinter from './types/IVirtualConsolePrinter.cjs';
3
+ /**
4
+ * Virtual Console.
5
+ *
6
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Console
7
+ */
8
+ export default class VirtualConsole implements Console {
9
+ Console: NodeJS.ConsoleConstructor;
10
+ private _printer;
11
+ private _count;
12
+ private _time;
13
+ private _groupID;
14
+ private _groups;
15
+ /**
16
+ * Constructor.
17
+ *
18
+ * @param printer Console printer.
19
+ */
20
+ constructor(printer: IVirtualConsolePrinter);
21
+ /**
22
+ * Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
23
+ *
24
+ * @param assertion Assertion.
25
+ * @param args Arguments.
26
+ */
27
+ assert(assertion: boolean, ...args: Array<object | string>): void;
28
+ /**
29
+ * Clears the console.
30
+ */
31
+ clear(): void;
32
+ /**
33
+ * Logs the number of times that this particular call to count() has been called.
34
+ *
35
+ * @param [label='default'] Label.
36
+ */
37
+ count(label?: string): void;
38
+ /**
39
+ * Resets the counter.
40
+ *
41
+ * @param [label='default'] Label.
42
+ */
43
+ countReset(label?: string): void;
44
+ /**
45
+ * Outputs a message to the web console at the "debug" log level.
46
+ *
47
+ * @param args Arguments.
48
+ */
49
+ debug(...args: Array<object | string>): void;
50
+ /**
51
+ * Displays an interactive list of the properties of the specified JavaScript object.
52
+ *
53
+ * @param data Data.
54
+ */
55
+ dir(data: object): void;
56
+ /**
57
+ * Displays an interactive tree of the descendant elements of the specified XML/HTML element.
58
+ *
59
+ * @param data Data.
60
+ */
61
+ dirxml(data: object): void;
62
+ /**
63
+ * Outputs an error message to the console.
64
+ *
65
+ * @param args Arguments.
66
+ */
67
+ error(...args: Array<object | string>): void;
68
+ /**
69
+ * Alias for error().
70
+ *
71
+ * @deprecated
72
+ * @alias error()
73
+ * @param args Arguments.
74
+ */
75
+ exception(...args: Array<object | string>): void;
76
+ /**
77
+ * Creates a new inline group in the console, causing any subsequent console messages to be indented by an additional level, until console.groupEnd() is called.
78
+ *
79
+ * @param [label] Label.
80
+ */
81
+ group(label?: string): void;
82
+ /**
83
+ * Creates a new inline group in the console, but prints it as collapsed, requiring the use of a disclosure button to expand it.
84
+ *
85
+ * @param [label] Label.
86
+ */
87
+ groupCollapsed(label?: string): void;
88
+ /**
89
+ * Exits the current inline group in the console.
90
+ */
91
+ groupEnd(): void;
92
+ /**
93
+ *
94
+ * @param args
95
+ */
96
+ info(...args: Array<object | string>): void;
97
+ /**
98
+ * Outputs a message to the console.
99
+ *
100
+ * @param args Arguments.
101
+ */
102
+ log(...args: Array<object | string>): void;
103
+ /**
104
+ * Starts recording a performance profile.
105
+ *
106
+ * TODO: Implement this.
107
+ */
108
+ profile(): void;
109
+ /**
110
+ * Stops recording a performance profile.
111
+ *
112
+ * TODO: Implement this.
113
+ */
114
+ profileEnd(): void;
115
+ /**
116
+ * Displays tabular data as a table.
117
+ *
118
+ * @param data Data.
119
+ */
120
+ table(data: {
121
+ [key: string]: number | string | boolean;
122
+ } | string[]): void;
123
+ /**
124
+ * Starts a timer you can use to track how long an operation takes.
125
+ *
126
+ * @param [label=default] Label.
127
+ */
128
+ time(label?: string): void;
129
+ /**
130
+ * Stops a timer that was previously started by calling console.time().
131
+ * The method logs the elapsed time in milliseconds.
132
+ *
133
+ * @param [label=default] Label.
134
+ */
135
+ timeEnd(label?: string): void;
136
+ /**
137
+ * Logs the current value of a timer that was previously started by calling console.time().
138
+ * The method logs the elapsed time in milliseconds.
139
+ *
140
+ * @param [label=default] Label.
141
+ * @param [args] Arguments.
142
+ */
143
+ timeLog(label?: string, ...args: Array<object | string>): void;
144
+ /**
145
+ * Adds a single marker to the browser's Performance tool.
146
+ *
147
+ * TODO: Implement this.
148
+ */
149
+ timeStamp(): void;
150
+ /**
151
+ * Outputs a stack trace to the console.
152
+ *
153
+ * @param args Arguments.
154
+ */
155
+ trace(...args: Array<object | string>): void;
156
+ /**
157
+ * Outputs a warning message to the console.
158
+ *
159
+ * @param args Arguments.
160
+ */
161
+ warn(...args: Array<object | string>): void;
162
+ }
163
+ //# sourceMappingURL=VirtualConsole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsole.d.ts","sourceRoot":"","sources":["../../src/console/VirtualConsole.ts"],"names":[],"mappings":";AAAA,OAAO,sBAAsB,MAAM,mCAAmC,CAAC;AAMvE;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,OAAO;IAG9C,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC;IAE1C,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,OAAO,CAAiC;IAEhD;;;;OAIG;gBACS,OAAO,EAAE,sBAAsB;IAI3C;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;IAWxE;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;;OAIG;IACI,KAAK,CAAC,KAAK,SAAY,GAAG,IAAI;IAerC;;;;OAIG;IACI,UAAU,CAAC,KAAK,SAAY,GAAG,IAAI;IAW1C;;;;OAIG;IACI,KAAK,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;IASnD;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAS9B;;;;OAIG;I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D;;;;OAIG;IACI,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;CAQlD"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const VirtualConsoleLogLevelEnum_js_1 = __importDefault(require("./enums/VirtualConsoleLogLevelEnum.cjs"));
7
+ const Event_js_1 = __importDefault(require("../event/Event.cjs"));
8
+ const VirtualConsoleLogEntryStringifier_js_1 = __importDefault(require("./utilities/VirtualConsoleLogEntryStringifier.cjs"));
9
+ /**
10
+ * Virtual console printer.
11
+ */
12
+ class VirtualConsolePrinter {
13
+ constructor() {
14
+ this._logEntries = [];
15
+ this._listeners = { print: [], clear: [] };
16
+ }
17
+ /**
18
+ * Writes to the output.
19
+ *
20
+ * @param logEntry Log entry.
21
+ */
22
+ print(logEntry) {
23
+ this._logEntries.push(logEntry);
24
+ this.dispatchEvent(new Event_js_1.default('print'));
25
+ }
26
+ /**
27
+ * Clears the output.
28
+ */
29
+ clear() {
30
+ this._logEntries = [];
31
+ this.dispatchEvent(new Event_js_1.default('clear'));
32
+ }
33
+ /**
34
+ * Adds an event listener.
35
+ *
36
+ * @param eventType Event type ("print" or "clear").
37
+ * @param listener Listener.
38
+ */
39
+ addEventListener(eventType, listener) {
40
+ if (!this._listeners[eventType]) {
41
+ throw new Error(`Event type "${eventType}" is not supported.`);
42
+ }
43
+ this._listeners[eventType].push(listener);
44
+ }
45
+ /**
46
+ * Removes an event listener.
47
+ *
48
+ * @param eventType Event type ("print" or "clear").
49
+ * @param listener Listener.
50
+ */
51
+ removeEventListener(eventType, listener) {
52
+ if (!this._listeners[eventType]) {
53
+ throw new Error(`Event type "${eventType}" is not supported.`);
54
+ }
55
+ const index = this._listeners[eventType].indexOf(listener);
56
+ if (index !== -1) {
57
+ this._listeners[eventType].splice(index, 1);
58
+ }
59
+ }
60
+ /**
61
+ * Dispatches an event.
62
+ *
63
+ * @param event Event.
64
+ */
65
+ dispatchEvent(event) {
66
+ if (!this._listeners[event.type]) {
67
+ throw new Error(`Event type "${event.type}" is not supported.`);
68
+ }
69
+ for (const listener of this._listeners[event.type]) {
70
+ listener(event);
71
+ }
72
+ }
73
+ /**
74
+ * Reads the buffer.
75
+ *
76
+ * @returns Console log entries.
77
+ */
78
+ read() {
79
+ const logEntries = this._logEntries;
80
+ this._logEntries = [];
81
+ return logEntries;
82
+ }
83
+ /**
84
+ * Returns the buffer as a string.
85
+ *
86
+ * @param [logLevel] Log level.
87
+ * @returns Buffer as a string of concatenated log entries.
88
+ */
89
+ readAsString(logLevel = VirtualConsoleLogLevelEnum_js_1.default.log) {
90
+ const logEntries = this.read();
91
+ let output = '';
92
+ for (const logEntry of logEntries) {
93
+ if (logEntry.level >= logLevel) {
94
+ output += VirtualConsoleLogEntryStringifier_js_1.default.toString(logEntry);
95
+ }
96
+ }
97
+ return output;
98
+ }
99
+ }
100
+ exports.default = VirtualConsolePrinter;
101
+ //# sourceMappingURL=VirtualConsolePrinter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsolePrinter.cjs","sourceRoot":"","sources":["../../src/console/VirtualConsolePrinter.ts"],"names":[],"mappings":";;;;;AACA,0GAA+E;AAC/E,iEAAsC;AACtC,4HAAiG;AAGjG;;GAEG;AACH,MAAqB,qBAAqB;IAA1C;QACS,gBAAW,GAA8B,EAAE,CAAC;QAC5C,eAAU,GAGd,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IA4F9B,CAAC;IA1FA;;;;OAIG;IACI,KAAK,CAAC,QAAiC;QAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,kBAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACx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