@socketsecurity/lib 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/abort.js.map +2 -2
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.d.ts +143 -0
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +1 -4
- package/dist/bin.js.map +2 -2
- package/dist/cacache.d.ts +0 -2
- package/dist/cacache.js +0 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/dlx.js.map +2 -2
- package/dist/external/@yarnpkg/extensions.d.ts +0 -1
- package/dist/external/cacache.d.ts +0 -7
- package/dist/external/debug.d.ts +0 -3
- package/dist/external/fast-sort.d.ts +0 -1
- package/dist/external/libnpmpack.d.ts +0 -1
- package/dist/external/make-fetch-happen.d.ts +0 -1
- package/dist/external/pacote.d.ts +0 -5
- package/dist/external/semver.d.ts +0 -1
- package/dist/external/validate-npm-package-name.js +1 -1
- package/dist/external/yargs-parser.d.ts +0 -1
- package/dist/external/yoctocolors-cjs.js +1 -1
- package/dist/external/zod.js +9 -9
- package/dist/fs.d.ts +595 -23
- package/dist/fs.js.map +2 -2
- package/dist/git.d.ts +488 -41
- package/dist/git.js.map +2 -2
- package/dist/github.d.ts +361 -12
- package/dist/github.js.map +2 -2
- package/dist/http-request.d.ts +463 -4
- package/dist/http-request.js.map +2 -2
- package/dist/json.d.ts +177 -4
- package/dist/json.js.map +2 -2
- package/dist/logger.d.ts +823 -70
- package/dist/logger.js +654 -51
- package/dist/logger.js.map +2 -2
- package/dist/objects.d.ts +386 -10
- package/dist/objects.js.map +2 -2
- package/dist/path.d.ts +270 -6
- package/dist/path.js.map +2 -2
- package/dist/promises.d.ts +432 -27
- package/dist/promises.js +3 -0
- package/dist/promises.js.map +2 -2
- package/dist/signal-exit.js.map +2 -2
- package/dist/sorts.js.map +2 -2
- package/dist/spawn.d.ts +242 -33
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.d.ts +260 -20
- package/dist/spinner.js +201 -63
- package/dist/spinner.js.map +2 -2
- package/dist/stdio/clear.d.ts +130 -9
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.d.ts +106 -10
- package/dist/stdio/divider.js +10 -0
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.d.ts +70 -3
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.d.ts +93 -12
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.d.ts +82 -14
- package/dist/stdio/mask.js +25 -4
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.d.ts +112 -15
- package/dist/stdio/progress.js +43 -3
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.d.ts +95 -5
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.d.ts +114 -11
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.d.ts +107 -11
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/strings.d.ts +357 -28
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/validation/json-parser.d.ts +226 -7
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.d.ts +114 -12
- package/dist/validation/types.js.map +1 -1
- package/package.json +5 -3
package/dist/logger.js
CHANGED
|
@@ -50,7 +50,6 @@ function constructConsole(...args) {
|
|
|
50
50
|
_Console = nodeConsole.Console;
|
|
51
51
|
}
|
|
52
52
|
return ReflectConstruct(
|
|
53
|
-
// biome-ignore lint/style/noNonNullAssertion: Initialized above.
|
|
54
53
|
_Console,
|
|
55
54
|
// eslint-disable-line no-undef
|
|
56
55
|
args
|
|
@@ -133,12 +132,17 @@ const maxIndentation = 1e3;
|
|
|
133
132
|
const privateConsole = /* @__PURE__ */ new WeakMap();
|
|
134
133
|
const consoleSymbols = Object.getOwnPropertySymbols(globalConsole);
|
|
135
134
|
const incLogCallCountSymbol = Symbol.for("logger.logCallCount++");
|
|
136
|
-
const kGroupIndentationWidthSymbol = (
|
|
137
|
-
// biome-ignore lint/suspicious/noExplicitAny: Symbol property access.
|
|
138
|
-
consoleSymbols.find((s) => s.label === "kGroupIndentWidth") ?? Symbol("kGroupIndentWidth")
|
|
139
|
-
);
|
|
135
|
+
const kGroupIndentationWidthSymbol = consoleSymbols.find((s) => s.label === "kGroupIndentWidth") ?? Symbol("kGroupIndentWidth");
|
|
140
136
|
const lastWasBlankSymbol = Symbol.for("logger.lastWasBlank");
|
|
141
137
|
class Logger {
|
|
138
|
+
/**
|
|
139
|
+
* Static reference to log symbols for convenience.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* console.log(`${Logger.LOG_SYMBOLS.success} Done`)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
142
146
|
static LOG_SYMBOLS = LOG_SYMBOLS;
|
|
143
147
|
#parent;
|
|
144
148
|
#boundStream;
|
|
@@ -150,6 +154,27 @@ class Logger {
|
|
|
150
154
|
#logCallCount = 0;
|
|
151
155
|
#constructorArgs;
|
|
152
156
|
#options;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new Logger instance.
|
|
159
|
+
*
|
|
160
|
+
* When called without arguments, creates a logger using the default
|
|
161
|
+
* `process.stdout` and `process.stderr` streams. Can accept custom
|
|
162
|
+
* console constructor arguments for advanced use cases.
|
|
163
|
+
*
|
|
164
|
+
* @param args - Optional console constructor arguments
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Default logger
|
|
169
|
+
* const logger = new Logger()
|
|
170
|
+
*
|
|
171
|
+
* // Custom streams (advanced)
|
|
172
|
+
* const customLogger = new Logger({
|
|
173
|
+
* stdout: customWritableStream,
|
|
174
|
+
* stderr: customErrorStream
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
153
178
|
constructor(...args) {
|
|
154
179
|
this.#constructorArgs = args;
|
|
155
180
|
const options = args["0"];
|
|
@@ -172,8 +197,25 @@ class Logger {
|
|
|
172
197
|
}
|
|
173
198
|
}
|
|
174
199
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
200
|
+
* Gets a logger instance bound exclusively to stderr.
|
|
201
|
+
*
|
|
202
|
+
* All logging operations on this instance will write to stderr only.
|
|
203
|
+
* Indentation is tracked separately from stdout. The instance is
|
|
204
|
+
* cached and reused on subsequent accesses.
|
|
205
|
+
*
|
|
206
|
+
* @returns A logger instance bound to stderr
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Write errors to stderr
|
|
211
|
+
* logger.stderr.error('Configuration invalid')
|
|
212
|
+
* logger.stderr.warn('Using fallback settings')
|
|
213
|
+
*
|
|
214
|
+
* // Indent only affects stderr
|
|
215
|
+
* logger.stderr.indent()
|
|
216
|
+
* logger.stderr.error('Nested error details')
|
|
217
|
+
* logger.stderr.dedent()
|
|
218
|
+
* ```
|
|
177
219
|
*/
|
|
178
220
|
get stderr() {
|
|
179
221
|
if (!this.#stderrLogger) {
|
|
@@ -186,8 +228,25 @@ class Logger {
|
|
|
186
228
|
return this.#stderrLogger;
|
|
187
229
|
}
|
|
188
230
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
231
|
+
* Gets a logger instance bound exclusively to stdout.
|
|
232
|
+
*
|
|
233
|
+
* All logging operations on this instance will write to stdout only.
|
|
234
|
+
* Indentation is tracked separately from stderr. The instance is
|
|
235
|
+
* cached and reused on subsequent accesses.
|
|
236
|
+
*
|
|
237
|
+
* @returns A logger instance bound to stdout
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* // Write normal output to stdout
|
|
242
|
+
* logger.stdout.log('Processing started')
|
|
243
|
+
* logger.stdout.log('Items processed: 42')
|
|
244
|
+
*
|
|
245
|
+
* // Indent only affects stdout
|
|
246
|
+
* logger.stdout.indent()
|
|
247
|
+
* logger.stdout.log('Detailed output')
|
|
248
|
+
* logger.stdout.dedent()
|
|
249
|
+
* ```
|
|
191
250
|
*/
|
|
192
251
|
get stdout() {
|
|
193
252
|
if (!this.#stdoutLogger) {
|
|
@@ -287,27 +346,65 @@ class Logger {
|
|
|
287
346
|
return this;
|
|
288
347
|
}
|
|
289
348
|
/**
|
|
290
|
-
*
|
|
349
|
+
* Gets the total number of log calls made on this logger instance.
|
|
350
|
+
*
|
|
351
|
+
* Tracks all logging method calls including `log()`, `error()`, `warn()`,
|
|
352
|
+
* `success()`, `fail()`, etc. Useful for testing and monitoring logging activity.
|
|
353
|
+
*
|
|
354
|
+
* @returns The number of times logging methods have been called
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* logger.log('Message 1')
|
|
359
|
+
* logger.error('Message 2')
|
|
360
|
+
* console.log(logger.logCallCount) // 2
|
|
361
|
+
* ```
|
|
291
362
|
*/
|
|
292
363
|
get logCallCount() {
|
|
293
364
|
return this.#logCallCount;
|
|
294
365
|
}
|
|
295
366
|
/**
|
|
296
|
-
*
|
|
367
|
+
* Increments the internal log call counter.
|
|
368
|
+
*
|
|
369
|
+
* This is called automatically by logging methods and should not
|
|
370
|
+
* be called directly in normal usage.
|
|
371
|
+
*
|
|
372
|
+
* @returns The logger instance for chaining
|
|
297
373
|
*/
|
|
298
374
|
[incLogCallCountSymbol]() {
|
|
299
375
|
this.#logCallCount += 1;
|
|
300
376
|
return this;
|
|
301
377
|
}
|
|
302
378
|
/**
|
|
303
|
-
*
|
|
379
|
+
* Sets whether the last logged line was blank.
|
|
380
|
+
*
|
|
381
|
+
* Used internally to track blank lines and prevent duplicate spacing.
|
|
382
|
+
* This is called automatically by logging methods.
|
|
383
|
+
*
|
|
384
|
+
* @param value - Whether the last line was blank
|
|
385
|
+
* @returns The logger instance for chaining
|
|
304
386
|
*/
|
|
305
387
|
[lastWasBlankSymbol](value) {
|
|
306
388
|
this.#lastWasBlank = !!value;
|
|
307
389
|
return this;
|
|
308
390
|
}
|
|
309
391
|
/**
|
|
310
|
-
*
|
|
392
|
+
* Logs an assertion failure message if the value is falsy.
|
|
393
|
+
*
|
|
394
|
+
* Works like `console.assert()` but returns the logger for chaining.
|
|
395
|
+
* If the value is truthy, nothing is logged. If falsy, logs an error
|
|
396
|
+
* message with an assertion failure.
|
|
397
|
+
*
|
|
398
|
+
* @param value - The value to test
|
|
399
|
+
* @param message - Optional message and additional arguments to log
|
|
400
|
+
* @returns The logger instance for chaining
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* logger.assert(true, 'This will not log')
|
|
405
|
+
* logger.assert(false, 'Assertion failed: value is false')
|
|
406
|
+
* logger.assert(items.length > 0, 'No items found')
|
|
407
|
+
* ```
|
|
311
408
|
*/
|
|
312
409
|
assert(value, ...message) {
|
|
313
410
|
const con = privateConsole.get(this);
|
|
@@ -316,8 +413,23 @@ class Logger {
|
|
|
316
413
|
return value ? this : this[incLogCallCountSymbol]();
|
|
317
414
|
}
|
|
318
415
|
/**
|
|
319
|
-
*
|
|
320
|
-
*
|
|
416
|
+
* Clears the visible terminal screen.
|
|
417
|
+
*
|
|
418
|
+
* Only available on the main logger instance, not on stream-bound instances
|
|
419
|
+
* (`.stderr` or `.stdout`). Resets the log call count and blank line tracking
|
|
420
|
+
* if the output is a TTY.
|
|
421
|
+
*
|
|
422
|
+
* @returns The logger instance for chaining
|
|
423
|
+
* @throws {Error} If called on a stream-bound logger instance
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* logger.log('Some output')
|
|
428
|
+
* logger.clearVisible() // Screen is now clear
|
|
429
|
+
*
|
|
430
|
+
* // Error: Can't call on stream-bound instance
|
|
431
|
+
* logger.stderr.clearVisible() // throws
|
|
432
|
+
* ```
|
|
321
433
|
*/
|
|
322
434
|
clearVisible() {
|
|
323
435
|
if (this.#boundStream) {
|
|
@@ -335,7 +447,21 @@ class Logger {
|
|
|
335
447
|
return this;
|
|
336
448
|
}
|
|
337
449
|
/**
|
|
338
|
-
*
|
|
450
|
+
* Increments and logs a counter for the given label.
|
|
451
|
+
*
|
|
452
|
+
* Each unique label maintains its own counter. Works like `console.count()`.
|
|
453
|
+
*
|
|
454
|
+
* @param label - Optional label for the counter
|
|
455
|
+
* @default 'default'
|
|
456
|
+
* @returns The logger instance for chaining
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* logger.count('requests') // requests: 1
|
|
461
|
+
* logger.count('requests') // requests: 2
|
|
462
|
+
* logger.count('errors') // errors: 1
|
|
463
|
+
* logger.count() // default: 1
|
|
464
|
+
* ```
|
|
339
465
|
*/
|
|
340
466
|
count(label) {
|
|
341
467
|
const con = privateConsole.get(this);
|
|
@@ -344,7 +470,26 @@ class Logger {
|
|
|
344
470
|
return this[incLogCallCountSymbol]();
|
|
345
471
|
}
|
|
346
472
|
/**
|
|
347
|
-
*
|
|
473
|
+
* Creates a task that logs start and completion messages automatically.
|
|
474
|
+
*
|
|
475
|
+
* Returns a task object with a `run()` method that executes the provided
|
|
476
|
+
* function and logs "Starting task: {name}" before execution and
|
|
477
|
+
* "Completed task: {name}" after completion.
|
|
478
|
+
*
|
|
479
|
+
* @param name - The name of the task
|
|
480
|
+
* @returns A task object with a `run()` method
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const task = logger.createTask('Database Migration')
|
|
485
|
+
* const result = task.run(() => {
|
|
486
|
+
* // Logs: "Starting task: Database Migration"
|
|
487
|
+
* migrateDatabase()
|
|
488
|
+
* return 'success'
|
|
489
|
+
* // Logs: "Completed task: Database Migration"
|
|
490
|
+
* })
|
|
491
|
+
* console.log(result) // 'success'
|
|
492
|
+
* ```
|
|
348
493
|
*/
|
|
349
494
|
createTask(name) {
|
|
350
495
|
return {
|
|
@@ -357,9 +502,33 @@ class Logger {
|
|
|
357
502
|
};
|
|
358
503
|
}
|
|
359
504
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
505
|
+
* Decreases the indentation level by removing spaces from the prefix.
|
|
506
|
+
*
|
|
507
|
+
* When called on the main logger, affects both stderr and stdout indentation.
|
|
508
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), affects
|
|
509
|
+
* only that stream's indentation.
|
|
510
|
+
*
|
|
511
|
+
* @param spaces - Number of spaces to remove from indentation
|
|
512
|
+
* @default 2
|
|
513
|
+
* @returns The logger instance for chaining
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* logger.indent()
|
|
518
|
+
* logger.log('Indented')
|
|
519
|
+
* logger.dedent()
|
|
520
|
+
* logger.log('Back to normal')
|
|
521
|
+
*
|
|
522
|
+
* // Remove custom amount
|
|
523
|
+
* logger.indent(4)
|
|
524
|
+
* logger.log('Four spaces')
|
|
525
|
+
* logger.dedent(4)
|
|
526
|
+
*
|
|
527
|
+
* // Stream-specific dedent
|
|
528
|
+
* logger.stdout.indent()
|
|
529
|
+
* logger.stdout.log('Indented stdout')
|
|
530
|
+
* logger.stdout.dedent()
|
|
531
|
+
* ```
|
|
363
532
|
*/
|
|
364
533
|
dedent(spaces = 2) {
|
|
365
534
|
if (this.#boundStream) {
|
|
@@ -374,7 +543,22 @@ class Logger {
|
|
|
374
543
|
return this;
|
|
375
544
|
}
|
|
376
545
|
/**
|
|
377
|
-
*
|
|
546
|
+
* Displays an object's properties in a formatted way.
|
|
547
|
+
*
|
|
548
|
+
* Works like `console.dir()` with customizable options for depth,
|
|
549
|
+
* colors, etc. Useful for inspecting complex objects.
|
|
550
|
+
*
|
|
551
|
+
* @param obj - The object to display
|
|
552
|
+
* @param options - Optional formatting options (Node.js inspect options)
|
|
553
|
+
* @returns The logger instance for chaining
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* const obj = { a: 1, b: { c: 2, d: { e: 3 } } }
|
|
558
|
+
* logger.dir(obj)
|
|
559
|
+
* logger.dir(obj, { depth: 1 }) // Limit nesting depth
|
|
560
|
+
* logger.dir(obj, { colors: true }) // Enable colors
|
|
561
|
+
* ```
|
|
378
562
|
*/
|
|
379
563
|
dir(obj, options) {
|
|
380
564
|
const con = privateConsole.get(this);
|
|
@@ -383,7 +567,18 @@ class Logger {
|
|
|
383
567
|
return this[incLogCallCountSymbol]();
|
|
384
568
|
}
|
|
385
569
|
/**
|
|
386
|
-
*
|
|
570
|
+
* Displays data as XML/HTML in a formatted way.
|
|
571
|
+
*
|
|
572
|
+
* Works like `console.dirxml()`. In Node.js, behaves the same as `dir()`.
|
|
573
|
+
*
|
|
574
|
+
* @param data - The data to display
|
|
575
|
+
* @returns The logger instance for chaining
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* logger.dirxml(document.body) // In browser environments
|
|
580
|
+
* logger.dirxml(xmlObject) // In Node.js
|
|
581
|
+
* ```
|
|
387
582
|
*/
|
|
388
583
|
dirxml(...data) {
|
|
389
584
|
const con = privateConsole.get(this);
|
|
@@ -392,25 +587,87 @@ class Logger {
|
|
|
392
587
|
return this[incLogCallCountSymbol]();
|
|
393
588
|
}
|
|
394
589
|
/**
|
|
395
|
-
*
|
|
590
|
+
* Logs an error message to stderr.
|
|
591
|
+
*
|
|
592
|
+
* Automatically applies current indentation. All arguments are formatted
|
|
593
|
+
* and logged like `console.error()`.
|
|
594
|
+
*
|
|
595
|
+
* @param args - Message and additional arguments to log
|
|
596
|
+
* @returns The logger instance for chaining
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* logger.error('Build failed')
|
|
601
|
+
* logger.error('Error code:', 500)
|
|
602
|
+
* logger.error('Details:', { message: 'Not found' })
|
|
603
|
+
* ```
|
|
396
604
|
*/
|
|
397
605
|
error(...args) {
|
|
398
606
|
return this.#apply("error", args);
|
|
399
607
|
}
|
|
400
608
|
/**
|
|
401
|
-
*
|
|
609
|
+
* Logs a newline to stderr only if the last line wasn't already blank.
|
|
610
|
+
*
|
|
611
|
+
* Prevents multiple consecutive blank lines. Useful for adding spacing
|
|
612
|
+
* between sections without creating excessive whitespace.
|
|
613
|
+
*
|
|
614
|
+
* @returns The logger instance for chaining
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* logger.error('Error message')
|
|
619
|
+
* logger.errorNewline() // Adds blank line
|
|
620
|
+
* logger.errorNewline() // Does nothing (already blank)
|
|
621
|
+
* logger.error('Next section')
|
|
622
|
+
* ```
|
|
402
623
|
*/
|
|
403
624
|
errorNewline() {
|
|
404
625
|
return this.#lastWasBlank ? this : this.error("");
|
|
405
626
|
}
|
|
406
627
|
/**
|
|
407
|
-
*
|
|
628
|
+
* Logs a failure message with a red colored fail symbol.
|
|
629
|
+
*
|
|
630
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.fail` (red ✖).
|
|
631
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
632
|
+
* symbol, it will be stripped and replaced.
|
|
633
|
+
*
|
|
634
|
+
* @param args - Message and additional arguments to log
|
|
635
|
+
* @returns The logger instance for chaining
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* logger.fail('Build failed')
|
|
640
|
+
* logger.fail('Test suite failed:', { passed: 5, failed: 3 })
|
|
641
|
+
* ```
|
|
408
642
|
*/
|
|
409
643
|
fail(...args) {
|
|
410
644
|
return this.#symbolApply("fail", args);
|
|
411
645
|
}
|
|
412
646
|
/**
|
|
413
|
-
*
|
|
647
|
+
* Starts a new indented log group.
|
|
648
|
+
*
|
|
649
|
+
* If a label is provided, it's logged before increasing indentation.
|
|
650
|
+
* Groups can be nested. Each group increases indentation by the
|
|
651
|
+
* `kGroupIndentWidth` (default 2 spaces). Call `groupEnd()` to close.
|
|
652
|
+
*
|
|
653
|
+
* @param label - Optional label to display before the group
|
|
654
|
+
* @returns The logger instance for chaining
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* logger.group('Processing files:')
|
|
659
|
+
* logger.log('file1.js')
|
|
660
|
+
* logger.log('file2.js')
|
|
661
|
+
* logger.groupEnd()
|
|
662
|
+
*
|
|
663
|
+
* // Nested groups
|
|
664
|
+
* logger.group('Outer')
|
|
665
|
+
* logger.log('Outer content')
|
|
666
|
+
* logger.group('Inner')
|
|
667
|
+
* logger.log('Inner content')
|
|
668
|
+
* logger.groupEnd()
|
|
669
|
+
* logger.groupEnd()
|
|
670
|
+
* ```
|
|
414
671
|
*/
|
|
415
672
|
group(...label) {
|
|
416
673
|
const { length } = label;
|
|
@@ -426,7 +683,20 @@ class Logger {
|
|
|
426
683
|
return this;
|
|
427
684
|
}
|
|
428
685
|
/**
|
|
429
|
-
*
|
|
686
|
+
* Starts a new collapsed log group (alias for `group()`).
|
|
687
|
+
*
|
|
688
|
+
* In browser consoles, this creates a collapsed group. In Node.js,
|
|
689
|
+
* it behaves identically to `group()`.
|
|
690
|
+
*
|
|
691
|
+
* @param label - Optional label to display before the group
|
|
692
|
+
* @returns The logger instance for chaining
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* logger.groupCollapsed('Details')
|
|
697
|
+
* logger.log('Hidden by default in browsers')
|
|
698
|
+
* logger.groupEnd()
|
|
699
|
+
* ```
|
|
430
700
|
*/
|
|
431
701
|
// groupCollapsed is an alias of group.
|
|
432
702
|
// https://nodejs.org/api/console.html#consolegroupcollapsed
|
|
@@ -434,16 +704,54 @@ class Logger {
|
|
|
434
704
|
return ReflectApply(this.group, this, label);
|
|
435
705
|
}
|
|
436
706
|
/**
|
|
437
|
-
*
|
|
707
|
+
* Ends the current log group and decreases indentation.
|
|
708
|
+
*
|
|
709
|
+
* Must be called once for each `group()` or `groupCollapsed()` call
|
|
710
|
+
* to properly close the group and restore indentation.
|
|
711
|
+
*
|
|
712
|
+
* @returns The logger instance for chaining
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```typescript
|
|
716
|
+
* logger.group('Group 1')
|
|
717
|
+
* logger.log('Content')
|
|
718
|
+
* logger.groupEnd() // Closes 'Group 1'
|
|
719
|
+
* ```
|
|
438
720
|
*/
|
|
439
721
|
groupEnd() {
|
|
440
722
|
this.dedent(this[kGroupIndentationWidthSymbol]);
|
|
441
723
|
return this;
|
|
442
724
|
}
|
|
443
725
|
/**
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
726
|
+
* Increases the indentation level by adding spaces to the prefix.
|
|
727
|
+
*
|
|
728
|
+
* When called on the main logger, affects both stderr and stdout indentation.
|
|
729
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), affects
|
|
730
|
+
* only that stream's indentation. Maximum indentation is 1000 spaces.
|
|
731
|
+
*
|
|
732
|
+
* @param spaces - Number of spaces to add to indentation
|
|
733
|
+
* @default 2
|
|
734
|
+
* @returns The logger instance for chaining
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```typescript
|
|
738
|
+
* logger.log('Level 0')
|
|
739
|
+
* logger.indent()
|
|
740
|
+
* logger.log('Level 1')
|
|
741
|
+
* logger.indent()
|
|
742
|
+
* logger.log('Level 2')
|
|
743
|
+
* logger.dedent()
|
|
744
|
+
* logger.dedent()
|
|
745
|
+
*
|
|
746
|
+
* // Custom indent amount
|
|
747
|
+
* logger.indent(4)
|
|
748
|
+
* logger.log('Indented 4 spaces')
|
|
749
|
+
* logger.dedent(4)
|
|
750
|
+
*
|
|
751
|
+
* // Stream-specific indent
|
|
752
|
+
* logger.stdout.indent()
|
|
753
|
+
* logger.stdout.log('Only stdout is indented')
|
|
754
|
+
* ```
|
|
447
755
|
*/
|
|
448
756
|
indent(spaces = 2) {
|
|
449
757
|
const spacesToAdd = " ".repeat(Math.min(spaces, maxIndentation));
|
|
@@ -459,27 +767,86 @@ class Logger {
|
|
|
459
767
|
return this;
|
|
460
768
|
}
|
|
461
769
|
/**
|
|
462
|
-
*
|
|
770
|
+
* Logs an informational message with a blue colored info symbol.
|
|
771
|
+
*
|
|
772
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.info` (blue ℹ).
|
|
773
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
774
|
+
* symbol, it will be stripped and replaced.
|
|
775
|
+
*
|
|
776
|
+
* @param args - Message and additional arguments to log
|
|
777
|
+
* @returns The logger instance for chaining
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* ```typescript
|
|
781
|
+
* logger.info('Starting build process')
|
|
782
|
+
* logger.info('Configuration loaded:', config)
|
|
783
|
+
* logger.info('Using cache directory:', cacheDir)
|
|
784
|
+
* ```
|
|
463
785
|
*/
|
|
464
786
|
info(...args) {
|
|
465
787
|
return this.#symbolApply("info", args);
|
|
466
788
|
}
|
|
467
789
|
/**
|
|
468
|
-
*
|
|
790
|
+
* Logs a message to stdout.
|
|
791
|
+
*
|
|
792
|
+
* Automatically applies current indentation. All arguments are formatted
|
|
793
|
+
* and logged like `console.log()`. This is the primary method for
|
|
794
|
+
* standard output.
|
|
795
|
+
*
|
|
796
|
+
* @param args - Message and additional arguments to log
|
|
797
|
+
* @returns The logger instance for chaining
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* logger.log('Processing complete')
|
|
802
|
+
* logger.log('Items processed:', 42)
|
|
803
|
+
* logger.log('Results:', { success: true, count: 10 })
|
|
804
|
+
*
|
|
805
|
+
* // Method chaining
|
|
806
|
+
* logger.log('Step 1').log('Step 2').log('Step 3')
|
|
807
|
+
* ```
|
|
469
808
|
*/
|
|
470
809
|
log(...args) {
|
|
471
810
|
return this.#apply("log", args);
|
|
472
811
|
}
|
|
473
812
|
/**
|
|
474
|
-
*
|
|
813
|
+
* Logs a newline to stdout only if the last line wasn't already blank.
|
|
814
|
+
*
|
|
815
|
+
* Prevents multiple consecutive blank lines. Useful for adding spacing
|
|
816
|
+
* between sections without creating excessive whitespace.
|
|
817
|
+
*
|
|
818
|
+
* @returns The logger instance for chaining
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* logger.log('Section 1')
|
|
823
|
+
* logger.logNewline() // Adds blank line
|
|
824
|
+
* logger.logNewline() // Does nothing (already blank)
|
|
825
|
+
* logger.log('Section 2')
|
|
826
|
+
* ```
|
|
475
827
|
*/
|
|
476
828
|
logNewline() {
|
|
477
829
|
return this.#lastWasBlank ? this : this.log("");
|
|
478
830
|
}
|
|
479
831
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
832
|
+
* Resets all indentation to zero.
|
|
833
|
+
*
|
|
834
|
+
* When called on the main logger, resets both stderr and stdout indentation.
|
|
835
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), resets
|
|
836
|
+
* only that stream's indentation.
|
|
837
|
+
*
|
|
838
|
+
* @returns The logger instance for chaining
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* logger.indent().indent().indent()
|
|
843
|
+
* logger.log('Very indented')
|
|
844
|
+
* logger.resetIndent()
|
|
845
|
+
* logger.log('Back to zero indentation')
|
|
846
|
+
*
|
|
847
|
+
* // Reset only stdout
|
|
848
|
+
* logger.stdout.resetIndent()
|
|
849
|
+
* ```
|
|
483
850
|
*/
|
|
484
851
|
resetIndent() {
|
|
485
852
|
if (this.#boundStream) {
|
|
@@ -491,7 +858,30 @@ class Logger {
|
|
|
491
858
|
return this;
|
|
492
859
|
}
|
|
493
860
|
/**
|
|
494
|
-
*
|
|
861
|
+
* Logs a main step message with a blank line before it (stateless).
|
|
862
|
+
*
|
|
863
|
+
* Automatically adds a blank line before the message unless the last
|
|
864
|
+
* line was already blank. Useful for marking major steps in a process
|
|
865
|
+
* with clear visual separation.
|
|
866
|
+
*
|
|
867
|
+
* @param msg - The step message to log
|
|
868
|
+
* @param extras - Additional arguments to log
|
|
869
|
+
* @returns The logger instance for chaining
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
* ```typescript
|
|
873
|
+
* logger.step('Building project')
|
|
874
|
+
* logger.log('Compiling TypeScript...')
|
|
875
|
+
* logger.step('Running tests')
|
|
876
|
+
* logger.log('Running test suite...')
|
|
877
|
+
* // Output:
|
|
878
|
+
* // [blank line]
|
|
879
|
+
* // Building project
|
|
880
|
+
* // Compiling TypeScript...
|
|
881
|
+
* // [blank line]
|
|
882
|
+
* // Running tests
|
|
883
|
+
* // Running test suite...
|
|
884
|
+
* ```
|
|
495
885
|
*/
|
|
496
886
|
step(msg, ...extras) {
|
|
497
887
|
if (!this.#lastWasBlank) {
|
|
@@ -500,27 +890,104 @@ class Logger {
|
|
|
500
890
|
return this.log(msg, ...extras);
|
|
501
891
|
}
|
|
502
892
|
/**
|
|
503
|
-
*
|
|
893
|
+
* Logs an indented substep message (stateless).
|
|
894
|
+
*
|
|
895
|
+
* Adds a 2-space indent to the message without affecting the logger's
|
|
896
|
+
* indentation state. Useful for showing sub-items under a main step.
|
|
897
|
+
*
|
|
898
|
+
* @param msg - The substep message to log
|
|
899
|
+
* @param extras - Additional arguments to log
|
|
900
|
+
* @returns The logger instance for chaining
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```typescript
|
|
904
|
+
* logger.log('Installing dependencies:')
|
|
905
|
+
* logger.substep('Installing react')
|
|
906
|
+
* logger.substep('Installing typescript')
|
|
907
|
+
* logger.substep('Installing eslint')
|
|
908
|
+
* // Output:
|
|
909
|
+
* // Installing dependencies:
|
|
910
|
+
* // Installing react
|
|
911
|
+
* // Installing typescript
|
|
912
|
+
* // Installing eslint
|
|
913
|
+
* ```
|
|
504
914
|
*/
|
|
505
915
|
substep(msg, ...extras) {
|
|
506
916
|
const indentedMsg = ` ${msg}`;
|
|
507
917
|
return this.log(indentedMsg, ...extras);
|
|
508
918
|
}
|
|
509
919
|
/**
|
|
510
|
-
*
|
|
920
|
+
* Logs a success message with a green colored success symbol.
|
|
921
|
+
*
|
|
922
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.success` (green ✔).
|
|
923
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
924
|
+
* symbol, it will be stripped and replaced.
|
|
925
|
+
*
|
|
926
|
+
* @param args - Message and additional arguments to log
|
|
927
|
+
* @returns The logger instance for chaining
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```typescript
|
|
931
|
+
* logger.success('Build completed')
|
|
932
|
+
* logger.success('Tests passed:', { total: 42, passed: 42 })
|
|
933
|
+
* logger.success('Deployment successful')
|
|
934
|
+
* ```
|
|
511
935
|
*/
|
|
512
936
|
success(...args) {
|
|
513
937
|
return this.#symbolApply("success", args);
|
|
514
938
|
}
|
|
515
939
|
/**
|
|
516
|
-
*
|
|
517
|
-
*
|
|
940
|
+
* Logs a completion message with a success symbol (alias for `success()`).
|
|
941
|
+
*
|
|
942
|
+
* Provides semantic clarity when marking something as "done". Does NOT
|
|
943
|
+
* automatically clear the current line - call `clearLine()` first if
|
|
944
|
+
* needed after using `progress()`.
|
|
945
|
+
*
|
|
946
|
+
* @param args - Message and additional arguments to log
|
|
947
|
+
* @returns The logger instance for chaining
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```typescript
|
|
951
|
+
* logger.done('Task completed')
|
|
952
|
+
*
|
|
953
|
+
* // After progress indicator
|
|
954
|
+
* logger.progress('Processing...')
|
|
955
|
+
* // ... do work ...
|
|
956
|
+
* logger.clearLine()
|
|
957
|
+
* logger.done('Processing complete')
|
|
958
|
+
* ```
|
|
518
959
|
*/
|
|
519
960
|
done(...args) {
|
|
520
961
|
return this.#symbolApply("success", args);
|
|
521
962
|
}
|
|
522
963
|
/**
|
|
523
|
-
*
|
|
964
|
+
* Displays data in a table format.
|
|
965
|
+
*
|
|
966
|
+
* Works like `console.table()`. Accepts arrays of objects or
|
|
967
|
+
* objects with nested objects. Optionally specify which properties
|
|
968
|
+
* to include in the table.
|
|
969
|
+
*
|
|
970
|
+
* @param tabularData - The data to display as a table
|
|
971
|
+
* @param properties - Optional array of property names to include
|
|
972
|
+
* @returns The logger instance for chaining
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```typescript
|
|
976
|
+
* // Array of objects
|
|
977
|
+
* logger.table([
|
|
978
|
+
* { name: 'Alice', age: 30 },
|
|
979
|
+
* { name: 'Bob', age: 25 }
|
|
980
|
+
* ])
|
|
981
|
+
*
|
|
982
|
+
* // Specify properties to show
|
|
983
|
+
* logger.table(users, ['name', 'email'])
|
|
984
|
+
*
|
|
985
|
+
* // Object with nested objects
|
|
986
|
+
* logger.table({
|
|
987
|
+
* user1: { name: 'Alice', age: 30 },
|
|
988
|
+
* user2: { name: 'Bob', age: 25 }
|
|
989
|
+
* })
|
|
990
|
+
* ```
|
|
524
991
|
*/
|
|
525
992
|
table(tabularData, properties) {
|
|
526
993
|
const con = privateConsole.get(this);
|
|
@@ -529,7 +996,27 @@ class Logger {
|
|
|
529
996
|
return this[incLogCallCountSymbol]();
|
|
530
997
|
}
|
|
531
998
|
/**
|
|
532
|
-
*
|
|
999
|
+
* Ends a timer and logs the elapsed time.
|
|
1000
|
+
*
|
|
1001
|
+
* Logs the duration since `console.time()` was called with the same
|
|
1002
|
+
* label. The timer is stopped and removed.
|
|
1003
|
+
*
|
|
1004
|
+
* @param label - Optional label for the timer
|
|
1005
|
+
* @default 'default'
|
|
1006
|
+
* @returns The logger instance for chaining
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* console.time('operation')
|
|
1011
|
+
* // ... do work ...
|
|
1012
|
+
* logger.timeEnd('operation')
|
|
1013
|
+
* // Logs: "operation: 123.456ms"
|
|
1014
|
+
*
|
|
1015
|
+
* console.time()
|
|
1016
|
+
* // ... do work ...
|
|
1017
|
+
* logger.timeEnd()
|
|
1018
|
+
* // Logs: "default: 123.456ms"
|
|
1019
|
+
* ```
|
|
533
1020
|
*/
|
|
534
1021
|
timeEnd(label) {
|
|
535
1022
|
const con = privateConsole.get(this);
|
|
@@ -538,7 +1025,28 @@ class Logger {
|
|
|
538
1025
|
return this[incLogCallCountSymbol]();
|
|
539
1026
|
}
|
|
540
1027
|
/**
|
|
541
|
-
*
|
|
1028
|
+
* Logs the current value of a timer without stopping it.
|
|
1029
|
+
*
|
|
1030
|
+
* Logs the duration since `console.time()` was called with the same
|
|
1031
|
+
* label, but keeps the timer running. Can include additional data
|
|
1032
|
+
* to log alongside the time.
|
|
1033
|
+
*
|
|
1034
|
+
* @param label - Optional label for the timer
|
|
1035
|
+
* @param data - Additional data to log with the time
|
|
1036
|
+
* @default 'default'
|
|
1037
|
+
* @returns The logger instance for chaining
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* console.time('process')
|
|
1042
|
+
* // ... partial work ...
|
|
1043
|
+
* logger.timeLog('process', 'Checkpoint 1')
|
|
1044
|
+
* // Logs: "process: 123.456ms Checkpoint 1"
|
|
1045
|
+
* // ... more work ...
|
|
1046
|
+
* logger.timeLog('process', 'Checkpoint 2')
|
|
1047
|
+
* // Logs: "process: 234.567ms Checkpoint 2"
|
|
1048
|
+
* console.timeEnd('process')
|
|
1049
|
+
* ```
|
|
542
1050
|
*/
|
|
543
1051
|
timeLog(label, ...data) {
|
|
544
1052
|
const con = privateConsole.get(this);
|
|
@@ -547,7 +1055,24 @@ class Logger {
|
|
|
547
1055
|
return this[incLogCallCountSymbol]();
|
|
548
1056
|
}
|
|
549
1057
|
/**
|
|
550
|
-
*
|
|
1058
|
+
* Logs a stack trace to the console.
|
|
1059
|
+
*
|
|
1060
|
+
* Works like `console.trace()`. Shows the call stack leading to
|
|
1061
|
+
* where this method was called. Useful for debugging.
|
|
1062
|
+
*
|
|
1063
|
+
* @param message - Optional message to display with the trace
|
|
1064
|
+
* @param args - Additional arguments to log
|
|
1065
|
+
* @returns The logger instance for chaining
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* function debugFunction() {
|
|
1070
|
+
* logger.trace('Debug point reached')
|
|
1071
|
+
* }
|
|
1072
|
+
*
|
|
1073
|
+
* logger.trace('Trace from here')
|
|
1074
|
+
* logger.trace('Error context:', { userId: 123 })
|
|
1075
|
+
* ```
|
|
551
1076
|
*/
|
|
552
1077
|
trace(message, ...args) {
|
|
553
1078
|
const con = privateConsole.get(this);
|
|
@@ -556,13 +1081,45 @@ class Logger {
|
|
|
556
1081
|
return this[incLogCallCountSymbol]();
|
|
557
1082
|
}
|
|
558
1083
|
/**
|
|
559
|
-
*
|
|
1084
|
+
* Logs a warning message with a yellow colored warning symbol.
|
|
1085
|
+
*
|
|
1086
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.warn` (yellow ⚠).
|
|
1087
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
1088
|
+
* symbol, it will be stripped and replaced.
|
|
1089
|
+
*
|
|
1090
|
+
* @param args - Message and additional arguments to log
|
|
1091
|
+
* @returns The logger instance for chaining
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```typescript
|
|
1095
|
+
* logger.warn('Deprecated API used')
|
|
1096
|
+
* logger.warn('Low memory:', { available: '100MB' })
|
|
1097
|
+
* logger.warn('Missing optional configuration')
|
|
1098
|
+
* ```
|
|
560
1099
|
*/
|
|
561
1100
|
warn(...args) {
|
|
562
1101
|
return this.#symbolApply("warn", args);
|
|
563
1102
|
}
|
|
564
1103
|
/**
|
|
565
|
-
*
|
|
1104
|
+
* Writes text directly to stdout without a newline or indentation.
|
|
1105
|
+
*
|
|
1106
|
+
* Useful for progress indicators or custom formatting where you need
|
|
1107
|
+
* low-level control. Does not apply any indentation or formatting.
|
|
1108
|
+
*
|
|
1109
|
+
* @param text - The text to write
|
|
1110
|
+
* @returns The logger instance for chaining
|
|
1111
|
+
*
|
|
1112
|
+
* @example
|
|
1113
|
+
* ```typescript
|
|
1114
|
+
* logger.write('Processing... ')
|
|
1115
|
+
* // ... do work ...
|
|
1116
|
+
* logger.write('done\n')
|
|
1117
|
+
*
|
|
1118
|
+
* // Build a line incrementally
|
|
1119
|
+
* logger.write('Step 1')
|
|
1120
|
+
* logger.write('... Step 2')
|
|
1121
|
+
* logger.write('... Step 3\n')
|
|
1122
|
+
* ```
|
|
566
1123
|
*/
|
|
567
1124
|
write(text) {
|
|
568
1125
|
const con = privateConsole.get(this);
|
|
@@ -571,8 +1128,29 @@ class Logger {
|
|
|
571
1128
|
return this;
|
|
572
1129
|
}
|
|
573
1130
|
/**
|
|
574
|
-
*
|
|
575
|
-
*
|
|
1131
|
+
* Shows a progress indicator that can be cleared with `clearLine()`.
|
|
1132
|
+
*
|
|
1133
|
+
* Displays a simple status message with a '∴' prefix. Does not include
|
|
1134
|
+
* animation or spinner. Intended to be cleared once the operation completes.
|
|
1135
|
+
* The output stream (stderr or stdout) depends on whether the logger is
|
|
1136
|
+
* stream-bound.
|
|
1137
|
+
*
|
|
1138
|
+
* @param text - The progress message to display
|
|
1139
|
+
* @returns The logger instance for chaining
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```typescript
|
|
1143
|
+
* logger.progress('Processing files...')
|
|
1144
|
+
* // ... do work ...
|
|
1145
|
+
* logger.clearLine()
|
|
1146
|
+
* logger.success('Files processed')
|
|
1147
|
+
*
|
|
1148
|
+
* // Stream-specific progress
|
|
1149
|
+
* logger.stdout.progress('Loading...')
|
|
1150
|
+
* // ... do work ...
|
|
1151
|
+
* logger.stdout.clearLine()
|
|
1152
|
+
* logger.stdout.log('Done')
|
|
1153
|
+
* ```
|
|
576
1154
|
*/
|
|
577
1155
|
progress(text) {
|
|
578
1156
|
const con = privateConsole.get(this);
|
|
@@ -583,7 +1161,32 @@ class Logger {
|
|
|
583
1161
|
return this;
|
|
584
1162
|
}
|
|
585
1163
|
/**
|
|
586
|
-
*
|
|
1164
|
+
* Clears the current line in the terminal.
|
|
1165
|
+
*
|
|
1166
|
+
* Moves the cursor to the beginning of the line and clears all content.
|
|
1167
|
+
* Works in both TTY and non-TTY environments. Useful for clearing
|
|
1168
|
+
* progress indicators created with `progress()`.
|
|
1169
|
+
*
|
|
1170
|
+
* The stream to clear (stderr or stdout) depends on whether the logger
|
|
1171
|
+
* is stream-bound.
|
|
1172
|
+
*
|
|
1173
|
+
* @returns The logger instance for chaining
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```typescript
|
|
1177
|
+
* logger.progress('Loading...')
|
|
1178
|
+
* // ... do work ...
|
|
1179
|
+
* logger.clearLine()
|
|
1180
|
+
* logger.success('Loaded')
|
|
1181
|
+
*
|
|
1182
|
+
* // Clear multiple progress updates
|
|
1183
|
+
* for (const file of files) {
|
|
1184
|
+
* logger.progress(`Processing ${file}`)
|
|
1185
|
+
* processFile(file)
|
|
1186
|
+
* logger.clearLine()
|
|
1187
|
+
* }
|
|
1188
|
+
* logger.success('All files processed')
|
|
1189
|
+
* ```
|
|
587
1190
|
*/
|
|
588
1191
|
clearLine() {
|
|
589
1192
|
const con = privateConsole.get(this);
|