@likec4/log 1.20.1 → 1.20.2

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