@likec4/log 1.18.0 → 1.19.1
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/browser.cjs +1465 -9
- package/dist/browser.mjs +1465 -10
- package/dist/chunks/prompt.cjs +201 -132
- package/dist/chunks/prompt.mjs +199 -130
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +357 -12
- package/dist/index.d.mts +357 -12
- package/dist/index.d.ts +357 -12
- package/dist/index.mjs +1 -1
- package/dist/shared/log.BjyNw23f.mjs +2823 -0
- package/dist/shared/log.DQnPBfHC.cjs +2846 -0
- package/package.json +10 -11
- package/src/browser.ts +16 -0
- package/src/format.ts +60 -0
- package/src/index.ts +36 -0
- package/dist/shared/log.BEan6jB3.cjs +0 -1366
- package/dist/shared/log.BMY8Anc1.mjs +0 -1343
|
@@ -0,0 +1,2846 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_util = require('node:util');
|
|
4
|
+
const node_path = require('node:path');
|
|
5
|
+
const process$1 = require('node:process');
|
|
6
|
+
const tty = require('node:tty');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceCompat(e) {
|
|
11
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
12
|
+
const n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
for (const k in e) {
|
|
15
|
+
n[k] = e[k];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const process$1__default = /*#__PURE__*/_interopDefaultCompat(process$1);
|
|
23
|
+
const tty__namespace = /*#__PURE__*/_interopNamespaceCompat(tty);
|
|
24
|
+
|
|
25
|
+
const LogLevels = {
|
|
26
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
27
|
+
fatal: 0,
|
|
28
|
+
error: 0,
|
|
29
|
+
warn: 1,
|
|
30
|
+
log: 2,
|
|
31
|
+
info: 3,
|
|
32
|
+
success: 3,
|
|
33
|
+
fail: 3,
|
|
34
|
+
ready: 3,
|
|
35
|
+
start: 3,
|
|
36
|
+
box: 3,
|
|
37
|
+
debug: 4,
|
|
38
|
+
trace: 5,
|
|
39
|
+
verbose: Number.POSITIVE_INFINITY
|
|
40
|
+
};
|
|
41
|
+
const LogTypes = {
|
|
42
|
+
// Silent
|
|
43
|
+
silent: {
|
|
44
|
+
level: -1
|
|
45
|
+
},
|
|
46
|
+
// Level 0
|
|
47
|
+
fatal: {
|
|
48
|
+
level: LogLevels.fatal
|
|
49
|
+
},
|
|
50
|
+
error: {
|
|
51
|
+
level: LogLevels.error
|
|
52
|
+
},
|
|
53
|
+
// Level 1
|
|
54
|
+
warn: {
|
|
55
|
+
level: LogLevels.warn
|
|
56
|
+
},
|
|
57
|
+
// Level 2
|
|
58
|
+
log: {
|
|
59
|
+
level: LogLevels.log
|
|
60
|
+
},
|
|
61
|
+
// Level 3
|
|
62
|
+
info: {
|
|
63
|
+
level: LogLevels.info
|
|
64
|
+
},
|
|
65
|
+
success: {
|
|
66
|
+
level: LogLevels.success
|
|
67
|
+
},
|
|
68
|
+
fail: {
|
|
69
|
+
level: LogLevels.fail
|
|
70
|
+
},
|
|
71
|
+
ready: {
|
|
72
|
+
level: LogLevels.info
|
|
73
|
+
},
|
|
74
|
+
start: {
|
|
75
|
+
level: LogLevels.info
|
|
76
|
+
},
|
|
77
|
+
box: {
|
|
78
|
+
level: LogLevels.info
|
|
79
|
+
},
|
|
80
|
+
// Level 4
|
|
81
|
+
debug: {
|
|
82
|
+
level: LogLevels.debug
|
|
83
|
+
},
|
|
84
|
+
// Level 5
|
|
85
|
+
trace: {
|
|
86
|
+
level: LogLevels.trace
|
|
87
|
+
},
|
|
88
|
+
// Verbose
|
|
89
|
+
verbose: {
|
|
90
|
+
level: LogLevels.verbose
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function isPlainObject$1(value) {
|
|
95
|
+
if (value === null || typeof value !== "object") {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const prototype = Object.getPrototypeOf(value);
|
|
99
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (Symbol.iterator in value) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (Symbol.toStringTag in value) {
|
|
106
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
112
|
+
if (!isPlainObject$1(defaults)) {
|
|
113
|
+
return _defu(baseObject, {}, namespace);
|
|
114
|
+
}
|
|
115
|
+
const object = Object.assign({}, defaults);
|
|
116
|
+
for (const key in baseObject) {
|
|
117
|
+
if (key === "__proto__" || key === "constructor") {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const value = baseObject[key];
|
|
121
|
+
if (value === null || value === void 0) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
125
|
+
object[key] = [...value, ...object[key]];
|
|
126
|
+
} else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
|
|
127
|
+
object[key] = _defu(
|
|
128
|
+
value,
|
|
129
|
+
object[key],
|
|
130
|
+
(namespace ? `${namespace}.` : "") + key.toString());
|
|
131
|
+
} else {
|
|
132
|
+
object[key] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return object;
|
|
136
|
+
}
|
|
137
|
+
function createDefu(merger) {
|
|
138
|
+
return (...arguments_) => (
|
|
139
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
140
|
+
arguments_.reduce((p, c) => _defu(p, c, ""), {})
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
const defu = createDefu();
|
|
144
|
+
|
|
145
|
+
function isPlainObject$2(obj) {
|
|
146
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
147
|
+
}
|
|
148
|
+
function isLogObj(arg) {
|
|
149
|
+
if (!isPlainObject$2(arg)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (!arg.message && !arg.args) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (arg.stack) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let paused = false;
|
|
162
|
+
const queue = [];
|
|
163
|
+
class Consola {
|
|
164
|
+
options;
|
|
165
|
+
_lastLog;
|
|
166
|
+
_mockFn;
|
|
167
|
+
/**
|
|
168
|
+
* Creates an instance of Consola with specified options or defaults.
|
|
169
|
+
*
|
|
170
|
+
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
|
171
|
+
*/
|
|
172
|
+
constructor(options = {}) {
|
|
173
|
+
const types = options.types || LogTypes;
|
|
174
|
+
this.options = defu(
|
|
175
|
+
{
|
|
176
|
+
...options,
|
|
177
|
+
defaults: { ...options.defaults },
|
|
178
|
+
level: _normalizeLogLevel(options.level, types),
|
|
179
|
+
reporters: [...options.reporters || []]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
types: LogTypes,
|
|
183
|
+
throttle: 1e3,
|
|
184
|
+
throttleMin: 5,
|
|
185
|
+
formatOptions: {
|
|
186
|
+
date: true,
|
|
187
|
+
colors: false,
|
|
188
|
+
compact: true
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
for (const type in types) {
|
|
193
|
+
const defaults = {
|
|
194
|
+
type,
|
|
195
|
+
...this.options.defaults,
|
|
196
|
+
...types[type]
|
|
197
|
+
};
|
|
198
|
+
this[type] = this._wrapLogFn(defaults);
|
|
199
|
+
this[type].raw = this._wrapLogFn(
|
|
200
|
+
defaults,
|
|
201
|
+
true
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (this.options.mockFn) {
|
|
205
|
+
this.mockTypes();
|
|
206
|
+
}
|
|
207
|
+
this._lastLog = {};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Gets the current log level of the Consola instance.
|
|
211
|
+
*
|
|
212
|
+
* @returns {number} The current log level.
|
|
213
|
+
*/
|
|
214
|
+
get level() {
|
|
215
|
+
return this.options.level;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Sets the minimum log level that will be output by the instance.
|
|
219
|
+
*
|
|
220
|
+
* @param {number} level - The new log level to set.
|
|
221
|
+
*/
|
|
222
|
+
set level(level) {
|
|
223
|
+
this.options.level = _normalizeLogLevel(
|
|
224
|
+
level,
|
|
225
|
+
this.options.types,
|
|
226
|
+
this.options.level
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Displays a prompt to the user and returns the response.
|
|
231
|
+
* Throw an error if `prompt` is not supported by the current configuration.
|
|
232
|
+
*
|
|
233
|
+
* @template T
|
|
234
|
+
* @param {string} message - The message to display in the prompt.
|
|
235
|
+
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
|
236
|
+
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
|
237
|
+
*/
|
|
238
|
+
prompt(message, opts) {
|
|
239
|
+
if (!this.options.prompt) {
|
|
240
|
+
throw new Error("prompt is not supported!");
|
|
241
|
+
}
|
|
242
|
+
return this.options.prompt(message, opts);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
|
246
|
+
*
|
|
247
|
+
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
|
248
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
249
|
+
*/
|
|
250
|
+
create(options) {
|
|
251
|
+
const instance = new Consola({
|
|
252
|
+
...this.options,
|
|
253
|
+
...options
|
|
254
|
+
});
|
|
255
|
+
if (this._mockFn) {
|
|
256
|
+
instance.mockTypes(this._mockFn);
|
|
257
|
+
}
|
|
258
|
+
return instance;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Creates a new Consola instance with the specified default log object properties.
|
|
262
|
+
*
|
|
263
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
264
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
265
|
+
*/
|
|
266
|
+
withDefaults(defaults) {
|
|
267
|
+
return this.create({
|
|
268
|
+
...this.options,
|
|
269
|
+
defaults: {
|
|
270
|
+
...this.options.defaults,
|
|
271
|
+
...defaults
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
|
277
|
+
*
|
|
278
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
279
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
280
|
+
*/
|
|
281
|
+
withTag(tag) {
|
|
282
|
+
return this.withDefaults({
|
|
283
|
+
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Adds a custom reporter to the Consola instance.
|
|
288
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
289
|
+
*
|
|
290
|
+
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
|
291
|
+
* @returns {Consola} The current Consola instance.
|
|
292
|
+
*/
|
|
293
|
+
addReporter(reporter) {
|
|
294
|
+
this.options.reporters.push(reporter);
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Removes a custom reporter from the Consola instance.
|
|
299
|
+
* If no reporter is specified, all reporters will be removed.
|
|
300
|
+
*
|
|
301
|
+
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
|
302
|
+
* @returns {Consola} The current Consola instance.
|
|
303
|
+
*/
|
|
304
|
+
removeReporter(reporter) {
|
|
305
|
+
if (reporter) {
|
|
306
|
+
const i = this.options.reporters.indexOf(reporter);
|
|
307
|
+
if (i !== -1) {
|
|
308
|
+
return this.options.reporters.splice(i, 1);
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
this.options.reporters.splice(0);
|
|
312
|
+
}
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
|
317
|
+
*
|
|
318
|
+
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
|
319
|
+
* @returns {Consola} The current Consola instance.
|
|
320
|
+
*/
|
|
321
|
+
setReporters(reporters) {
|
|
322
|
+
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
wrapAll() {
|
|
326
|
+
this.wrapConsole();
|
|
327
|
+
this.wrapStd();
|
|
328
|
+
}
|
|
329
|
+
restoreAll() {
|
|
330
|
+
this.restoreConsole();
|
|
331
|
+
this.restoreStd();
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Overrides console methods with Consola logging methods for consistent logging.
|
|
335
|
+
*/
|
|
336
|
+
wrapConsole() {
|
|
337
|
+
for (const type in this.options.types) {
|
|
338
|
+
if (!console["__" + type]) {
|
|
339
|
+
console["__" + type] = console[type];
|
|
340
|
+
}
|
|
341
|
+
console[type] = this[type].raw;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Restores the original console methods, removing Consola overrides.
|
|
346
|
+
*/
|
|
347
|
+
restoreConsole() {
|
|
348
|
+
for (const type in this.options.types) {
|
|
349
|
+
if (console["__" + type]) {
|
|
350
|
+
console[type] = console["__" + type];
|
|
351
|
+
delete console["__" + type];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Overrides standard output and error streams to redirect them through Consola.
|
|
357
|
+
*/
|
|
358
|
+
wrapStd() {
|
|
359
|
+
this._wrapStream(this.options.stdout, "log");
|
|
360
|
+
this._wrapStream(this.options.stderr, "log");
|
|
361
|
+
}
|
|
362
|
+
_wrapStream(stream, type) {
|
|
363
|
+
if (!stream) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (!stream.__write) {
|
|
367
|
+
stream.__write = stream.write;
|
|
368
|
+
}
|
|
369
|
+
stream.write = (data) => {
|
|
370
|
+
this[type].raw(String(data).trim());
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Restores the original standard output and error streams, removing the Consola redirection.
|
|
375
|
+
*/
|
|
376
|
+
restoreStd() {
|
|
377
|
+
this._restoreStream(this.options.stdout);
|
|
378
|
+
this._restoreStream(this.options.stderr);
|
|
379
|
+
}
|
|
380
|
+
_restoreStream(stream) {
|
|
381
|
+
if (!stream) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (stream.__write) {
|
|
385
|
+
stream.write = stream.__write;
|
|
386
|
+
delete stream.__write;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
391
|
+
*/
|
|
392
|
+
pauseLogs() {
|
|
393
|
+
paused = true;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Resumes logging, processing any queued logs.
|
|
397
|
+
*/
|
|
398
|
+
resumeLogs() {
|
|
399
|
+
paused = false;
|
|
400
|
+
const _queue = queue.splice(0);
|
|
401
|
+
for (const item of _queue) {
|
|
402
|
+
item[0]._logFn(item[1], item[2]);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
407
|
+
*
|
|
408
|
+
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
|
409
|
+
*/
|
|
410
|
+
mockTypes(mockFn) {
|
|
411
|
+
const _mockFn = mockFn || this.options.mockFn;
|
|
412
|
+
this._mockFn = _mockFn;
|
|
413
|
+
if (typeof _mockFn !== "function") {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
for (const type in this.options.types) {
|
|
417
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
418
|
+
this[type].raw = this[type];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
_wrapLogFn(defaults, isRaw) {
|
|
422
|
+
return (...args) => {
|
|
423
|
+
if (paused) {
|
|
424
|
+
queue.push([this, defaults, args, isRaw]);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
return this._logFn(defaults, args, isRaw);
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
_logFn(defaults, args, isRaw) {
|
|
431
|
+
if ((defaults.level || 0) > this.level) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
const logObj = {
|
|
435
|
+
date: /* @__PURE__ */ new Date(),
|
|
436
|
+
args: [],
|
|
437
|
+
...defaults,
|
|
438
|
+
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
439
|
+
};
|
|
440
|
+
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
441
|
+
Object.assign(logObj, args[0]);
|
|
442
|
+
} else {
|
|
443
|
+
logObj.args = [...args];
|
|
444
|
+
}
|
|
445
|
+
if (logObj.message) {
|
|
446
|
+
logObj.args.unshift(logObj.message);
|
|
447
|
+
delete logObj.message;
|
|
448
|
+
}
|
|
449
|
+
if (logObj.additional) {
|
|
450
|
+
if (!Array.isArray(logObj.additional)) {
|
|
451
|
+
logObj.additional = logObj.additional.split("\n");
|
|
452
|
+
}
|
|
453
|
+
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
454
|
+
delete logObj.additional;
|
|
455
|
+
}
|
|
456
|
+
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
457
|
+
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
458
|
+
const resolveLog = (newLog = false) => {
|
|
459
|
+
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
460
|
+
if (this._lastLog.object && repeated > 0) {
|
|
461
|
+
const args2 = [...this._lastLog.object.args];
|
|
462
|
+
if (repeated > 1) {
|
|
463
|
+
args2.push(`(repeated ${repeated} times)`);
|
|
464
|
+
}
|
|
465
|
+
this._log({ ...this._lastLog.object, args: args2 });
|
|
466
|
+
this._lastLog.count = 1;
|
|
467
|
+
}
|
|
468
|
+
if (newLog) {
|
|
469
|
+
this._lastLog.object = logObj;
|
|
470
|
+
this._log(logObj);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
clearTimeout(this._lastLog.timeout);
|
|
474
|
+
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
475
|
+
this._lastLog.time = logObj.date;
|
|
476
|
+
if (diffTime < this.options.throttle) {
|
|
477
|
+
try {
|
|
478
|
+
const serializedLog = JSON.stringify([
|
|
479
|
+
logObj.type,
|
|
480
|
+
logObj.tag,
|
|
481
|
+
logObj.args
|
|
482
|
+
]);
|
|
483
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
484
|
+
this._lastLog.serialized = serializedLog;
|
|
485
|
+
if (isSameLog) {
|
|
486
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
487
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
488
|
+
this._lastLog.timeout = setTimeout(
|
|
489
|
+
resolveLog,
|
|
490
|
+
this.options.throttle
|
|
491
|
+
);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
resolveLog(true);
|
|
499
|
+
}
|
|
500
|
+
_log(logObj) {
|
|
501
|
+
for (const reporter of this.options.reporters) {
|
|
502
|
+
reporter.log(logObj, {
|
|
503
|
+
options: this.options
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
509
|
+
if (input === void 0) {
|
|
510
|
+
return defaultLevel;
|
|
511
|
+
}
|
|
512
|
+
if (typeof input === "number") {
|
|
513
|
+
return input;
|
|
514
|
+
}
|
|
515
|
+
if (types[input] && types[input].level !== void 0) {
|
|
516
|
+
return types[input].level;
|
|
517
|
+
}
|
|
518
|
+
return defaultLevel;
|
|
519
|
+
}
|
|
520
|
+
Consola.prototype.add = Consola.prototype.addReporter;
|
|
521
|
+
Consola.prototype.remove = Consola.prototype.removeReporter;
|
|
522
|
+
Consola.prototype.clear = Consola.prototype.removeReporter;
|
|
523
|
+
Consola.prototype.withScope = Consola.prototype.withTag;
|
|
524
|
+
Consola.prototype.mock = Consola.prototype.mockTypes;
|
|
525
|
+
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
|
526
|
+
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
|
527
|
+
function createConsola$1(options = {}) {
|
|
528
|
+
return new Consola(options);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function parseStack$1(stack) {
|
|
532
|
+
const cwd = process.cwd() + node_path.sep;
|
|
533
|
+
const lines = stack.split("\n").splice(1).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
|
534
|
+
return lines;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function writeStream(data, stream) {
|
|
538
|
+
const write = stream.__write || stream.write;
|
|
539
|
+
return write.call(stream, data);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const bracket = (x) => x ? `[${x}]` : "";
|
|
543
|
+
class BasicReporter {
|
|
544
|
+
formatStack(stack, opts) {
|
|
545
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
546
|
+
return indent + parseStack$1(stack).join(`
|
|
547
|
+
${indent}`);
|
|
548
|
+
}
|
|
549
|
+
formatError(err, opts) {
|
|
550
|
+
const message = err.message ?? node_util.formatWithOptions(opts, err);
|
|
551
|
+
const stack = err.stack ? this.formatStack(err.stack, opts) : "";
|
|
552
|
+
const level = opts?.errorLevel || 0;
|
|
553
|
+
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
|
554
|
+
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, { ...opts, errorLevel: level + 1 }) : "";
|
|
555
|
+
return causedPrefix + message + "\n" + stack + causedError;
|
|
556
|
+
}
|
|
557
|
+
formatArgs(args, opts) {
|
|
558
|
+
const _args = args.map((arg) => {
|
|
559
|
+
if (arg && typeof arg.stack === "string") {
|
|
560
|
+
return this.formatError(arg, opts);
|
|
561
|
+
}
|
|
562
|
+
return arg;
|
|
563
|
+
});
|
|
564
|
+
return node_util.formatWithOptions(opts, ..._args);
|
|
565
|
+
}
|
|
566
|
+
formatDate(date, opts) {
|
|
567
|
+
return opts.date ? date.toLocaleTimeString() : "";
|
|
568
|
+
}
|
|
569
|
+
filterAndJoin(arr) {
|
|
570
|
+
return arr.filter(Boolean).join(" ");
|
|
571
|
+
}
|
|
572
|
+
formatLogObj(logObj, opts) {
|
|
573
|
+
const message = this.formatArgs(logObj.args, opts);
|
|
574
|
+
if (logObj.type === "box") {
|
|
575
|
+
return "\n" + [
|
|
576
|
+
bracket(logObj.tag),
|
|
577
|
+
logObj.title && logObj.title,
|
|
578
|
+
...message.split("\n")
|
|
579
|
+
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
|
580
|
+
}
|
|
581
|
+
return this.filterAndJoin([
|
|
582
|
+
bracket(logObj.type),
|
|
583
|
+
bracket(logObj.tag),
|
|
584
|
+
message
|
|
585
|
+
]);
|
|
586
|
+
}
|
|
587
|
+
log(logObj, ctx) {
|
|
588
|
+
const line = this.formatLogObj(logObj, {
|
|
589
|
+
columns: ctx.options.stdout.columns || 0,
|
|
590
|
+
...ctx.options.formatOptions
|
|
591
|
+
});
|
|
592
|
+
return writeStream(
|
|
593
|
+
line + "\n",
|
|
594
|
+
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const {
|
|
600
|
+
env = {},
|
|
601
|
+
argv = [],
|
|
602
|
+
platform = ""
|
|
603
|
+
} = typeof process === "undefined" ? {} : process;
|
|
604
|
+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
605
|
+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
606
|
+
const isWindows = platform === "win32";
|
|
607
|
+
const isDumbTerminal = env.TERM === "dumb";
|
|
608
|
+
const isCompatibleTerminal = tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal;
|
|
609
|
+
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
610
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
611
|
+
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
612
|
+
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
613
|
+
}
|
|
614
|
+
function clearBleed(index, string, open, close, replace) {
|
|
615
|
+
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
616
|
+
}
|
|
617
|
+
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
|
618
|
+
return (string) => string || !(string === "" || string === void 0) ? clearBleed(
|
|
619
|
+
("" + string).indexOf(close, at),
|
|
620
|
+
string,
|
|
621
|
+
open,
|
|
622
|
+
close,
|
|
623
|
+
replace
|
|
624
|
+
) : "";
|
|
625
|
+
}
|
|
626
|
+
function init(open, close, replace) {
|
|
627
|
+
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
|
628
|
+
}
|
|
629
|
+
const colorDefs = {
|
|
630
|
+
reset: init(0, 0),
|
|
631
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
632
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
633
|
+
italic: init(3, 23),
|
|
634
|
+
underline: init(4, 24),
|
|
635
|
+
inverse: init(7, 27),
|
|
636
|
+
hidden: init(8, 28),
|
|
637
|
+
strikethrough: init(9, 29),
|
|
638
|
+
black: init(30, 39),
|
|
639
|
+
red: init(31, 39),
|
|
640
|
+
green: init(32, 39),
|
|
641
|
+
yellow: init(33, 39),
|
|
642
|
+
blue: init(34, 39),
|
|
643
|
+
magenta: init(35, 39),
|
|
644
|
+
cyan: init(36, 39),
|
|
645
|
+
white: init(37, 39),
|
|
646
|
+
gray: init(90, 39),
|
|
647
|
+
bgBlack: init(40, 49),
|
|
648
|
+
bgRed: init(41, 49),
|
|
649
|
+
bgGreen: init(42, 49),
|
|
650
|
+
bgYellow: init(43, 49),
|
|
651
|
+
bgBlue: init(44, 49),
|
|
652
|
+
bgMagenta: init(45, 49),
|
|
653
|
+
bgCyan: init(46, 49),
|
|
654
|
+
bgWhite: init(47, 49),
|
|
655
|
+
blackBright: init(90, 39),
|
|
656
|
+
redBright: init(91, 39),
|
|
657
|
+
greenBright: init(92, 39),
|
|
658
|
+
yellowBright: init(93, 39),
|
|
659
|
+
blueBright: init(94, 39),
|
|
660
|
+
magentaBright: init(95, 39),
|
|
661
|
+
cyanBright: init(96, 39),
|
|
662
|
+
whiteBright: init(97, 39),
|
|
663
|
+
bgBlackBright: init(100, 49),
|
|
664
|
+
bgRedBright: init(101, 49),
|
|
665
|
+
bgGreenBright: init(102, 49),
|
|
666
|
+
bgYellowBright: init(103, 49),
|
|
667
|
+
bgBlueBright: init(104, 49),
|
|
668
|
+
bgMagentaBright: init(105, 49),
|
|
669
|
+
bgCyanBright: init(106, 49),
|
|
670
|
+
bgWhiteBright: init(107, 49)
|
|
671
|
+
};
|
|
672
|
+
function createColors(useColor = isColorSupported) {
|
|
673
|
+
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
|
674
|
+
}
|
|
675
|
+
const colors = createColors();
|
|
676
|
+
function getColor$1(color, fallback = "reset") {
|
|
677
|
+
return colors[color] || colors[fallback];
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const ansiRegex$1 = [
|
|
681
|
+
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
|
682
|
+
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
|
683
|
+
].join("|");
|
|
684
|
+
function stripAnsi$1(text) {
|
|
685
|
+
return text.replace(new RegExp(ansiRegex$1, "g"), "");
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const boxStylePresets = {
|
|
689
|
+
solid: {
|
|
690
|
+
tl: "\u250C",
|
|
691
|
+
tr: "\u2510",
|
|
692
|
+
bl: "\u2514",
|
|
693
|
+
br: "\u2518",
|
|
694
|
+
h: "\u2500",
|
|
695
|
+
v: "\u2502"
|
|
696
|
+
},
|
|
697
|
+
double: {
|
|
698
|
+
tl: "\u2554",
|
|
699
|
+
tr: "\u2557",
|
|
700
|
+
bl: "\u255A",
|
|
701
|
+
br: "\u255D",
|
|
702
|
+
h: "\u2550",
|
|
703
|
+
v: "\u2551"
|
|
704
|
+
},
|
|
705
|
+
doubleSingle: {
|
|
706
|
+
tl: "\u2553",
|
|
707
|
+
tr: "\u2556",
|
|
708
|
+
bl: "\u2559",
|
|
709
|
+
br: "\u255C",
|
|
710
|
+
h: "\u2500",
|
|
711
|
+
v: "\u2551"
|
|
712
|
+
},
|
|
713
|
+
doubleSingleRounded: {
|
|
714
|
+
tl: "\u256D",
|
|
715
|
+
tr: "\u256E",
|
|
716
|
+
bl: "\u2570",
|
|
717
|
+
br: "\u256F",
|
|
718
|
+
h: "\u2500",
|
|
719
|
+
v: "\u2551"
|
|
720
|
+
},
|
|
721
|
+
singleThick: {
|
|
722
|
+
tl: "\u250F",
|
|
723
|
+
tr: "\u2513",
|
|
724
|
+
bl: "\u2517",
|
|
725
|
+
br: "\u251B",
|
|
726
|
+
h: "\u2501",
|
|
727
|
+
v: "\u2503"
|
|
728
|
+
},
|
|
729
|
+
singleDouble: {
|
|
730
|
+
tl: "\u2552",
|
|
731
|
+
tr: "\u2555",
|
|
732
|
+
bl: "\u2558",
|
|
733
|
+
br: "\u255B",
|
|
734
|
+
h: "\u2550",
|
|
735
|
+
v: "\u2502"
|
|
736
|
+
},
|
|
737
|
+
singleDoubleRounded: {
|
|
738
|
+
tl: "\u256D",
|
|
739
|
+
tr: "\u256E",
|
|
740
|
+
bl: "\u2570",
|
|
741
|
+
br: "\u256F",
|
|
742
|
+
h: "\u2550",
|
|
743
|
+
v: "\u2502"
|
|
744
|
+
},
|
|
745
|
+
rounded: {
|
|
746
|
+
tl: "\u256D",
|
|
747
|
+
tr: "\u256E",
|
|
748
|
+
bl: "\u2570",
|
|
749
|
+
br: "\u256F",
|
|
750
|
+
h: "\u2500",
|
|
751
|
+
v: "\u2502"
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
const defaultStyle = {
|
|
755
|
+
borderColor: "white",
|
|
756
|
+
borderStyle: "rounded",
|
|
757
|
+
valign: "center",
|
|
758
|
+
padding: 2,
|
|
759
|
+
marginLeft: 1,
|
|
760
|
+
marginTop: 1,
|
|
761
|
+
marginBottom: 1
|
|
762
|
+
};
|
|
763
|
+
function box(text, _opts = {}) {
|
|
764
|
+
const opts = {
|
|
765
|
+
..._opts,
|
|
766
|
+
style: {
|
|
767
|
+
...defaultStyle,
|
|
768
|
+
..._opts.style
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const textLines = text.split("\n");
|
|
772
|
+
const boxLines = [];
|
|
773
|
+
const _color = getColor$1(opts.style.borderColor);
|
|
774
|
+
const borderStyle = {
|
|
775
|
+
...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
|
|
776
|
+
};
|
|
777
|
+
if (_color) {
|
|
778
|
+
for (const key in borderStyle) {
|
|
779
|
+
borderStyle[key] = _color(
|
|
780
|
+
borderStyle[key]
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
|
785
|
+
const height = textLines.length + paddingOffset;
|
|
786
|
+
const width = Math.max(...textLines.map((line) => line.length)) + paddingOffset;
|
|
787
|
+
const widthOffset = width + paddingOffset;
|
|
788
|
+
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
|
789
|
+
if (opts.style.marginTop > 0) {
|
|
790
|
+
boxLines.push("".repeat(opts.style.marginTop));
|
|
791
|
+
}
|
|
792
|
+
if (opts.title) {
|
|
793
|
+
const title = _color ? _color(opts.title) : opts.title;
|
|
794
|
+
const left = borderStyle.h.repeat(
|
|
795
|
+
Math.floor((width - stripAnsi$1(opts.title).length) / 2)
|
|
796
|
+
);
|
|
797
|
+
const right = borderStyle.h.repeat(
|
|
798
|
+
width - stripAnsi$1(opts.title).length - stripAnsi$1(left).length + paddingOffset
|
|
799
|
+
);
|
|
800
|
+
boxLines.push(
|
|
801
|
+
`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`
|
|
802
|
+
);
|
|
803
|
+
} else {
|
|
804
|
+
boxLines.push(
|
|
805
|
+
`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
809
|
+
for (let i = 0; i < height; i++) {
|
|
810
|
+
if (i < valignOffset || i >= valignOffset + textLines.length) {
|
|
811
|
+
boxLines.push(
|
|
812
|
+
`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
|
|
813
|
+
);
|
|
814
|
+
} else {
|
|
815
|
+
const line = textLines[i - valignOffset];
|
|
816
|
+
const left = " ".repeat(paddingOffset);
|
|
817
|
+
const right = " ".repeat(width - stripAnsi$1(line).length);
|
|
818
|
+
boxLines.push(
|
|
819
|
+
`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
boxLines.push(
|
|
824
|
+
`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
|
|
825
|
+
);
|
|
826
|
+
if (opts.style.marginBottom > 0) {
|
|
827
|
+
boxLines.push("".repeat(opts.style.marginBottom));
|
|
828
|
+
}
|
|
829
|
+
return boxLines.join("\n");
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const r=Object.create(null),i=e=>globalThis.process?.env||undefined||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?r:globalThis),s$1=new Proxy(r,{get(e,o){return i()[o]??r[o]},has(e,o){const E=i();return o in E||o in r},set(e,o,E){const b=i(!0);return b[o]=E,!0},deleteProperty(e,o){if(!o)return !1;const E=i(!0);return delete E[o],!0},ownKeys(){const e=i(!0);return Object.keys(e)}}),t=typeof process<"u"&&process.env&&process.env.NODE_ENV||"",B=[["APPVEYOR"],["AWS_AMPLIFY","AWS_APP_ID",{ci:!0}],["AZURE_PIPELINES","SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],["AZURE_STATIC","INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],["APPCIRCLE","AC_APPCIRCLE"],["BAMBOO","bamboo_planKey"],["BITBUCKET","BITBUCKET_COMMIT"],["BITRISE","BITRISE_IO"],["BUDDY","BUDDY_WORKSPACE_ID"],["BUILDKITE"],["CIRCLE","CIRCLECI"],["CIRRUS","CIRRUS_CI"],["CLOUDFLARE_PAGES","CF_PAGES",{ci:!0}],["CODEBUILD","CODEBUILD_BUILD_ARN"],["CODEFRESH","CF_BUILD_ID"],["DRONE"],["DRONE","DRONE_BUILD_EVENT"],["DSARI"],["GITHUB_ACTIONS"],["GITLAB","GITLAB_CI"],["GITLAB","CI_MERGE_REQUEST_ID"],["GOCD","GO_PIPELINE_LABEL"],["LAYERCI"],["HUDSON","HUDSON_URL"],["JENKINS","JENKINS_URL"],["MAGNUM"],["NETLIFY"],["NETLIFY","NETLIFY_LOCAL",{ci:!1}],["NEVERCODE"],["RENDER"],["SAIL","SAILCI"],["SEMAPHORE"],["SCREWDRIVER"],["SHIPPABLE"],["SOLANO","TDDIUM"],["STRIDER"],["TEAMCITY","TEAMCITY_VERSION"],["TRAVIS"],["VERCEL","NOW_BUILDER"],["VERCEL","VERCEL",{ci:!1}],["VERCEL","VERCEL_ENV",{ci:!1}],["APPCENTER","APPCENTER_BUILD_ID"],["CODESANDBOX","CODESANDBOX_SSE",{ci:!1}],["STACKBLITZ"],["STORMKIT"],["CLEAVR"],["ZEABUR"],["CODESPHERE","CODESPHERE_APP_ID",{ci:!0}],["RAILWAY","RAILWAY_PROJECT_ID"],["RAILWAY","RAILWAY_SERVICE_ID"],["DENO-DEPLOY","DENO_DEPLOYMENT_ID"],["FIREBASE_APP_HOSTING","FIREBASE_APP_HOSTING",{ci:!0}]];function p(){if(globalThis.process?.env)for(const e of B){const o=e[1]||e[0];if(globalThis.process?.env[o])return {name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL==="/bin/jsh"&&globalThis.process?.versions?.webcontainer?{name:"stackblitz",ci:!1}:{name:"",ci:!1}}const l=p();l.name;function n(e){return e?e!=="false":!1}const I=globalThis.process?.platform||"",T=n(s$1.CI)||l.ci!==!1,R=n(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),U=n(s$1.DEBUG),A=t==="test"||n(s$1.TEST);n(s$1.MINIMAL)||T||A||!R;const _=/^win/i.test(I);!n(s$1.NO_COLOR)&&(n(s$1.FORCE_COLOR)||(R||_)&&s$1.TERM!=="dumb"||T);const C=(globalThis.process?.versions?.node||"").replace(/^v/,"")||null;Number(C?.split(".")[0])||null;const y=globalThis.process||Object.create(null),c={versions:{}};new Proxy(y,{get(e,o){if(o==="env")return s$1;if(o in e)return e[o];if(o in c)return c[o]}});const L=globalThis.process?.release?.name==="node",a=!!globalThis.Bun||!!globalThis.process?.versions?.bun,D=!!globalThis.Deno,O=!!globalThis.fastly,S=!!globalThis.Netlify,N=!!globalThis.EdgeRuntime,P=globalThis.navigator?.userAgent==="Cloudflare-Workers",F=[[S,"netlify"],[N,"edge-light"],[P,"workerd"],[O,"fastly"],[D,"deno"],[a,"bun"],[L,"node"]];function G(){const e=F.find(o=>o[0]);if(e)return {name:e[1]}}const u=G();u?.name||"";
|
|
833
|
+
|
|
834
|
+
function ansiRegex({onlyFirst = false} = {}) {
|
|
835
|
+
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
836
|
+
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
|
|
837
|
+
const pattern = [
|
|
838
|
+
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
|
|
839
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
840
|
+
].join('|');
|
|
841
|
+
|
|
842
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
const regex = ansiRegex();
|
|
846
|
+
|
|
847
|
+
function stripAnsi(string) {
|
|
848
|
+
if (typeof string !== 'string') {
|
|
849
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// Even though the regex is global, we don't need to reset the `.lastIndex`
|
|
853
|
+
// because unlike `.exec()` and `.test()`, `.replace()` does it automatically
|
|
854
|
+
// and doing it manually has a performance penalty.
|
|
855
|
+
return string.replace(regex, '');
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Generated code.
|
|
859
|
+
|
|
860
|
+
function isAmbiguous(x) {
|
|
861
|
+
return x === 0xA1
|
|
862
|
+
|| x === 0xA4
|
|
863
|
+
|| x === 0xA7
|
|
864
|
+
|| x === 0xA8
|
|
865
|
+
|| x === 0xAA
|
|
866
|
+
|| x === 0xAD
|
|
867
|
+
|| x === 0xAE
|
|
868
|
+
|| x >= 0xB0 && x <= 0xB4
|
|
869
|
+
|| x >= 0xB6 && x <= 0xBA
|
|
870
|
+
|| x >= 0xBC && x <= 0xBF
|
|
871
|
+
|| x === 0xC6
|
|
872
|
+
|| x === 0xD0
|
|
873
|
+
|| x === 0xD7
|
|
874
|
+
|| x === 0xD8
|
|
875
|
+
|| x >= 0xDE && x <= 0xE1
|
|
876
|
+
|| x === 0xE6
|
|
877
|
+
|| x >= 0xE8 && x <= 0xEA
|
|
878
|
+
|| x === 0xEC
|
|
879
|
+
|| x === 0xED
|
|
880
|
+
|| x === 0xF0
|
|
881
|
+
|| x === 0xF2
|
|
882
|
+
|| x === 0xF3
|
|
883
|
+
|| x >= 0xF7 && x <= 0xFA
|
|
884
|
+
|| x === 0xFC
|
|
885
|
+
|| x === 0xFE
|
|
886
|
+
|| x === 0x101
|
|
887
|
+
|| x === 0x111
|
|
888
|
+
|| x === 0x113
|
|
889
|
+
|| x === 0x11B
|
|
890
|
+
|| x === 0x126
|
|
891
|
+
|| x === 0x127
|
|
892
|
+
|| x === 0x12B
|
|
893
|
+
|| x >= 0x131 && x <= 0x133
|
|
894
|
+
|| x === 0x138
|
|
895
|
+
|| x >= 0x13F && x <= 0x142
|
|
896
|
+
|| x === 0x144
|
|
897
|
+
|| x >= 0x148 && x <= 0x14B
|
|
898
|
+
|| x === 0x14D
|
|
899
|
+
|| x === 0x152
|
|
900
|
+
|| x === 0x153
|
|
901
|
+
|| x === 0x166
|
|
902
|
+
|| x === 0x167
|
|
903
|
+
|| x === 0x16B
|
|
904
|
+
|| x === 0x1CE
|
|
905
|
+
|| x === 0x1D0
|
|
906
|
+
|| x === 0x1D2
|
|
907
|
+
|| x === 0x1D4
|
|
908
|
+
|| x === 0x1D6
|
|
909
|
+
|| x === 0x1D8
|
|
910
|
+
|| x === 0x1DA
|
|
911
|
+
|| x === 0x1DC
|
|
912
|
+
|| x === 0x251
|
|
913
|
+
|| x === 0x261
|
|
914
|
+
|| x === 0x2C4
|
|
915
|
+
|| x === 0x2C7
|
|
916
|
+
|| x >= 0x2C9 && x <= 0x2CB
|
|
917
|
+
|| x === 0x2CD
|
|
918
|
+
|| x === 0x2D0
|
|
919
|
+
|| x >= 0x2D8 && x <= 0x2DB
|
|
920
|
+
|| x === 0x2DD
|
|
921
|
+
|| x === 0x2DF
|
|
922
|
+
|| x >= 0x300 && x <= 0x36F
|
|
923
|
+
|| x >= 0x391 && x <= 0x3A1
|
|
924
|
+
|| x >= 0x3A3 && x <= 0x3A9
|
|
925
|
+
|| x >= 0x3B1 && x <= 0x3C1
|
|
926
|
+
|| x >= 0x3C3 && x <= 0x3C9
|
|
927
|
+
|| x === 0x401
|
|
928
|
+
|| x >= 0x410 && x <= 0x44F
|
|
929
|
+
|| x === 0x451
|
|
930
|
+
|| x === 0x2010
|
|
931
|
+
|| x >= 0x2013 && x <= 0x2016
|
|
932
|
+
|| x === 0x2018
|
|
933
|
+
|| x === 0x2019
|
|
934
|
+
|| x === 0x201C
|
|
935
|
+
|| x === 0x201D
|
|
936
|
+
|| x >= 0x2020 && x <= 0x2022
|
|
937
|
+
|| x >= 0x2024 && x <= 0x2027
|
|
938
|
+
|| x === 0x2030
|
|
939
|
+
|| x === 0x2032
|
|
940
|
+
|| x === 0x2033
|
|
941
|
+
|| x === 0x2035
|
|
942
|
+
|| x === 0x203B
|
|
943
|
+
|| x === 0x203E
|
|
944
|
+
|| x === 0x2074
|
|
945
|
+
|| x === 0x207F
|
|
946
|
+
|| x >= 0x2081 && x <= 0x2084
|
|
947
|
+
|| x === 0x20AC
|
|
948
|
+
|| x === 0x2103
|
|
949
|
+
|| x === 0x2105
|
|
950
|
+
|| x === 0x2109
|
|
951
|
+
|| x === 0x2113
|
|
952
|
+
|| x === 0x2116
|
|
953
|
+
|| x === 0x2121
|
|
954
|
+
|| x === 0x2122
|
|
955
|
+
|| x === 0x2126
|
|
956
|
+
|| x === 0x212B
|
|
957
|
+
|| x === 0x2153
|
|
958
|
+
|| x === 0x2154
|
|
959
|
+
|| x >= 0x215B && x <= 0x215E
|
|
960
|
+
|| x >= 0x2160 && x <= 0x216B
|
|
961
|
+
|| x >= 0x2170 && x <= 0x2179
|
|
962
|
+
|| x === 0x2189
|
|
963
|
+
|| x >= 0x2190 && x <= 0x2199
|
|
964
|
+
|| x === 0x21B8
|
|
965
|
+
|| x === 0x21B9
|
|
966
|
+
|| x === 0x21D2
|
|
967
|
+
|| x === 0x21D4
|
|
968
|
+
|| x === 0x21E7
|
|
969
|
+
|| x === 0x2200
|
|
970
|
+
|| x === 0x2202
|
|
971
|
+
|| x === 0x2203
|
|
972
|
+
|| x === 0x2207
|
|
973
|
+
|| x === 0x2208
|
|
974
|
+
|| x === 0x220B
|
|
975
|
+
|| x === 0x220F
|
|
976
|
+
|| x === 0x2211
|
|
977
|
+
|| x === 0x2215
|
|
978
|
+
|| x === 0x221A
|
|
979
|
+
|| x >= 0x221D && x <= 0x2220
|
|
980
|
+
|| x === 0x2223
|
|
981
|
+
|| x === 0x2225
|
|
982
|
+
|| x >= 0x2227 && x <= 0x222C
|
|
983
|
+
|| x === 0x222E
|
|
984
|
+
|| x >= 0x2234 && x <= 0x2237
|
|
985
|
+
|| x === 0x223C
|
|
986
|
+
|| x === 0x223D
|
|
987
|
+
|| x === 0x2248
|
|
988
|
+
|| x === 0x224C
|
|
989
|
+
|| x === 0x2252
|
|
990
|
+
|| x === 0x2260
|
|
991
|
+
|| x === 0x2261
|
|
992
|
+
|| x >= 0x2264 && x <= 0x2267
|
|
993
|
+
|| x === 0x226A
|
|
994
|
+
|| x === 0x226B
|
|
995
|
+
|| x === 0x226E
|
|
996
|
+
|| x === 0x226F
|
|
997
|
+
|| x === 0x2282
|
|
998
|
+
|| x === 0x2283
|
|
999
|
+
|| x === 0x2286
|
|
1000
|
+
|| x === 0x2287
|
|
1001
|
+
|| x === 0x2295
|
|
1002
|
+
|| x === 0x2299
|
|
1003
|
+
|| x === 0x22A5
|
|
1004
|
+
|| x === 0x22BF
|
|
1005
|
+
|| x === 0x2312
|
|
1006
|
+
|| x >= 0x2460 && x <= 0x24E9
|
|
1007
|
+
|| x >= 0x24EB && x <= 0x254B
|
|
1008
|
+
|| x >= 0x2550 && x <= 0x2573
|
|
1009
|
+
|| x >= 0x2580 && x <= 0x258F
|
|
1010
|
+
|| x >= 0x2592 && x <= 0x2595
|
|
1011
|
+
|| x === 0x25A0
|
|
1012
|
+
|| x === 0x25A1
|
|
1013
|
+
|| x >= 0x25A3 && x <= 0x25A9
|
|
1014
|
+
|| x === 0x25B2
|
|
1015
|
+
|| x === 0x25B3
|
|
1016
|
+
|| x === 0x25B6
|
|
1017
|
+
|| x === 0x25B7
|
|
1018
|
+
|| x === 0x25BC
|
|
1019
|
+
|| x === 0x25BD
|
|
1020
|
+
|| x === 0x25C0
|
|
1021
|
+
|| x === 0x25C1
|
|
1022
|
+
|| x >= 0x25C6 && x <= 0x25C8
|
|
1023
|
+
|| x === 0x25CB
|
|
1024
|
+
|| x >= 0x25CE && x <= 0x25D1
|
|
1025
|
+
|| x >= 0x25E2 && x <= 0x25E5
|
|
1026
|
+
|| x === 0x25EF
|
|
1027
|
+
|| x === 0x2605
|
|
1028
|
+
|| x === 0x2606
|
|
1029
|
+
|| x === 0x2609
|
|
1030
|
+
|| x === 0x260E
|
|
1031
|
+
|| x === 0x260F
|
|
1032
|
+
|| x === 0x261C
|
|
1033
|
+
|| x === 0x261E
|
|
1034
|
+
|| x === 0x2640
|
|
1035
|
+
|| x === 0x2642
|
|
1036
|
+
|| x === 0x2660
|
|
1037
|
+
|| x === 0x2661
|
|
1038
|
+
|| x >= 0x2663 && x <= 0x2665
|
|
1039
|
+
|| x >= 0x2667 && x <= 0x266A
|
|
1040
|
+
|| x === 0x266C
|
|
1041
|
+
|| x === 0x266D
|
|
1042
|
+
|| x === 0x266F
|
|
1043
|
+
|| x === 0x269E
|
|
1044
|
+
|| x === 0x269F
|
|
1045
|
+
|| x === 0x26BF
|
|
1046
|
+
|| x >= 0x26C6 && x <= 0x26CD
|
|
1047
|
+
|| x >= 0x26CF && x <= 0x26D3
|
|
1048
|
+
|| x >= 0x26D5 && x <= 0x26E1
|
|
1049
|
+
|| x === 0x26E3
|
|
1050
|
+
|| x === 0x26E8
|
|
1051
|
+
|| x === 0x26E9
|
|
1052
|
+
|| x >= 0x26EB && x <= 0x26F1
|
|
1053
|
+
|| x === 0x26F4
|
|
1054
|
+
|| x >= 0x26F6 && x <= 0x26F9
|
|
1055
|
+
|| x === 0x26FB
|
|
1056
|
+
|| x === 0x26FC
|
|
1057
|
+
|| x === 0x26FE
|
|
1058
|
+
|| x === 0x26FF
|
|
1059
|
+
|| x === 0x273D
|
|
1060
|
+
|| x >= 0x2776 && x <= 0x277F
|
|
1061
|
+
|| x >= 0x2B56 && x <= 0x2B59
|
|
1062
|
+
|| x >= 0x3248 && x <= 0x324F
|
|
1063
|
+
|| x >= 0xE000 && x <= 0xF8FF
|
|
1064
|
+
|| x >= 0xFE00 && x <= 0xFE0F
|
|
1065
|
+
|| x === 0xFFFD
|
|
1066
|
+
|| x >= 0x1F100 && x <= 0x1F10A
|
|
1067
|
+
|| x >= 0x1F110 && x <= 0x1F12D
|
|
1068
|
+
|| x >= 0x1F130 && x <= 0x1F169
|
|
1069
|
+
|| x >= 0x1F170 && x <= 0x1F18D
|
|
1070
|
+
|| x === 0x1F18F
|
|
1071
|
+
|| x === 0x1F190
|
|
1072
|
+
|| x >= 0x1F19B && x <= 0x1F1AC
|
|
1073
|
+
|| x >= 0xE0100 && x <= 0xE01EF
|
|
1074
|
+
|| x >= 0xF0000 && x <= 0xFFFFD
|
|
1075
|
+
|| x >= 0x100000 && x <= 0x10FFFD;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function isFullWidth(x) {
|
|
1079
|
+
return x === 0x3000
|
|
1080
|
+
|| x >= 0xFF01 && x <= 0xFF60
|
|
1081
|
+
|| x >= 0xFFE0 && x <= 0xFFE6;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function isWide(x) {
|
|
1085
|
+
return x >= 0x1100 && x <= 0x115F
|
|
1086
|
+
|| x === 0x231A
|
|
1087
|
+
|| x === 0x231B
|
|
1088
|
+
|| x === 0x2329
|
|
1089
|
+
|| x === 0x232A
|
|
1090
|
+
|| x >= 0x23E9 && x <= 0x23EC
|
|
1091
|
+
|| x === 0x23F0
|
|
1092
|
+
|| x === 0x23F3
|
|
1093
|
+
|| x === 0x25FD
|
|
1094
|
+
|| x === 0x25FE
|
|
1095
|
+
|| x === 0x2614
|
|
1096
|
+
|| x === 0x2615
|
|
1097
|
+
|| x >= 0x2630 && x <= 0x2637
|
|
1098
|
+
|| x >= 0x2648 && x <= 0x2653
|
|
1099
|
+
|| x === 0x267F
|
|
1100
|
+
|| x >= 0x268A && x <= 0x268F
|
|
1101
|
+
|| x === 0x2693
|
|
1102
|
+
|| x === 0x26A1
|
|
1103
|
+
|| x === 0x26AA
|
|
1104
|
+
|| x === 0x26AB
|
|
1105
|
+
|| x === 0x26BD
|
|
1106
|
+
|| x === 0x26BE
|
|
1107
|
+
|| x === 0x26C4
|
|
1108
|
+
|| x === 0x26C5
|
|
1109
|
+
|| x === 0x26CE
|
|
1110
|
+
|| x === 0x26D4
|
|
1111
|
+
|| x === 0x26EA
|
|
1112
|
+
|| x === 0x26F2
|
|
1113
|
+
|| x === 0x26F3
|
|
1114
|
+
|| x === 0x26F5
|
|
1115
|
+
|| x === 0x26FA
|
|
1116
|
+
|| x === 0x26FD
|
|
1117
|
+
|| x === 0x2705
|
|
1118
|
+
|| x === 0x270A
|
|
1119
|
+
|| x === 0x270B
|
|
1120
|
+
|| x === 0x2728
|
|
1121
|
+
|| x === 0x274C
|
|
1122
|
+
|| x === 0x274E
|
|
1123
|
+
|| x >= 0x2753 && x <= 0x2755
|
|
1124
|
+
|| x === 0x2757
|
|
1125
|
+
|| x >= 0x2795 && x <= 0x2797
|
|
1126
|
+
|| x === 0x27B0
|
|
1127
|
+
|| x === 0x27BF
|
|
1128
|
+
|| x === 0x2B1B
|
|
1129
|
+
|| x === 0x2B1C
|
|
1130
|
+
|| x === 0x2B50
|
|
1131
|
+
|| x === 0x2B55
|
|
1132
|
+
|| x >= 0x2E80 && x <= 0x2E99
|
|
1133
|
+
|| x >= 0x2E9B && x <= 0x2EF3
|
|
1134
|
+
|| x >= 0x2F00 && x <= 0x2FD5
|
|
1135
|
+
|| x >= 0x2FF0 && x <= 0x2FFF
|
|
1136
|
+
|| x >= 0x3001 && x <= 0x303E
|
|
1137
|
+
|| x >= 0x3041 && x <= 0x3096
|
|
1138
|
+
|| x >= 0x3099 && x <= 0x30FF
|
|
1139
|
+
|| x >= 0x3105 && x <= 0x312F
|
|
1140
|
+
|| x >= 0x3131 && x <= 0x318E
|
|
1141
|
+
|| x >= 0x3190 && x <= 0x31E5
|
|
1142
|
+
|| x >= 0x31EF && x <= 0x321E
|
|
1143
|
+
|| x >= 0x3220 && x <= 0x3247
|
|
1144
|
+
|| x >= 0x3250 && x <= 0xA48C
|
|
1145
|
+
|| x >= 0xA490 && x <= 0xA4C6
|
|
1146
|
+
|| x >= 0xA960 && x <= 0xA97C
|
|
1147
|
+
|| x >= 0xAC00 && x <= 0xD7A3
|
|
1148
|
+
|| x >= 0xF900 && x <= 0xFAFF
|
|
1149
|
+
|| x >= 0xFE10 && x <= 0xFE19
|
|
1150
|
+
|| x >= 0xFE30 && x <= 0xFE52
|
|
1151
|
+
|| x >= 0xFE54 && x <= 0xFE66
|
|
1152
|
+
|| x >= 0xFE68 && x <= 0xFE6B
|
|
1153
|
+
|| x >= 0x16FE0 && x <= 0x16FE4
|
|
1154
|
+
|| x === 0x16FF0
|
|
1155
|
+
|| x === 0x16FF1
|
|
1156
|
+
|| x >= 0x17000 && x <= 0x187F7
|
|
1157
|
+
|| x >= 0x18800 && x <= 0x18CD5
|
|
1158
|
+
|| x >= 0x18CFF && x <= 0x18D08
|
|
1159
|
+
|| x >= 0x1AFF0 && x <= 0x1AFF3
|
|
1160
|
+
|| x >= 0x1AFF5 && x <= 0x1AFFB
|
|
1161
|
+
|| x === 0x1AFFD
|
|
1162
|
+
|| x === 0x1AFFE
|
|
1163
|
+
|| x >= 0x1B000 && x <= 0x1B122
|
|
1164
|
+
|| x === 0x1B132
|
|
1165
|
+
|| x >= 0x1B150 && x <= 0x1B152
|
|
1166
|
+
|| x === 0x1B155
|
|
1167
|
+
|| x >= 0x1B164 && x <= 0x1B167
|
|
1168
|
+
|| x >= 0x1B170 && x <= 0x1B2FB
|
|
1169
|
+
|| x >= 0x1D300 && x <= 0x1D356
|
|
1170
|
+
|| x >= 0x1D360 && x <= 0x1D376
|
|
1171
|
+
|| x === 0x1F004
|
|
1172
|
+
|| x === 0x1F0CF
|
|
1173
|
+
|| x === 0x1F18E
|
|
1174
|
+
|| x >= 0x1F191 && x <= 0x1F19A
|
|
1175
|
+
|| x >= 0x1F200 && x <= 0x1F202
|
|
1176
|
+
|| x >= 0x1F210 && x <= 0x1F23B
|
|
1177
|
+
|| x >= 0x1F240 && x <= 0x1F248
|
|
1178
|
+
|| x === 0x1F250
|
|
1179
|
+
|| x === 0x1F251
|
|
1180
|
+
|| x >= 0x1F260 && x <= 0x1F265
|
|
1181
|
+
|| x >= 0x1F300 && x <= 0x1F320
|
|
1182
|
+
|| x >= 0x1F32D && x <= 0x1F335
|
|
1183
|
+
|| x >= 0x1F337 && x <= 0x1F37C
|
|
1184
|
+
|| x >= 0x1F37E && x <= 0x1F393
|
|
1185
|
+
|| x >= 0x1F3A0 && x <= 0x1F3CA
|
|
1186
|
+
|| x >= 0x1F3CF && x <= 0x1F3D3
|
|
1187
|
+
|| x >= 0x1F3E0 && x <= 0x1F3F0
|
|
1188
|
+
|| x === 0x1F3F4
|
|
1189
|
+
|| x >= 0x1F3F8 && x <= 0x1F43E
|
|
1190
|
+
|| x === 0x1F440
|
|
1191
|
+
|| x >= 0x1F442 && x <= 0x1F4FC
|
|
1192
|
+
|| x >= 0x1F4FF && x <= 0x1F53D
|
|
1193
|
+
|| x >= 0x1F54B && x <= 0x1F54E
|
|
1194
|
+
|| x >= 0x1F550 && x <= 0x1F567
|
|
1195
|
+
|| x === 0x1F57A
|
|
1196
|
+
|| x === 0x1F595
|
|
1197
|
+
|| x === 0x1F596
|
|
1198
|
+
|| x === 0x1F5A4
|
|
1199
|
+
|| x >= 0x1F5FB && x <= 0x1F64F
|
|
1200
|
+
|| x >= 0x1F680 && x <= 0x1F6C5
|
|
1201
|
+
|| x === 0x1F6CC
|
|
1202
|
+
|| x >= 0x1F6D0 && x <= 0x1F6D2
|
|
1203
|
+
|| x >= 0x1F6D5 && x <= 0x1F6D7
|
|
1204
|
+
|| x >= 0x1F6DC && x <= 0x1F6DF
|
|
1205
|
+
|| x === 0x1F6EB
|
|
1206
|
+
|| x === 0x1F6EC
|
|
1207
|
+
|| x >= 0x1F6F4 && x <= 0x1F6FC
|
|
1208
|
+
|| x >= 0x1F7E0 && x <= 0x1F7EB
|
|
1209
|
+
|| x === 0x1F7F0
|
|
1210
|
+
|| x >= 0x1F90C && x <= 0x1F93A
|
|
1211
|
+
|| x >= 0x1F93C && x <= 0x1F945
|
|
1212
|
+
|| x >= 0x1F947 && x <= 0x1F9FF
|
|
1213
|
+
|| x >= 0x1FA70 && x <= 0x1FA7C
|
|
1214
|
+
|| x >= 0x1FA80 && x <= 0x1FA89
|
|
1215
|
+
|| x >= 0x1FA8F && x <= 0x1FAC6
|
|
1216
|
+
|| x >= 0x1FACE && x <= 0x1FADC
|
|
1217
|
+
|| x >= 0x1FADF && x <= 0x1FAE9
|
|
1218
|
+
|| x >= 0x1FAF0 && x <= 0x1FAF8
|
|
1219
|
+
|| x >= 0x20000 && x <= 0x2FFFD
|
|
1220
|
+
|| x >= 0x30000 && x <= 0x3FFFD;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
function validate(codePoint) {
|
|
1224
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
1225
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
|
|
1230
|
+
validate(codePoint);
|
|
1231
|
+
|
|
1232
|
+
if (
|
|
1233
|
+
isFullWidth(codePoint)
|
|
1234
|
+
|| isWide(codePoint)
|
|
1235
|
+
|| (ambiguousAsWide && isAmbiguous(codePoint))
|
|
1236
|
+
) {
|
|
1237
|
+
return 2;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
return 1;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
const emojiRegex = () => {
|
|
1244
|
+
// https://mths.be/emoji
|
|
1245
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split('') };
|
|
1249
|
+
|
|
1250
|
+
const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
1251
|
+
|
|
1252
|
+
function stringWidth$1(string, options = {}) {
|
|
1253
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
1254
|
+
return 0;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
const {
|
|
1258
|
+
ambiguousIsNarrow = true,
|
|
1259
|
+
countAnsiEscapeCodes = false,
|
|
1260
|
+
} = options;
|
|
1261
|
+
|
|
1262
|
+
if (!countAnsiEscapeCodes) {
|
|
1263
|
+
string = stripAnsi(string);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
if (string.length === 0) {
|
|
1267
|
+
return 0;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
let width = 0;
|
|
1271
|
+
const eastAsianWidthOptions = {ambiguousAsWide: !ambiguousIsNarrow};
|
|
1272
|
+
|
|
1273
|
+
for (const {segment: character} of segmenter.segment(string)) {
|
|
1274
|
+
const codePoint = character.codePointAt(0);
|
|
1275
|
+
|
|
1276
|
+
// Ignore control characters
|
|
1277
|
+
if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// Ignore zero-width characters
|
|
1282
|
+
if (
|
|
1283
|
+
(codePoint >= 0x20_0B && codePoint <= 0x20_0F) // Zero-width space, non-joiner, joiner, left-to-right mark, right-to-left mark
|
|
1284
|
+
|| codePoint === 0xFE_FF // Zero-width no-break space
|
|
1285
|
+
) {
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// Ignore combining characters
|
|
1290
|
+
if (
|
|
1291
|
+
(codePoint >= 0x3_00 && codePoint <= 0x3_6F) // Combining diacritical marks
|
|
1292
|
+
|| (codePoint >= 0x1A_B0 && codePoint <= 0x1A_FF) // Combining diacritical marks extended
|
|
1293
|
+
|| (codePoint >= 0x1D_C0 && codePoint <= 0x1D_FF) // Combining diacritical marks supplement
|
|
1294
|
+
|| (codePoint >= 0x20_D0 && codePoint <= 0x20_FF) // Combining diacritical marks for symbols
|
|
1295
|
+
|| (codePoint >= 0xFE_20 && codePoint <= 0xFE_2F) // Combining half marks
|
|
1296
|
+
) {
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// Ignore surrogate pairs
|
|
1301
|
+
if (codePoint >= 0xD8_00 && codePoint <= 0xDF_FF) {
|
|
1302
|
+
continue;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// Ignore variation selectors
|
|
1306
|
+
if (codePoint >= 0xFE_00 && codePoint <= 0xFE_0F) {
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// This covers some of the above cases, but we still keep them for performance reasons.
|
|
1311
|
+
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// TODO: Use `/\p{RGI_Emoji}/v` when targeting Node.js 20.
|
|
1316
|
+
if (emojiRegex().test(character)) {
|
|
1317
|
+
width += 2;
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
return width;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
function isUnicodeSupported() {
|
|
1328
|
+
const {env} = process$1__default;
|
|
1329
|
+
const {TERM, TERM_PROGRAM} = env;
|
|
1330
|
+
|
|
1331
|
+
if (process$1__default.platform !== 'win32') {
|
|
1332
|
+
return TERM !== 'linux'; // Linux console (kernel)
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
return Boolean(env.WT_SESSION) // Windows Terminal
|
|
1336
|
+
|| Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
1337
|
+
|| env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
1338
|
+
|| TERM_PROGRAM === 'Terminus-Sublime'
|
|
1339
|
+
|| TERM_PROGRAM === 'vscode'
|
|
1340
|
+
|| TERM === 'xterm-256color'
|
|
1341
|
+
|| TERM === 'alacritty'
|
|
1342
|
+
|| TERM === 'rxvt-unicode'
|
|
1343
|
+
|| TERM === 'rxvt-unicode-256color'
|
|
1344
|
+
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
const TYPE_COLOR_MAP = {
|
|
1348
|
+
info: "cyan",
|
|
1349
|
+
fail: "red",
|
|
1350
|
+
success: "green",
|
|
1351
|
+
ready: "green",
|
|
1352
|
+
start: "magenta"
|
|
1353
|
+
};
|
|
1354
|
+
const LEVEL_COLOR_MAP = {
|
|
1355
|
+
0: "red",
|
|
1356
|
+
1: "yellow"
|
|
1357
|
+
};
|
|
1358
|
+
const unicode = isUnicodeSupported();
|
|
1359
|
+
const s = (c, fallback) => unicode ? c : fallback;
|
|
1360
|
+
const TYPE_ICONS = {
|
|
1361
|
+
error: s("\u2716", "\xD7"),
|
|
1362
|
+
fatal: s("\u2716", "\xD7"),
|
|
1363
|
+
ready: s("\u2714", "\u221A"),
|
|
1364
|
+
warn: s("\u26A0", "\u203C"),
|
|
1365
|
+
info: s("\u2139", "i"),
|
|
1366
|
+
success: s("\u2714", "\u221A"),
|
|
1367
|
+
debug: s("\u2699", "D"),
|
|
1368
|
+
trace: s("\u2192", "\u2192"),
|
|
1369
|
+
fail: s("\u2716", "\xD7"),
|
|
1370
|
+
start: s("\u25D0", "o"),
|
|
1371
|
+
log: ""
|
|
1372
|
+
};
|
|
1373
|
+
function stringWidth(str) {
|
|
1374
|
+
const hasICU = typeof Intl === "object";
|
|
1375
|
+
if (!hasICU || !Intl.Segmenter) {
|
|
1376
|
+
return stripAnsi$1(str).length;
|
|
1377
|
+
}
|
|
1378
|
+
return stringWidth$1(str);
|
|
1379
|
+
}
|
|
1380
|
+
class FancyReporter extends BasicReporter {
|
|
1381
|
+
formatStack(stack, opts) {
|
|
1382
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
1383
|
+
return `
|
|
1384
|
+
${indent}` + parseStack$1(stack).map(
|
|
1385
|
+
(line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)
|
|
1386
|
+
).join(`
|
|
1387
|
+
${indent}`);
|
|
1388
|
+
}
|
|
1389
|
+
formatType(logObj, isBadge, opts) {
|
|
1390
|
+
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
1391
|
+
if (isBadge) {
|
|
1392
|
+
return getBgColor(typeColor)(
|
|
1393
|
+
colors.black(` ${logObj.type.toUpperCase()} `)
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
1397
|
+
return _type ? getColor(typeColor)(_type) : "";
|
|
1398
|
+
}
|
|
1399
|
+
formatLogObj(logObj, opts) {
|
|
1400
|
+
const [message, ...additional] = this.formatArgs(logObj.args, opts).split(
|
|
1401
|
+
"\n"
|
|
1402
|
+
);
|
|
1403
|
+
if (logObj.type === "box") {
|
|
1404
|
+
return box(
|
|
1405
|
+
characterFormat(
|
|
1406
|
+
message + (additional.length > 0 ? "\n" + additional.join("\n") : "")
|
|
1407
|
+
),
|
|
1408
|
+
{
|
|
1409
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
1410
|
+
style: logObj.style
|
|
1411
|
+
}
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
const date = this.formatDate(logObj.date, opts);
|
|
1415
|
+
const coloredDate = date && colors.gray(date);
|
|
1416
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
1417
|
+
const type = this.formatType(logObj, isBadge, opts);
|
|
1418
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
1419
|
+
let line;
|
|
1420
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
1421
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
1422
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
1423
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
1424
|
+
line += characterFormat(
|
|
1425
|
+
additional.length > 0 ? "\n" + additional.join("\n") : ""
|
|
1426
|
+
);
|
|
1427
|
+
if (logObj.type === "trace") {
|
|
1428
|
+
const _err = new Error("Trace: " + logObj.message);
|
|
1429
|
+
line += this.formatStack(_err.stack || "");
|
|
1430
|
+
}
|
|
1431
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
function characterFormat(str) {
|
|
1435
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
1436
|
+
}
|
|
1437
|
+
function getColor(color = "white") {
|
|
1438
|
+
return colors[color] || colors.white;
|
|
1439
|
+
}
|
|
1440
|
+
function getBgColor(color = "bgWhite") {
|
|
1441
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function createConsola(options = {}) {
|
|
1445
|
+
let level = _getDefaultLogLevel();
|
|
1446
|
+
if (process.env.CONSOLA_LEVEL) {
|
|
1447
|
+
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
|
1448
|
+
}
|
|
1449
|
+
const consola2 = createConsola$1({
|
|
1450
|
+
level,
|
|
1451
|
+
defaults: { level },
|
|
1452
|
+
stdout: process.stdout,
|
|
1453
|
+
stderr: process.stderr,
|
|
1454
|
+
prompt: (...args) => import('../chunks/prompt.cjs').then((m) => m.prompt(...args)),
|
|
1455
|
+
reporters: options.reporters || [
|
|
1456
|
+
options.fancy ?? !(T || A) ? new FancyReporter() : new BasicReporter()
|
|
1457
|
+
],
|
|
1458
|
+
...options
|
|
1459
|
+
});
|
|
1460
|
+
return consola2;
|
|
1461
|
+
}
|
|
1462
|
+
function _getDefaultLogLevel() {
|
|
1463
|
+
if (U) {
|
|
1464
|
+
return LogLevels.debug;
|
|
1465
|
+
}
|
|
1466
|
+
if (A) {
|
|
1467
|
+
return LogLevels.warn;
|
|
1468
|
+
}
|
|
1469
|
+
return LogLevels.info;
|
|
1470
|
+
}
|
|
1471
|
+
createConsola();
|
|
1472
|
+
|
|
1473
|
+
const normalizeDescriptors=(error)=>{
|
|
1474
|
+
CORE_ERROR_PROPS.forEach((propName)=>{
|
|
1475
|
+
normalizeDescriptor$1(error,propName);
|
|
1476
|
+
});
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
const CORE_ERROR_PROPS=["name","message","stack","cause","errors"];
|
|
1480
|
+
|
|
1481
|
+
const normalizeDescriptor$1=(error,propName)=>{
|
|
1482
|
+
const descriptor=getDescriptor(error,propName);
|
|
1483
|
+
|
|
1484
|
+
if(descriptor===undefined){
|
|
1485
|
+
return
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
if(isReadonlyGetter(descriptor)){
|
|
1489
|
+
setErrorProperty$1(error,propName,error[propName]);
|
|
1490
|
+
return
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
if(isInvalidDescriptor(descriptor)){
|
|
1494
|
+
setErrorDescriptor(error,propName,descriptor);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
const getDescriptor=(value,propName)=>{
|
|
1500
|
+
const descriptor=Object.getOwnPropertyDescriptor(value,propName);
|
|
1501
|
+
|
|
1502
|
+
if(descriptor!==undefined){
|
|
1503
|
+
return descriptor
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
const prototype=Object.getPrototypeOf(value);
|
|
1507
|
+
return prototype===null?undefined:getDescriptor(prototype,propName)
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
const isReadonlyGetter=({get,set})=>
|
|
1512
|
+
get!==undefined&&set===undefined;
|
|
1513
|
+
|
|
1514
|
+
const isInvalidDescriptor=({enumerable,writable})=>
|
|
1515
|
+
enumerable||!writable;
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
const setErrorProperty$1=(error,propName,value)=>{
|
|
1519
|
+
setErrorDescriptor(error,propName,{value});
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
const setErrorDescriptor=(error,propName,descriptor)=>{
|
|
1524
|
+
|
|
1525
|
+
Object.defineProperty(error,propName,{
|
|
1526
|
+
...descriptor,
|
|
1527
|
+
...("get"in descriptor||"set"in descriptor?{}:{writable:true}),
|
|
1528
|
+
enumerable:false,
|
|
1529
|
+
configurable:true
|
|
1530
|
+
});
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
const normalizeAggregate=(error,recurse)=>{
|
|
1534
|
+
if(Array.isArray(error.errors)){
|
|
1535
|
+
const aggregateErrors=error.errors.
|
|
1536
|
+
filter(isDefined).
|
|
1537
|
+
map(recurse).
|
|
1538
|
+
filter(Boolean);
|
|
1539
|
+
setErrorProperty$1(error,"errors",aggregateErrors);
|
|
1540
|
+
}else if(isAggregateError(error)){
|
|
1541
|
+
setErrorProperty$1(error,"errors",[]);
|
|
1542
|
+
}else if(error.errors!==undefined){
|
|
1543
|
+
deleteAggregateErrors(error);
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1547
|
+
const isDefined=(error)=>error!==undefined;
|
|
1548
|
+
|
|
1549
|
+
const isAggregateError=(error)=>
|
|
1550
|
+
"AggregateError"in globalThis&&(
|
|
1551
|
+
error.name==="AggregateError"||error instanceof AggregateError);
|
|
1552
|
+
|
|
1553
|
+
const deleteAggregateErrors=(error)=>{
|
|
1554
|
+
|
|
1555
|
+
delete error.errors;
|
|
1556
|
+
|
|
1557
|
+
if(error.errors!==undefined){
|
|
1558
|
+
setErrorProperty$1(error,"errors",[]);
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
const normalizeCause=(error,recurse)=>{
|
|
1563
|
+
if(!("cause"in error)){
|
|
1564
|
+
return
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
const cause=error.cause===undefined?error.cause:recurse(error.cause);
|
|
1568
|
+
|
|
1569
|
+
if(cause===undefined){
|
|
1570
|
+
|
|
1571
|
+
delete error.cause;
|
|
1572
|
+
}else {
|
|
1573
|
+
setErrorProperty$1(error,"cause",cause);
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
const isErrorInstance$1=(value)=>
|
|
1578
|
+
isInstanceOfError$1(value)||hasErrorTag$1(value);
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
const isInstanceOfError$1=(value)=>{
|
|
1583
|
+
try{
|
|
1584
|
+
return value instanceof Error
|
|
1585
|
+
}catch{
|
|
1586
|
+
return false
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1590
|
+
const hasErrorTag$1=(value)=>{
|
|
1591
|
+
try{
|
|
1592
|
+
return ERROR_TAGS$1.has(Object.prototype.toString.call(value))
|
|
1593
|
+
}catch{
|
|
1594
|
+
return false
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
const ERROR_TAGS$1=new Set([
|
|
1599
|
+
|
|
1600
|
+
"[object Error]",
|
|
1601
|
+
|
|
1602
|
+
"[object DOMException]",
|
|
1603
|
+
|
|
1604
|
+
"[object DOMError]",
|
|
1605
|
+
|
|
1606
|
+
"[object Exception]"]
|
|
1607
|
+
);
|
|
1608
|
+
|
|
1609
|
+
function isPlainObject(value) {
|
|
1610
|
+
if (typeof value !== 'object' || value === null) {
|
|
1611
|
+
return false;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1615
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
const isNonModifiableError=(error)=>
|
|
1619
|
+
!Object.isExtensible(error)||
|
|
1620
|
+
CORE_ERROR_PROPS.some(
|
|
1621
|
+
(propName)=>
|
|
1622
|
+
isNonConfigurableProp(error,propName)||isThrowingProp(error,propName)
|
|
1623
|
+
);
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
const isNonConfigurableProp=(error,propName)=>{
|
|
1628
|
+
const descriptor=Object.getOwnPropertyDescriptor(error,propName);
|
|
1629
|
+
return descriptor!==undefined&&!descriptor.configurable
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
|
|
1633
|
+
const isThrowingProp=(error,propName)=>{
|
|
1634
|
+
try{
|
|
1635
|
+
|
|
1636
|
+
error[propName];
|
|
1637
|
+
return false
|
|
1638
|
+
}catch{
|
|
1639
|
+
return true
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
const setStack=(error)=>{
|
|
1644
|
+
const stack=getStack$3(error.message,error.name);
|
|
1645
|
+
setErrorProperty$1(error,"stack",stack);
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
|
|
1649
|
+
|
|
1650
|
+
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
|
|
1654
|
+
const getStack$3=(message="",name="Error")=>{
|
|
1655
|
+
const StackError=getErrorClass(name);
|
|
1656
|
+
const{stack}=new StackError(message);
|
|
1657
|
+
return typeof stack==="string"&&stack!==""?
|
|
1658
|
+
stack:
|
|
1659
|
+
`${name}: ${message}`
|
|
1660
|
+
};
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
|
|
1666
|
+
const getErrorClass=(name)=>{
|
|
1667
|
+
const descriptor={
|
|
1668
|
+
value:name,
|
|
1669
|
+
enumerable:false,
|
|
1670
|
+
writable:true,
|
|
1671
|
+
configurable:true
|
|
1672
|
+
};
|
|
1673
|
+
|
|
1674
|
+
const StackError=Object.defineProperty(
|
|
1675
|
+
class extends Error{},
|
|
1676
|
+
"name",
|
|
1677
|
+
descriptor
|
|
1678
|
+
);
|
|
1679
|
+
|
|
1680
|
+
Object.defineProperty(StackError.prototype,"name",descriptor);
|
|
1681
|
+
return StackError
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1684
|
+
const copyObject=(object)=>{
|
|
1685
|
+
const objectCopy={};
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
for(const propName of getPropsToCopy(object)){
|
|
1689
|
+
|
|
1690
|
+
try{
|
|
1691
|
+
const value=object[propName];
|
|
1692
|
+
const{
|
|
1693
|
+
enumerable,
|
|
1694
|
+
configurable,
|
|
1695
|
+
writable=true
|
|
1696
|
+
}=getDescriptor(object,propName);
|
|
1697
|
+
|
|
1698
|
+
Object.defineProperty(objectCopy,propName,{
|
|
1699
|
+
value,
|
|
1700
|
+
enumerable,
|
|
1701
|
+
configurable,
|
|
1702
|
+
writable
|
|
1703
|
+
});
|
|
1704
|
+
}catch{}
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
return objectCopy
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
|
|
1711
|
+
|
|
1712
|
+
|
|
1713
|
+
|
|
1714
|
+
const getPropsToCopy=(object)=>{
|
|
1715
|
+
const propNames=getOwnKeys(object);
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
for(const propName of CORE_ERROR_PROPS){
|
|
1719
|
+
|
|
1720
|
+
if(isInheritedProp(object,propName)){
|
|
1721
|
+
|
|
1722
|
+
propNames.push(propName);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
return propNames
|
|
1727
|
+
};
|
|
1728
|
+
|
|
1729
|
+
|
|
1730
|
+
const getOwnKeys=(object)=>{
|
|
1731
|
+
try{
|
|
1732
|
+
return Reflect.ownKeys(object)
|
|
1733
|
+
}catch{
|
|
1734
|
+
return []
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
const isInheritedProp=(object,propName)=>{
|
|
1740
|
+
try{
|
|
1741
|
+
return propName in object&&!Object.hasOwn(object,propName)
|
|
1742
|
+
}catch{
|
|
1743
|
+
return false
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
const objectifyError=(object)=>{
|
|
1748
|
+
const{name,message,stack,cause,errors,...objectA}=copyObject(object);
|
|
1749
|
+
const messageA=getMessage$1(message,objectA);
|
|
1750
|
+
const error=newError(name,messageA);
|
|
1751
|
+
|
|
1752
|
+
if(message===messageA){
|
|
1753
|
+
assignObjectProps(error,objectA);
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
Object.entries({name,stack,cause,errors}).forEach(
|
|
1757
|
+
([propName,propValue])=>{
|
|
1758
|
+
setNewErrorProperty(error,propName,propValue);
|
|
1759
|
+
}
|
|
1760
|
+
);
|
|
1761
|
+
|
|
1762
|
+
if(stack===undefined){
|
|
1763
|
+
setStack(error);
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
return error
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
const getMessage$1=(message,object)=>
|
|
1771
|
+
typeof message==="string"&&message!==""?
|
|
1772
|
+
message:
|
|
1773
|
+
truncateMessage(safeJsonStringify(object));
|
|
1774
|
+
|
|
1775
|
+
const safeJsonStringify=(object)=>{
|
|
1776
|
+
try{
|
|
1777
|
+
return JSON.stringify(object)
|
|
1778
|
+
}catch{
|
|
1779
|
+
return safeStringify$1(object)
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
const safeStringify$1=(object)=>{
|
|
1784
|
+
try{
|
|
1785
|
+
return String(object)
|
|
1786
|
+
}catch{
|
|
1787
|
+
return "Invalid error"
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
const truncateMessage=(message)=>
|
|
1792
|
+
message.length<MESSAGE_MAX_SIZE?
|
|
1793
|
+
message:
|
|
1794
|
+
`${message.slice(0,MESSAGE_MAX_SIZE)}...`;
|
|
1795
|
+
|
|
1796
|
+
const MESSAGE_MAX_SIZE=1e3;
|
|
1797
|
+
|
|
1798
|
+
const newError=(name,message)=>{
|
|
1799
|
+
if(name==="AggregateError"&&"AggregateError"in globalThis){
|
|
1800
|
+
return new AggregateError([],message)
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
if(name in NATIVE_ERRORS){
|
|
1804
|
+
return new NATIVE_ERRORS[name](message)
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
return new Error(message)
|
|
1808
|
+
};
|
|
1809
|
+
|
|
1810
|
+
const NATIVE_ERRORS={
|
|
1811
|
+
Error,
|
|
1812
|
+
ReferenceError,
|
|
1813
|
+
TypeError,
|
|
1814
|
+
SyntaxError,
|
|
1815
|
+
RangeError,
|
|
1816
|
+
URIError,
|
|
1817
|
+
EvalError
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1820
|
+
|
|
1821
|
+
const assignObjectProps=(error,object)=>{
|
|
1822
|
+
|
|
1823
|
+
for(const propName in object){
|
|
1824
|
+
|
|
1825
|
+
if(!(propName in error)){
|
|
1826
|
+
error[propName]=object[propName];
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
|
|
1831
|
+
const setNewErrorProperty=(error,propName,propValue)=>{
|
|
1832
|
+
if(propValue!==undefined){
|
|
1833
|
+
setErrorProperty$1(error,propName,propValue);
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
|
|
1837
|
+
const stringifyError=(value)=>{
|
|
1838
|
+
try{
|
|
1839
|
+
const error=new Error(String(value));
|
|
1840
|
+
setStack(error);
|
|
1841
|
+
return error
|
|
1842
|
+
}catch(error_){
|
|
1843
|
+
return error_
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
const{toString:objectToString}=Object.prototype;
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
const createError=(value)=>{
|
|
1851
|
+
if(isErrorPlainObj(value)){
|
|
1852
|
+
return objectifyError(value)
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
if(!isErrorInstance$1(value)){
|
|
1856
|
+
return stringifyError(value)
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
if(isInvalidError(value)){
|
|
1860
|
+
return objectifyError(value)
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
return value
|
|
1864
|
+
};
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
const isErrorPlainObj=(value)=>{
|
|
1868
|
+
try{
|
|
1869
|
+
return isPlainObject(value)
|
|
1870
|
+
}catch{
|
|
1871
|
+
return false
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
|
|
1875
|
+
const isInvalidError=(value)=>
|
|
1876
|
+
isProxy(value)||isNonModifiableError(value)||hasInvalidConstructor(value);
|
|
1877
|
+
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
const isProxy=(value)=>{
|
|
1882
|
+
try{
|
|
1883
|
+
return objectToString.call(value)==="[object Object]"
|
|
1884
|
+
}catch{
|
|
1885
|
+
return true
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
|
|
1891
|
+
const hasInvalidConstructor=(error)=>
|
|
1892
|
+
typeof error.constructor!=="function"||
|
|
1893
|
+
typeof error.constructor.name!=="string"||
|
|
1894
|
+
error.constructor.name===""||
|
|
1895
|
+
error.constructor.prototype!==Object.getPrototypeOf(error);
|
|
1896
|
+
|
|
1897
|
+
const normalizeException=(error,{shallow=false}={})=>
|
|
1898
|
+
recurseException(error,[],shallow);
|
|
1899
|
+
|
|
1900
|
+
const recurseException=(error,parents,shallow)=>{
|
|
1901
|
+
if(parents.includes(error)){
|
|
1902
|
+
return
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
const recurse=shallow?
|
|
1906
|
+
identity:
|
|
1907
|
+
(innerError)=>recurseException(innerError,[...parents,error],shallow);
|
|
1908
|
+
|
|
1909
|
+
const errorA=createError(error);
|
|
1910
|
+
normalizeProps(errorA,recurse);
|
|
1911
|
+
return errorA
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1914
|
+
const identity=(error)=>error;
|
|
1915
|
+
|
|
1916
|
+
const normalizeProps=(error,recurse)=>{
|
|
1917
|
+
normalizeName(error);
|
|
1918
|
+
normalizeMessage(error);
|
|
1919
|
+
normalizeStack(error);
|
|
1920
|
+
normalizeCause(error,recurse);
|
|
1921
|
+
normalizeAggregate(error,recurse);
|
|
1922
|
+
normalizeDescriptors(error);
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
const normalizeName=(error)=>{
|
|
1931
|
+
if(isDefinedString$1(error.name)){
|
|
1932
|
+
return
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
const prototypeName=Object.getPrototypeOf(error).name;
|
|
1936
|
+
const name=isDefinedString$1(prototypeName)?
|
|
1937
|
+
prototypeName:
|
|
1938
|
+
error.constructor.name;
|
|
1939
|
+
setErrorProperty$1(error,"name",name);
|
|
1940
|
+
};
|
|
1941
|
+
|
|
1942
|
+
|
|
1943
|
+
const normalizeMessage=(error)=>{
|
|
1944
|
+
if(!isDefinedString$1(error.message)){
|
|
1945
|
+
setErrorProperty$1(error,"message","");
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
|
|
1950
|
+
const normalizeStack=(error)=>{
|
|
1951
|
+
if(!isDefinedString$1(error.stack)){
|
|
1952
|
+
setStack(error);
|
|
1953
|
+
}
|
|
1954
|
+
};
|
|
1955
|
+
|
|
1956
|
+
const isDefinedString$1=(value)=>typeof value==="string"&&value!=="";
|
|
1957
|
+
|
|
1958
|
+
const normalizeArgs$1=(error,ErrorClass,currentName=error.name)=>{
|
|
1959
|
+
validateErrorClass(ErrorClass);
|
|
1960
|
+
|
|
1961
|
+
if(typeof currentName!=="string"){
|
|
1962
|
+
throw new TypeError(`currentName must be a string: ${currentName}`)
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
return currentName
|
|
1966
|
+
};
|
|
1967
|
+
|
|
1968
|
+
const validateErrorClass=(ErrorClass)=>{
|
|
1969
|
+
if(!isClass(ErrorClass)){
|
|
1970
|
+
throw new TypeError(`ErrorClass must be a class: ${ErrorClass}`)
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
if(!isErrorClass(ErrorClass.prototype)){
|
|
1974
|
+
throw new TypeError(`ErrorClass must inherit from Error: ${ErrorClass}`)
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
if(!hasConstructor(ErrorClass)){
|
|
1978
|
+
throw new TypeError(
|
|
1979
|
+
`ErrorClass must be have a valid constructor: ${ErrorClass}`
|
|
1980
|
+
)
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1984
|
+
const isClass=(ErrorClass)=>
|
|
1985
|
+
typeof ErrorClass==="function"&&
|
|
1986
|
+
typeof ErrorClass.prototype==="object"&&
|
|
1987
|
+
ErrorClass.prototype!==null;
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
const isErrorClass=(prototype)=>
|
|
1991
|
+
prototype!==null&&(
|
|
1992
|
+
prototype.name==="Error"||isErrorClass(Object.getPrototypeOf(prototype)));
|
|
1993
|
+
|
|
1994
|
+
const hasConstructor=(ErrorClass)=>
|
|
1995
|
+
typeof ErrorClass.prototype.constructor==="function";
|
|
1996
|
+
|
|
1997
|
+
const setNonEnumProp$1=(error,propName,value)=>{
|
|
1998
|
+
|
|
1999
|
+
Object.defineProperty(error,propName,{
|
|
2000
|
+
value,
|
|
2001
|
+
enumerable:false,
|
|
2002
|
+
writable:true,
|
|
2003
|
+
configurable:true
|
|
2004
|
+
});
|
|
2005
|
+
};
|
|
2006
|
+
|
|
2007
|
+
const updatePrototype=(error,ErrorClass)=>{
|
|
2008
|
+
if(Object.getPrototypeOf(error)===ErrorClass.prototype){
|
|
2009
|
+
return
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
setPrototype(error,ErrorClass);
|
|
2013
|
+
deleteOwnProperty(error,"constructor");
|
|
2014
|
+
fixName(error,ErrorClass);
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
const setPrototype=(error,ErrorClass)=>{
|
|
2022
|
+
|
|
2023
|
+
Object.setPrototypeOf(error,ErrorClass.prototype);
|
|
2024
|
+
};
|
|
2025
|
+
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
|
|
2030
|
+
|
|
2031
|
+
|
|
2032
|
+
|
|
2033
|
+
|
|
2034
|
+
|
|
2035
|
+
const fixName=(error,ErrorClass)=>{
|
|
2036
|
+
deleteOwnProperty(error,"name");
|
|
2037
|
+
|
|
2038
|
+
const prototypeName=getClassName(ErrorClass.prototype);
|
|
2039
|
+
|
|
2040
|
+
if(error.name!==prototypeName){
|
|
2041
|
+
setNonEnumProp$1(error,"name",prototypeName);
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
|
|
2045
|
+
const getClassName=(prototype)=>
|
|
2046
|
+
getPrototypeName(prototype)??
|
|
2047
|
+
getConstructorName(prototype)??
|
|
2048
|
+
getClassName(Object.getPrototypeOf(prototype));
|
|
2049
|
+
|
|
2050
|
+
const getPrototypeName=(prototype)=>
|
|
2051
|
+
Object.hasOwn(prototype,"name")&&isDefinedString(prototype.name)?
|
|
2052
|
+
prototype.name:
|
|
2053
|
+
undefined;
|
|
2054
|
+
|
|
2055
|
+
const getConstructorName=(prototype)=>
|
|
2056
|
+
typeof prototype.constructor==="function"&&
|
|
2057
|
+
isDefinedString(prototype.constructor.name)?
|
|
2058
|
+
prototype.constructor.name:
|
|
2059
|
+
undefined;
|
|
2060
|
+
|
|
2061
|
+
const isDefinedString=(value)=>typeof value==="string"&&value!=="";
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
const deleteOwnProperty=(error,propName)=>{
|
|
2066
|
+
if(Object.hasOwn(error,propName)){
|
|
2067
|
+
|
|
2068
|
+
delete error[propName];
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
const updateStack$1=(error,currentName)=>{
|
|
2073
|
+
if(!shouldUpdateStack(error,currentName)){
|
|
2074
|
+
return
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
const stack=getStack$2(error,currentName);
|
|
2078
|
+
setNonEnumProp$1(error,"stack",stack);
|
|
2079
|
+
};
|
|
2080
|
+
|
|
2081
|
+
const shouldUpdateStack=(error,currentName)=>
|
|
2082
|
+
currentName!==error.name&&
|
|
2083
|
+
currentName!==""&&
|
|
2084
|
+
error.stack.includes(currentName)&&
|
|
2085
|
+
stackIncludesName();
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
const stackIncludesName=()=>{
|
|
2089
|
+
|
|
2090
|
+
class StackError extends Error{}
|
|
2091
|
+
const descriptor={
|
|
2092
|
+
value:EXAMPLE_NAME,
|
|
2093
|
+
enumerable:false,
|
|
2094
|
+
writable:true,
|
|
2095
|
+
configurable:true
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2098
|
+
Object.defineProperty(StackError,"name",descriptor);
|
|
2099
|
+
|
|
2100
|
+
Object.defineProperty(StackError.prototype,"name",descriptor);
|
|
2101
|
+
const{stack}=new StackError("");
|
|
2102
|
+
return typeof stack==="string"&&stack.includes(EXAMPLE_NAME)
|
|
2103
|
+
};
|
|
2104
|
+
|
|
2105
|
+
const EXAMPLE_NAME="SetErrorClassError";
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
const getStack$2=({name,stack},currentName)=>{
|
|
2115
|
+
if(stack.startsWith(`${currentName}: `)){
|
|
2116
|
+
return stack.replace(currentName,name)
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
const replacers=getReplacers$1(currentName,name);
|
|
2120
|
+
const[fromA,to]=replacers.find(([from])=>stack.includes(from));
|
|
2121
|
+
return stack.replace(fromA,to)
|
|
2122
|
+
};
|
|
2123
|
+
|
|
2124
|
+
|
|
2125
|
+
|
|
2126
|
+
const getReplacers$1=(currentName,newName)=>[
|
|
2127
|
+
[`\n${currentName}: `,`\n${newName}: `],
|
|
2128
|
+
[`${currentName}: `,`${newName}: `],
|
|
2129
|
+
[`${currentName} `,`${newName} `],
|
|
2130
|
+
[currentName,newName]];
|
|
2131
|
+
|
|
2132
|
+
const setErrorClass=(error,ErrorClass,currentName)=>{
|
|
2133
|
+
const errorA=normalizeException(error);
|
|
2134
|
+
const currentNameA=normalizeArgs$1(errorA,ErrorClass,currentName);
|
|
2135
|
+
updatePrototype(errorA,ErrorClass);
|
|
2136
|
+
updateStack$1(errorA,currentNameA);
|
|
2137
|
+
return errorA
|
|
2138
|
+
};
|
|
2139
|
+
|
|
2140
|
+
const mergeDescriptors=(newDescriptor,currentDescriptor)=>
|
|
2141
|
+
currentDescriptor.configurable===false?
|
|
2142
|
+
mergeNonConfig(newDescriptor,currentDescriptor):
|
|
2143
|
+
mergeConfig(newDescriptor,currentDescriptor);
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
|
|
2147
|
+
|
|
2148
|
+
const mergeNonConfig=(newDescriptor,currentDescriptor)=>({
|
|
2149
|
+
...currentDescriptor,
|
|
2150
|
+
...getNonConfigWritable(newDescriptor,currentDescriptor),
|
|
2151
|
+
...getNonConfigValue(newDescriptor,currentDescriptor)
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
const getNonConfigWritable=(newDescriptor,currentDescriptor)=>
|
|
2155
|
+
currentDescriptor.writable===true&&newDescriptor.writable===false?
|
|
2156
|
+
{writable:false}:
|
|
2157
|
+
{};
|
|
2158
|
+
|
|
2159
|
+
const getNonConfigValue=(newDescriptor,currentDescriptor)=>
|
|
2160
|
+
newDescriptor.hasValue&&
|
|
2161
|
+
"value"in currentDescriptor&&
|
|
2162
|
+
currentDescriptor.writable===true?
|
|
2163
|
+
{value:newDescriptor.value}:
|
|
2164
|
+
{};
|
|
2165
|
+
|
|
2166
|
+
const mergeConfig=(newDescriptor,currentDescriptor)=>{
|
|
2167
|
+
const enumerable=mergeDescriptor(
|
|
2168
|
+
newDescriptor.enumerable,
|
|
2169
|
+
currentDescriptor.enumerable,
|
|
2170
|
+
true
|
|
2171
|
+
);
|
|
2172
|
+
const writable=mergeDescriptor(
|
|
2173
|
+
newDescriptor.writable,
|
|
2174
|
+
currentDescriptor.writable,
|
|
2175
|
+
true
|
|
2176
|
+
);
|
|
2177
|
+
const configurable=mergeDescriptor(
|
|
2178
|
+
newDescriptor.configurable,
|
|
2179
|
+
currentDescriptor.configurable,
|
|
2180
|
+
true
|
|
2181
|
+
);
|
|
2182
|
+
const valueProps=mergeValue(newDescriptor,currentDescriptor,writable);
|
|
2183
|
+
return {...valueProps,enumerable,configurable}
|
|
2184
|
+
};
|
|
2185
|
+
|
|
2186
|
+
const mergeValue=(newDescriptor,currentDescriptor,writable)=>{
|
|
2187
|
+
if(newDescriptor.hasValue){
|
|
2188
|
+
return {value:newDescriptor.value,writable}
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
if(!hasGetSet(newDescriptor)&&!hasGetSet(currentDescriptor)){
|
|
2192
|
+
return {value:currentDescriptor.value,writable}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
return {
|
|
2196
|
+
get:mergeDescriptor(newDescriptor.get,currentDescriptor.get),
|
|
2197
|
+
set:mergeDescriptor(newDescriptor.set,currentDescriptor.set)
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
const hasGetSet=({get,set})=>get!==undefined||set!==undefined;
|
|
2202
|
+
|
|
2203
|
+
const mergeDescriptor=(newValue,currentValue,defaultValue)=>
|
|
2204
|
+
newValue??currentValue??defaultValue;
|
|
2205
|
+
|
|
2206
|
+
const normalizeInput=(input,key,newDescriptor)=>{
|
|
2207
|
+
if(!isAnyObj(input)){
|
|
2208
|
+
throw new TypeError(`Argument must be an object: ${input}`)
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
if(!isValidKey(key)){
|
|
2212
|
+
throw new TypeError(
|
|
2213
|
+
`Property key must be a string, a symbol or an integer: ${key}`
|
|
2214
|
+
)
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
return normalizeDescriptor(newDescriptor)
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
const isAnyObj=(value)=>typeof value==="object"&&value!==null;
|
|
2221
|
+
|
|
2222
|
+
const isValidKey=(key)=>{
|
|
2223
|
+
const type=typeof key;
|
|
2224
|
+
return type==="string"||type==="symbol"||type==="number"
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
const normalizeDescriptor=(newDescriptor)=>{
|
|
2228
|
+
if(!isPlainObject(newDescriptor)){
|
|
2229
|
+
throw new TypeError(`Descriptor must be a plain object: ${newDescriptor}`)
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
const{
|
|
2233
|
+
enumerable,
|
|
2234
|
+
writable,
|
|
2235
|
+
configurable,
|
|
2236
|
+
value,
|
|
2237
|
+
get,
|
|
2238
|
+
set,
|
|
2239
|
+
...unknownProps
|
|
2240
|
+
}=newDescriptor;
|
|
2241
|
+
const hasValue=("value"in newDescriptor);
|
|
2242
|
+
validateDescriptor({
|
|
2243
|
+
enumerable,
|
|
2244
|
+
writable,
|
|
2245
|
+
configurable,
|
|
2246
|
+
get,
|
|
2247
|
+
set,
|
|
2248
|
+
unknownProps,
|
|
2249
|
+
hasValue
|
|
2250
|
+
});
|
|
2251
|
+
return {enumerable,writable,configurable,value,get,set,hasValue}
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
const validateDescriptor=({
|
|
2255
|
+
enumerable,
|
|
2256
|
+
writable,
|
|
2257
|
+
configurable,
|
|
2258
|
+
get,
|
|
2259
|
+
set,
|
|
2260
|
+
unknownProps,
|
|
2261
|
+
hasValue
|
|
2262
|
+
})=>{
|
|
2263
|
+
validateGetSet(hasValue,get,"get");
|
|
2264
|
+
validateGetSet(hasValue,set,"set");
|
|
2265
|
+
validateBoolean(enumerable,"enumerable");
|
|
2266
|
+
validateBoolean(writable,"writable");
|
|
2267
|
+
validateBoolean(configurable,"configurable");
|
|
2268
|
+
validateUnknownProps(unknownProps);
|
|
2269
|
+
};
|
|
2270
|
+
|
|
2271
|
+
const validateGetSet=(hasValue,getSet,propName)=>{
|
|
2272
|
+
validateFunction(getSet,propName);
|
|
2273
|
+
|
|
2274
|
+
if(hasValue&&getSet!==undefined){
|
|
2275
|
+
throw new TypeError(
|
|
2276
|
+
`Descriptor property "value" and "${propName}" must not both be defined: ${getSet}`
|
|
2277
|
+
)
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
|
|
2281
|
+
const validateFunction=(propValue,propName)=>{
|
|
2282
|
+
if(propValue!==undefined&&typeof propValue!=="function"){
|
|
2283
|
+
throw new TypeError(
|
|
2284
|
+
`Descriptor property "${propName}" must be a function: ${propValue}`
|
|
2285
|
+
)
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
|
|
2289
|
+
const validateBoolean=(propValue,propName)=>{
|
|
2290
|
+
if(propValue!==undefined&&typeof propValue!=="boolean"){
|
|
2291
|
+
throw new TypeError(
|
|
2292
|
+
`Descriptor property "${propName}" must be a boolean: ${propValue}`
|
|
2293
|
+
)
|
|
2294
|
+
}
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
const validateUnknownProps=(unknownProps)=>{
|
|
2298
|
+
const[unknownProp]=Object.keys(unknownProps);
|
|
2299
|
+
|
|
2300
|
+
if(unknownProp!==undefined){
|
|
2301
|
+
throw new TypeError(
|
|
2302
|
+
`Unknown descriptor property "${unknownProp}": ${unknownProps[unknownProp]}`
|
|
2303
|
+
)
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
|
|
2307
|
+
const redefineProperty=(input,key,newDescriptor)=>{
|
|
2308
|
+
const newDescriptorA=normalizeInput(input,key,newDescriptor);
|
|
2309
|
+
const currentDescriptor=getCurrentDescriptor(input,key);
|
|
2310
|
+
const finalDescriptor=mergeDescriptors(newDescriptorA,currentDescriptor);
|
|
2311
|
+
setProperty(input,key,finalDescriptor);
|
|
2312
|
+
return input
|
|
2313
|
+
};
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
const getCurrentDescriptor=(input,key)=>{
|
|
2317
|
+
const descriptor=Object.getOwnPropertyDescriptor(input,key);
|
|
2318
|
+
|
|
2319
|
+
if(descriptor!==undefined){
|
|
2320
|
+
return descriptor
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
const prototype=Object.getPrototypeOf(input);
|
|
2324
|
+
return prototype===null?{}:getCurrentDescriptor(prototype,key)
|
|
2325
|
+
};
|
|
2326
|
+
|
|
2327
|
+
|
|
2328
|
+
const setProperty=(input,key,finalDescriptor)=>{
|
|
2329
|
+
try{
|
|
2330
|
+
|
|
2331
|
+
Object.defineProperty(input,key,finalDescriptor);
|
|
2332
|
+
}catch{}
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
const assignProp=(error,propName,propValue)=>{
|
|
2336
|
+
if(propValue!==undefined){
|
|
2337
|
+
return setProp(error,propName,propValue)
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
try{
|
|
2341
|
+
|
|
2342
|
+
delete error[propName];
|
|
2343
|
+
}catch{}
|
|
2344
|
+
|
|
2345
|
+
if(error[propName]!==undefined){
|
|
2346
|
+
return setProp(error,propName)
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
|
|
2350
|
+
const setProp=(error,propName,propValue)=>{
|
|
2351
|
+
const nonEnum=getNonEnum(propName);
|
|
2352
|
+
redefineProperty(error,propName,{value:propValue,...nonEnum});
|
|
2353
|
+
};
|
|
2354
|
+
|
|
2355
|
+
|
|
2356
|
+
const getNonEnum=(propName)=>
|
|
2357
|
+
typeof propName==="string"&&propName.startsWith("_")?
|
|
2358
|
+
{enumerable:false}:
|
|
2359
|
+
{};
|
|
2360
|
+
|
|
2361
|
+
const isErrorInstance=(value)=>
|
|
2362
|
+
isInstanceOfError(value)||hasErrorTag(value);
|
|
2363
|
+
|
|
2364
|
+
|
|
2365
|
+
|
|
2366
|
+
const isInstanceOfError=(value)=>{
|
|
2367
|
+
try{
|
|
2368
|
+
return value instanceof Error
|
|
2369
|
+
}catch{
|
|
2370
|
+
return false
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
const hasErrorTag=(value)=>{
|
|
2375
|
+
try{
|
|
2376
|
+
return ERROR_TAGS.has(Object.prototype.toString.call(value))
|
|
2377
|
+
}catch{
|
|
2378
|
+
return false
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2381
|
+
|
|
2382
|
+
const ERROR_TAGS=new Set([
|
|
2383
|
+
|
|
2384
|
+
"[object Error]",
|
|
2385
|
+
|
|
2386
|
+
"[object DOMException]",
|
|
2387
|
+
|
|
2388
|
+
"[object DOMError]",
|
|
2389
|
+
|
|
2390
|
+
"[object Exception]"]
|
|
2391
|
+
);
|
|
2392
|
+
|
|
2393
|
+
const normalizeOptions=(error,props,opts={})=>{
|
|
2394
|
+
validateErrorOrObject(error,"First argument");
|
|
2395
|
+
validateErrorOrObject(props,"Second argument");
|
|
2396
|
+
|
|
2397
|
+
if(!isPlainObject(opts)){
|
|
2398
|
+
throw new TypeError(`Options must be a plain object: ${opts}`)
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
const{soft=false}=opts;
|
|
2402
|
+
|
|
2403
|
+
if(typeof soft!=="boolean"){
|
|
2404
|
+
throw new TypeError(`Option "soft" must be a boolean: ${soft}`)
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
return {soft}
|
|
2408
|
+
};
|
|
2409
|
+
|
|
2410
|
+
const validateErrorOrObject=(value,prefix)=>{
|
|
2411
|
+
if(value===undefined){
|
|
2412
|
+
throw new TypeError(`${prefix} is required.`)
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
if(!isErrorOrObject(value)){
|
|
2416
|
+
throw new TypeError(
|
|
2417
|
+
`${prefix} must be a plain object or an error: ${value}`
|
|
2418
|
+
)
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2422
|
+
const isErrorOrObject=(value)=>isPlainObject(value)||isErrorInstance(value);
|
|
2423
|
+
|
|
2424
|
+
const shouldSkipProp=({error,props,propName,soft})=>
|
|
2425
|
+
isIgnoredPropName(propName)||
|
|
2426
|
+
!isEnum.call(props,propName)||
|
|
2427
|
+
soft&&error[propName]!==undefined;
|
|
2428
|
+
|
|
2429
|
+
const isIgnoredPropName=(propName)=>
|
|
2430
|
+
propName in CHECK_ERROR||IGNORED_PROPS.has(propName);
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
const CHECK_ERROR=new Error("check");
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
const IGNORED_PROPS=new Set(["prototype","errors","cause"]);
|
|
2440
|
+
|
|
2441
|
+
const{propertyIsEnumerable:isEnum}=Object.prototype;
|
|
2442
|
+
|
|
2443
|
+
const setErrorProps=(error,props,opts)=>{
|
|
2444
|
+
const{soft}=normalizeOptions(error,props,opts);
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
for(const propName of Reflect.ownKeys(props)){
|
|
2448
|
+
setErrorProp({error,props,propName,soft});
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
return error
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
|
|
2457
|
+
|
|
2458
|
+
const setErrorProp=({error,props,propName,soft})=>{
|
|
2459
|
+
if(!shouldSkipProp({error,props,propName,soft})){
|
|
2460
|
+
assignProp(error,propName,props[propName]);
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
|
|
2464
|
+
const setErrorProperty=(error,propName,value)=>{
|
|
2465
|
+
|
|
2466
|
+
Object.defineProperty(error,propName,{
|
|
2467
|
+
value,
|
|
2468
|
+
writable:true,
|
|
2469
|
+
enumerable:false,
|
|
2470
|
+
configurable:true
|
|
2471
|
+
});
|
|
2472
|
+
};
|
|
2473
|
+
|
|
2474
|
+
const mergeAggregateCauses=(parent,recurse)=>{
|
|
2475
|
+
if(parent.errors===undefined){
|
|
2476
|
+
return
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
const errors=parent.errors.
|
|
2480
|
+
map((error)=>recurse(error).error).
|
|
2481
|
+
filter(Boolean);
|
|
2482
|
+
setErrorProperty(parent,"errors",errors);
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2485
|
+
const mergeAggregateErrors=({target,source,parent,child})=>{
|
|
2486
|
+
if(!hasErrors(target)){
|
|
2487
|
+
mergeSourceErrors(target,source);
|
|
2488
|
+
return
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
if(hasErrors(source)){
|
|
2492
|
+
setErrorProperty(target,"errors",[...child.errors,...parent.errors]);
|
|
2493
|
+
}
|
|
2494
|
+
};
|
|
2495
|
+
|
|
2496
|
+
const mergeSourceErrors=(target,source)=>{
|
|
2497
|
+
if(source.errors!==undefined){
|
|
2498
|
+
setErrorProperty(target,"errors",source.errors);
|
|
2499
|
+
}
|
|
2500
|
+
};
|
|
2501
|
+
|
|
2502
|
+
const hasErrors=(targetOrSource)=>
|
|
2503
|
+
targetOrSource.errors!==undefined&&targetOrSource.errors.length!==0;
|
|
2504
|
+
|
|
2505
|
+
const normalizeArgs=(
|
|
2506
|
+
error,
|
|
2507
|
+
newMessage,
|
|
2508
|
+
currentMessage=error.message)=>
|
|
2509
|
+
{
|
|
2510
|
+
if(typeof newMessage!=="string"){
|
|
2511
|
+
throw new TypeError(`newMessage must be a string: ${newMessage}`)
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
if(typeof currentMessage!=="string"){
|
|
2515
|
+
throw new TypeError(`currentMessage must be a string: ${currentMessage}`)
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
return currentMessage
|
|
2519
|
+
};
|
|
2520
|
+
|
|
2521
|
+
const getStack$1=({name,stack},newMessage,currentMessage)=>
|
|
2522
|
+
currentMessage!==""&&stack.includes(currentMessage)?
|
|
2523
|
+
replaceMessage({name,stack,newMessage,currentMessage}):
|
|
2524
|
+
insertMessage(name,stack,newMessage);
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
|
|
2528
|
+
const replaceMessage=({name,stack,newMessage,currentMessage})=>{
|
|
2529
|
+
const replacers=getReplacers(name,newMessage,currentMessage);
|
|
2530
|
+
const[fromA,to]=replacers.find(([from])=>stack.includes(from));
|
|
2531
|
+
return stack.replace(fromA,to)
|
|
2532
|
+
};
|
|
2533
|
+
|
|
2534
|
+
|
|
2535
|
+
|
|
2536
|
+
const getReplacers=(name,newMessage,currentMessage)=>[
|
|
2537
|
+
[`${name}: ${currentMessage}`,`${name}: ${newMessage}`],
|
|
2538
|
+
[`: ${currentMessage}`,`: ${newMessage}`],
|
|
2539
|
+
[`\n${currentMessage}`,`\n${newMessage}`],
|
|
2540
|
+
[` ${currentMessage}`,` ${newMessage}`],
|
|
2541
|
+
[currentMessage,newMessage]];
|
|
2542
|
+
|
|
2543
|
+
|
|
2544
|
+
const insertMessage=(name,stack,newMessage)=>{
|
|
2545
|
+
const nameAndColon=`${name}: `;
|
|
2546
|
+
const newMessageA=newMessage.trimEnd();
|
|
2547
|
+
|
|
2548
|
+
if(stack===name||stack.startsWith(`${name}\n`)){
|
|
2549
|
+
return stack.replace(name,`${nameAndColon}${newMessageA}`)
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
return stack.startsWith(nameAndColon)?
|
|
2553
|
+
stack.replace(nameAndColon,`${nameAndColon}${newMessageA}\n`):
|
|
2554
|
+
`${nameAndColon}${newMessageA}\n${stack}`
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
const setErrorMessage=(error,newMessage,currentMessage)=>{
|
|
2558
|
+
const errorA=normalizeException(error);
|
|
2559
|
+
const currentMessageA=normalizeArgs(errorA,newMessage,currentMessage);
|
|
2560
|
+
setNonEnumProp(errorA,"message",newMessage);
|
|
2561
|
+
updateStack(errorA,newMessage,currentMessageA);
|
|
2562
|
+
return errorA
|
|
2563
|
+
};
|
|
2564
|
+
|
|
2565
|
+
|
|
2566
|
+
|
|
2567
|
+
const updateStack=(error,newMessage,currentMessage)=>{
|
|
2568
|
+
if(newMessage===currentMessage||!stackIncludesMessage()){
|
|
2569
|
+
return
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
const stack=getStack$1(error,newMessage,currentMessage);
|
|
2573
|
+
setNonEnumProp(error,"stack",stack);
|
|
2574
|
+
};
|
|
2575
|
+
|
|
2576
|
+
|
|
2577
|
+
const stackIncludesMessage=()=>{
|
|
2578
|
+
const{stack}=new Error(EXAMPLE_MESSAGE);
|
|
2579
|
+
return typeof stack==="string"&&stack.includes(EXAMPLE_MESSAGE)
|
|
2580
|
+
};
|
|
2581
|
+
|
|
2582
|
+
const EXAMPLE_MESSAGE="set-error-message test message";
|
|
2583
|
+
|
|
2584
|
+
const setNonEnumProp=(error,propName,value)=>{
|
|
2585
|
+
|
|
2586
|
+
Object.defineProperty(error,propName,{
|
|
2587
|
+
value,
|
|
2588
|
+
enumerable:false,
|
|
2589
|
+
writable:true,
|
|
2590
|
+
configurable:true
|
|
2591
|
+
});
|
|
2592
|
+
};
|
|
2593
|
+
|
|
2594
|
+
const wrapErrorMessage=(error,newMessage,oldMessage)=>{
|
|
2595
|
+
if(typeof newMessage!=="string"){
|
|
2596
|
+
throw new TypeError(
|
|
2597
|
+
`Second argument must be a message string: ${newMessage}`
|
|
2598
|
+
)
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
const errorA=normalizeException(error);
|
|
2602
|
+
const message=getMessage(newMessage,errorA.message);
|
|
2603
|
+
return setErrorMessage(errorA,message,oldMessage)
|
|
2604
|
+
};
|
|
2605
|
+
|
|
2606
|
+
|
|
2607
|
+
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
|
|
2612
|
+
|
|
2613
|
+
|
|
2614
|
+
const getMessage=(rawNewMessage,rawCurrentMessage)=>{
|
|
2615
|
+
const newMessage=rawNewMessage.trim();
|
|
2616
|
+
const currentMessage=rawCurrentMessage.trim();
|
|
2617
|
+
|
|
2618
|
+
if(newMessage===""){
|
|
2619
|
+
return currentMessage
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
if(currentMessage===""){
|
|
2623
|
+
return newMessage
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
return concatMessages(newMessage,currentMessage,rawNewMessage)
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
const concatMessages=(newMessage,currentMessage,rawNewMessage)=>{
|
|
2630
|
+
if(!newMessage.endsWith(PREPEND_CHAR)){
|
|
2631
|
+
return `${currentMessage}\n${newMessage}`
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
return rawNewMessage.endsWith(PREPEND_NEWLINE_CHAR)?
|
|
2635
|
+
`${newMessage}\n${currentMessage}`:
|
|
2636
|
+
`${newMessage} ${currentMessage}`
|
|
2637
|
+
};
|
|
2638
|
+
|
|
2639
|
+
const PREPEND_CHAR=":";
|
|
2640
|
+
const PREPEND_NEWLINE_CHAR="\n";
|
|
2641
|
+
|
|
2642
|
+
const mergeMessage=({parent,child,target,stackError})=>{
|
|
2643
|
+
const parentMessage=parent.message;
|
|
2644
|
+
|
|
2645
|
+
target.message=child.message;
|
|
2646
|
+
return wrapErrorMessage(target,parentMessage,stackError.message)
|
|
2647
|
+
};
|
|
2648
|
+
|
|
2649
|
+
const hasStack=(error,stack)=>getStack(error)===stack;
|
|
2650
|
+
|
|
2651
|
+
|
|
2652
|
+
|
|
2653
|
+
|
|
2654
|
+
const getStack=(error)=>
|
|
2655
|
+
typeof error==="object"&&error!==null?error.stack:undefined;
|
|
2656
|
+
|
|
2657
|
+
|
|
2658
|
+
|
|
2659
|
+
|
|
2660
|
+
|
|
2661
|
+
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
|
|
2665
|
+
|
|
2666
|
+
const mergeStack=({wrap,target,source,childHasStack})=>{
|
|
2667
|
+
if(wrap===childHasStack){
|
|
2668
|
+
return target
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
setErrorProperty(target,"stack",source.stack);
|
|
2672
|
+
return source
|
|
2673
|
+
};
|
|
2674
|
+
|
|
2675
|
+
const getWrap=(parent)=>{
|
|
2676
|
+
const{wrap,name}=parent;
|
|
2677
|
+
|
|
2678
|
+
if(typeof wrap!=="boolean"){
|
|
2679
|
+
return name==="Error"
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
if(Object.hasOwn(parent,"wrap")){
|
|
2683
|
+
|
|
2684
|
+
delete parent.wrap;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
return wrap
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
const mergeErrorCause=(error)=>mergeError(error,[]).error;
|
|
2691
|
+
|
|
2692
|
+
|
|
2693
|
+
|
|
2694
|
+
|
|
2695
|
+
|
|
2696
|
+
|
|
2697
|
+
const mergeError=(error,parents)=>{
|
|
2698
|
+
if(parents.includes(error)){
|
|
2699
|
+
return {}
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
const recurse=(innerError)=>mergeError(innerError,[...parents,error]);
|
|
2703
|
+
const stack=getStack(error);
|
|
2704
|
+
const errorA=normalizeException(error,{shallow:true});
|
|
2705
|
+
const parentHasStack=hasStack(errorA,stack);
|
|
2706
|
+
|
|
2707
|
+
mergeAggregateCauses(errorA,recurse);
|
|
2708
|
+
const{parent:errorB,childHasStack}=mergeCause(errorA,recurse);
|
|
2709
|
+
const errorHasStack=parentHasStack||childHasStack;
|
|
2710
|
+
return {error:errorB,errorHasStack}
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
|
|
2714
|
+
|
|
2715
|
+
const mergeCause=(parent,recurse)=>{
|
|
2716
|
+
const wrap=getWrap(parent);
|
|
2717
|
+
|
|
2718
|
+
if(parent.cause===undefined){
|
|
2719
|
+
return {parent,childHasStack:false}
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
const{error:child,errorHasStack:childHasStack}=recurse(parent.cause);
|
|
2723
|
+
|
|
2724
|
+
delete parent.cause;
|
|
2725
|
+
const parentA=mergeChild({parent,child,childHasStack,wrap});
|
|
2726
|
+
return {parent:parentA,childHasStack}
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2729
|
+
const mergeChild=({parent,child,childHasStack,wrap})=>{
|
|
2730
|
+
if(child===undefined){
|
|
2731
|
+
return parent
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
const[target,source]=wrap?[child,parent]:[parent,child];
|
|
2735
|
+
const stackError=mergeStack({wrap,target,source,childHasStack});
|
|
2736
|
+
const targetA=setErrorClass(target,target.constructor,stackError.name);
|
|
2737
|
+
const targetB=mergeMessage({parent,child,target:targetA,stackError});
|
|
2738
|
+
mergeAggregateErrors({target:targetB,source,parent,child});
|
|
2739
|
+
const targetC=setErrorProps(targetB,source,{soft:!wrap});
|
|
2740
|
+
return targetC
|
|
2741
|
+
};
|
|
2742
|
+
|
|
2743
|
+
function safeStringifyReplacer(seen) {
|
|
2744
|
+
return function (key, value) {
|
|
2745
|
+
// Handle objects with a custom `.toJSON()` method.
|
|
2746
|
+
if (typeof value?.toJSON === 'function') {
|
|
2747
|
+
value = value.toJSON();
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
if (!(value !== null && typeof value === 'object')) {
|
|
2751
|
+
return value;
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
if (seen.has(value)) {
|
|
2755
|
+
return '[Circular]';
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
seen.add(value);
|
|
2759
|
+
|
|
2760
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
2761
|
+
|
|
2762
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
2763
|
+
newValue[key2] = safeStringifyReplacer(seen)(key2, value2);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
seen.delete(value);
|
|
2767
|
+
|
|
2768
|
+
return newValue;
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
function safeStringify(object, {indentation} = {}) {
|
|
2773
|
+
const seen = new WeakSet();
|
|
2774
|
+
return JSON.stringify(object, safeStringifyReplacer(seen), indentation);
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
const defaultParseStack = (stack) => {
|
|
2778
|
+
const lines = stack.split("\n").map((l) => l.trim().replace("file://", ""));
|
|
2779
|
+
return lines;
|
|
2780
|
+
};
|
|
2781
|
+
function formattedLogObj(logObj, parseStack = defaultParseStack) {
|
|
2782
|
+
const result = {
|
|
2783
|
+
message: ""
|
|
2784
|
+
};
|
|
2785
|
+
const error = logObj.args.find((a) => a instanceof Error);
|
|
2786
|
+
if (!error) {
|
|
2787
|
+
result.message = logObj.args.map((arg) => typeof arg === "string" ? arg : safeStringify(arg)).join("; ");
|
|
2788
|
+
if (typeof logObj.tag === "string" && logObj.tag.length > 0) {
|
|
2789
|
+
result.message = `[${logObj.tag}] ${result.message}`;
|
|
2790
|
+
}
|
|
2791
|
+
return result;
|
|
2792
|
+
}
|
|
2793
|
+
const mergedErr = logObj.args.reduce(
|
|
2794
|
+
(acc, arg) => {
|
|
2795
|
+
if (arg === error) {
|
|
2796
|
+
return acc;
|
|
2797
|
+
}
|
|
2798
|
+
const msg = typeof arg === "string" ? arg : safeStringify(arg);
|
|
2799
|
+
return wrapErrorMessage(acc, msg);
|
|
2800
|
+
},
|
|
2801
|
+
mergeErrorCause(error)
|
|
2802
|
+
);
|
|
2803
|
+
result.message = mergedErr.message;
|
|
2804
|
+
result.error = {
|
|
2805
|
+
message: mergedErr.message,
|
|
2806
|
+
name: mergedErr.name
|
|
2807
|
+
};
|
|
2808
|
+
if (mergedErr.stack) {
|
|
2809
|
+
const stack = parseStack(mergedErr.stack);
|
|
2810
|
+
result.error.stack = stack.join("\n");
|
|
2811
|
+
result.message += "\n" + stack.slice(1).map((l) => " " + l).join("\n");
|
|
2812
|
+
}
|
|
2813
|
+
if (typeof logObj.tag === "string" && logObj.tag.length > 0) {
|
|
2814
|
+
result.message = `[${logObj.tag}] ${result.message}`;
|
|
2815
|
+
}
|
|
2816
|
+
return result;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
function parseStack(stack) {
|
|
2820
|
+
const currentDir = process$1.cwd() + node_path.sep;
|
|
2821
|
+
const lines = stack.split("\n").map((l) => l.trim().replace("file://", "").replace(currentDir, ""));
|
|
2822
|
+
return lines;
|
|
2823
|
+
}
|
|
2824
|
+
function formatLogObj(logObj) {
|
|
2825
|
+
return formattedLogObj(logObj, parseStack);
|
|
2826
|
+
}
|
|
2827
|
+
const level = LogLevels.debug;
|
|
2828
|
+
const consola = createConsola({
|
|
2829
|
+
level,
|
|
2830
|
+
defaults: {
|
|
2831
|
+
level
|
|
2832
|
+
},
|
|
2833
|
+
throttle: 2,
|
|
2834
|
+
throttleMin: 500,
|
|
2835
|
+
formatOptions: {
|
|
2836
|
+
colors: true,
|
|
2837
|
+
compact: false,
|
|
2838
|
+
date: false
|
|
2839
|
+
}
|
|
2840
|
+
});
|
|
2841
|
+
|
|
2842
|
+
exports.LogLevels = LogLevels;
|
|
2843
|
+
exports.colors = colors;
|
|
2844
|
+
exports.consola = consola;
|
|
2845
|
+
exports.formatLogObj = formatLogObj;
|
|
2846
|
+
exports.isUnicodeSupported = isUnicodeSupported;
|