@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
package/dist/logger.d.ts CHANGED
@@ -1,183 +1,936 @@
1
- // Type definitions
1
+ /**
2
+ * Log symbols for terminal output with colored indicators.
3
+ *
4
+ * Each symbol provides visual feedback for different message types, with
5
+ * Unicode and ASCII fallback support.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { LOG_SYMBOLS } from '@socketsecurity/lib'
10
+ *
11
+ * console.log(`${LOG_SYMBOLS.success} Operation completed`)
12
+ * console.log(`${LOG_SYMBOLS.fail} Operation failed`)
13
+ * console.log(`${LOG_SYMBOLS.warn} Warning message`)
14
+ * console.log(`${LOG_SYMBOLS.info} Information message`)
15
+ * ```
16
+ */
2
17
  type LogSymbols = {
18
+ /** Red colored failure symbol (✖ or × in ASCII) */
3
19
  fail: string;
20
+ /** Blue colored information symbol (ℹ or i in ASCII) */
4
21
  info: string;
22
+ /** Green colored success symbol (✔ or √ in ASCII) */
5
23
  success: string;
24
+ /** Yellow colored warning symbol (⚠ or ‼ in ASCII) */
6
25
  warn: string;
7
26
  };
27
+ /**
28
+ * Type definition for logger methods that mirror console methods.
29
+ *
30
+ * All methods return the logger instance for method chaining.
31
+ */
8
32
  type LoggerMethods = {
9
- [K in keyof typeof console]: (typeof console)[K] extends (...args: infer A
10
- // biome-ignore lint/suspicious/noExplicitAny: Console method return types are dynamic.
11
- ) => any ? (...args: A) => Logger : (typeof console)[K];
33
+ [K in keyof typeof console]: (typeof console)[K] extends (...args: infer A) => any ? (...args: A) => Logger : (typeof console)[K];
12
34
  };
35
+ /**
36
+ * A task that can be executed with automatic start/complete logging.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const task = logger.createTask('Database migration')
41
+ * task.run(() => {
42
+ * // Migration logic here
43
+ * })
44
+ * // Logs: "Starting task: Database migration"
45
+ * // Logs: "Completed task: Database migration"
46
+ * ```
47
+ */
13
48
  interface Task {
49
+ /**
50
+ * Executes the task function with automatic logging.
51
+ *
52
+ * @template T - The return type of the task function
53
+ * @param f - The function to execute
54
+ * @returns The result of the task function
55
+ */
14
56
  run<T>(f: () => T): T;
15
57
  }
16
58
  export type { LogSymbols, LoggerMethods, Task };
59
+ /**
60
+ * Log symbols for terminal output with colored indicators.
61
+ *
62
+ * Provides colored Unicode symbols (✔, ✖, ⚠, ℹ) with ASCII fallbacks (√, ×, ‼, i)
63
+ * for terminals that don't support Unicode. Symbols are color-coded: green for
64
+ * success, red for failure, yellow for warnings, blue for info.
65
+ *
66
+ * The symbols are lazily initialized on first access and then frozen for immutability.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { LOG_SYMBOLS } from '@socketsecurity/lib'
71
+ *
72
+ * console.log(`${LOG_SYMBOLS.success} Build completed`) // Green ✔
73
+ * console.log(`${LOG_SYMBOLS.fail} Build failed`) // Red ✖
74
+ * console.log(`${LOG_SYMBOLS.warn} Deprecated API used`) // Yellow ⚠
75
+ * console.log(`${LOG_SYMBOLS.info} Starting process`) // Blue ℹ
76
+ * ```
77
+ */
17
78
  export declare const LOG_SYMBOLS: Record<string, string>;
79
+ /**
80
+ * Symbol for incrementing the internal log call counter.
81
+ *
82
+ * This is an internal symbol used to track the number of times logging
83
+ * methods have been called on a logger instance.
84
+ */
18
85
  export declare const incLogCallCountSymbol: unique symbol;
86
+ /**
87
+ * Symbol for tracking whether the last logged line was blank.
88
+ *
89
+ * This is used internally to prevent multiple consecutive blank lines
90
+ * and to determine whether to add spacing before certain messages.
91
+ */
19
92
  export declare const lastWasBlankSymbol: unique symbol;
20
93
  /**
21
- * Custom Logger class that wraps console with additional features.
22
- * Supports indentation, symbols, and blank line tracking.
94
+ * Enhanced console logger with indentation, colored symbols, and stream management.
95
+ *
96
+ * Provides a fluent API for logging with automatic indentation tracking, colored
97
+ * status symbols, separate stderr/stdout management, and method chaining. All
98
+ * methods return `this` for easy chaining.
99
+ *
100
+ * Features:
101
+ * - Automatic line prefixing with indentation
102
+ * - Colored status symbols (success, fail, warn, info)
103
+ * - Separate indentation tracking for stderr and stdout
104
+ * - Stream-bound logger instances via `.stderr` and `.stdout`
105
+ * - Group/indentation management
106
+ * - Progress indicators with clearable lines
107
+ * - Task execution with automatic logging
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { logger } from '@socketsecurity/lib'
112
+ *
113
+ * // Basic logging with symbols
114
+ * logger.success('Build completed')
115
+ * logger.fail('Build failed')
116
+ * logger.warn('Deprecated API')
117
+ * logger.info('Starting process')
118
+ *
119
+ * // Indentation and grouping
120
+ * logger.log('Processing files:')
121
+ * logger.indent()
122
+ * logger.log('file1.js')
123
+ * logger.log('file2.js')
124
+ * logger.dedent()
125
+ *
126
+ * // Method chaining
127
+ * logger
128
+ * .log('Step 1')
129
+ * .indent()
130
+ * .log('Substep 1.1')
131
+ * .log('Substep 1.2')
132
+ * .dedent()
133
+ * .log('Step 2')
134
+ *
135
+ * // Stream-specific logging
136
+ * logger.stdout.log('Normal output')
137
+ * logger.stderr.error('Error message')
138
+ *
139
+ * // Progress indicators
140
+ * logger.progress('Processing...')
141
+ * // ... do work ...
142
+ * logger.clearLine()
143
+ * logger.success('Done')
144
+ *
145
+ * // Task execution
146
+ * const task = logger.createTask('Migration')
147
+ * task.run(() => {
148
+ * // Migration logic
149
+ * })
150
+ * ```
23
151
  */
24
152
  /*@__PURE__*/
25
153
  export declare class Logger {
26
154
  #private;
155
+ /**
156
+ * Static reference to log symbols for convenience.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * console.log(`${Logger.LOG_SYMBOLS.success} Done`)
161
+ * ```
162
+ */
27
163
  static LOG_SYMBOLS: Record<string, string>;
164
+ /**
165
+ * Creates a new Logger instance.
166
+ *
167
+ * When called without arguments, creates a logger using the default
168
+ * `process.stdout` and `process.stderr` streams. Can accept custom
169
+ * console constructor arguments for advanced use cases.
170
+ *
171
+ * @param args - Optional console constructor arguments
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Default logger
176
+ * const logger = new Logger()
177
+ *
178
+ * // Custom streams (advanced)
179
+ * const customLogger = new Logger({
180
+ * stdout: customWritableStream,
181
+ * stderr: customErrorStream
182
+ * })
183
+ * ```
184
+ */
28
185
  constructor(...args: unknown[]);
29
186
  /**
30
- * Get a logger instance bound to stderr.
31
- * All operations on this instance will use stderr.
187
+ * Gets a logger instance bound exclusively to stderr.
188
+ *
189
+ * All logging operations on this instance will write to stderr only.
190
+ * Indentation is tracked separately from stdout. The instance is
191
+ * cached and reused on subsequent accesses.
192
+ *
193
+ * @returns A logger instance bound to stderr
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * // Write errors to stderr
198
+ * logger.stderr.error('Configuration invalid')
199
+ * logger.stderr.warn('Using fallback settings')
200
+ *
201
+ * // Indent only affects stderr
202
+ * logger.stderr.indent()
203
+ * logger.stderr.error('Nested error details')
204
+ * logger.stderr.dedent()
205
+ * ```
32
206
  */
33
207
  get stderr(): Logger;
34
208
  /**
35
- * Get a logger instance bound to stdout.
36
- * All operations on this instance will use stdout.
209
+ * Gets a logger instance bound exclusively to stdout.
210
+ *
211
+ * All logging operations on this instance will write to stdout only.
212
+ * Indentation is tracked separately from stderr. The instance is
213
+ * cached and reused on subsequent accesses.
214
+ *
215
+ * @returns A logger instance bound to stdout
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * // Write normal output to stdout
220
+ * logger.stdout.log('Processing started')
221
+ * logger.stdout.log('Items processed: 42')
222
+ *
223
+ * // Indent only affects stdout
224
+ * logger.stdout.indent()
225
+ * logger.stdout.log('Detailed output')
226
+ * logger.stdout.dedent()
227
+ * ```
37
228
  */
38
229
  get stdout(): Logger;
39
230
  /**
40
- * Get the current log call count.
231
+ * Gets the total number of log calls made on this logger instance.
232
+ *
233
+ * Tracks all logging method calls including `log()`, `error()`, `warn()`,
234
+ * `success()`, `fail()`, etc. Useful for testing and monitoring logging activity.
235
+ *
236
+ * @returns The number of times logging methods have been called
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * logger.log('Message 1')
241
+ * logger.error('Message 2')
242
+ * console.log(logger.logCallCount) // 2
243
+ * ```
41
244
  */
42
245
  get logCallCount(): number;
43
246
  /**
44
- * Increment the log call count.
247
+ * Increments the internal log call counter.
248
+ *
249
+ * This is called automatically by logging methods and should not
250
+ * be called directly in normal usage.
251
+ *
252
+ * @returns The logger instance for chaining
45
253
  */
46
254
  [incLogCallCountSymbol](): this;
47
255
  /**
48
- * Set whether the last logged line was blank.
256
+ * Sets whether the last logged line was blank.
257
+ *
258
+ * Used internally to track blank lines and prevent duplicate spacing.
259
+ * This is called automatically by logging methods.
260
+ *
261
+ * @param value - Whether the last line was blank
262
+ * @returns The logger instance for chaining
49
263
  */
50
264
  [lastWasBlankSymbol](value: unknown): this;
51
265
  /**
52
- * Log an assertion.
266
+ * Logs an assertion failure message if the value is falsy.
267
+ *
268
+ * Works like `console.assert()` but returns the logger for chaining.
269
+ * If the value is truthy, nothing is logged. If falsy, logs an error
270
+ * message with an assertion failure.
271
+ *
272
+ * @param value - The value to test
273
+ * @param message - Optional message and additional arguments to log
274
+ * @returns The logger instance for chaining
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * logger.assert(true, 'This will not log')
279
+ * logger.assert(false, 'Assertion failed: value is false')
280
+ * logger.assert(items.length > 0, 'No items found')
281
+ * ```
53
282
  */
54
283
  assert(value: unknown, ...message: unknown[]): this;
55
284
  /**
56
- * Clear the visible terminal screen.
57
- * Only available on the main logger instance.
285
+ * Clears the visible terminal screen.
286
+ *
287
+ * Only available on the main logger instance, not on stream-bound instances
288
+ * (`.stderr` or `.stdout`). Resets the log call count and blank line tracking
289
+ * if the output is a TTY.
290
+ *
291
+ * @returns The logger instance for chaining
292
+ * @throws {Error} If called on a stream-bound logger instance
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * logger.log('Some output')
297
+ * logger.clearVisible() // Screen is now clear
298
+ *
299
+ * // Error: Can't call on stream-bound instance
300
+ * logger.stderr.clearVisible() // throws
301
+ * ```
58
302
  */
59
303
  clearVisible(): this;
60
304
  /**
61
- * Log a count for the given label.
62
- */
63
- count(label?: string): this;
64
- /**
65
- * Create a task with a given name.
305
+ * Increments and logs a counter for the given label.
306
+ *
307
+ * Each unique label maintains its own counter. Works like `console.count()`.
308
+ *
309
+ * @param label - Optional label for the counter
310
+ * @default 'default'
311
+ * @returns The logger instance for chaining
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * logger.count('requests') // requests: 1
316
+ * logger.count('requests') // requests: 2
317
+ * logger.count('errors') // errors: 1
318
+ * logger.count() // default: 1
319
+ * ```
320
+ */
321
+ count(label?: string | undefined): this;
322
+ /**
323
+ * Creates a task that logs start and completion messages automatically.
324
+ *
325
+ * Returns a task object with a `run()` method that executes the provided
326
+ * function and logs "Starting task: {name}" before execution and
327
+ * "Completed task: {name}" after completion.
328
+ *
329
+ * @param name - The name of the task
330
+ * @returns A task object with a `run()` method
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * const task = logger.createTask('Database Migration')
335
+ * const result = task.run(() => {
336
+ * // Logs: "Starting task: Database Migration"
337
+ * migrateDatabase()
338
+ * return 'success'
339
+ * // Logs: "Completed task: Database Migration"
340
+ * })
341
+ * console.log(result) // 'success'
342
+ * ```
66
343
  */
67
344
  createTask(name: string): Task;
68
345
  /**
69
- * Decrease indentation level.
70
- * If called on main logger, affects both streams.
71
- * If called on stream-bound logger, affects only that stream.
346
+ * Decreases the indentation level by removing spaces from the prefix.
347
+ *
348
+ * When called on the main logger, affects both stderr and stdout indentation.
349
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), affects
350
+ * only that stream's indentation.
351
+ *
352
+ * @param spaces - Number of spaces to remove from indentation
353
+ * @default 2
354
+ * @returns The logger instance for chaining
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * logger.indent()
359
+ * logger.log('Indented')
360
+ * logger.dedent()
361
+ * logger.log('Back to normal')
362
+ *
363
+ * // Remove custom amount
364
+ * logger.indent(4)
365
+ * logger.log('Four spaces')
366
+ * logger.dedent(4)
367
+ *
368
+ * // Stream-specific dedent
369
+ * logger.stdout.indent()
370
+ * logger.stdout.log('Indented stdout')
371
+ * logger.stdout.dedent()
372
+ * ```
72
373
  */
73
374
  dedent(spaces?: number): this;
74
375
  /**
75
- * Display an object's properties.
76
- */
77
- dir(obj: unknown, options?: unknown): this;
78
- /**
79
- * Display data as XML.
376
+ * Displays an object's properties in a formatted way.
377
+ *
378
+ * Works like `console.dir()` with customizable options for depth,
379
+ * colors, etc. Useful for inspecting complex objects.
380
+ *
381
+ * @param obj - The object to display
382
+ * @param options - Optional formatting options (Node.js inspect options)
383
+ * @returns The logger instance for chaining
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * const obj = { a: 1, b: { c: 2, d: { e: 3 } } }
388
+ * logger.dir(obj)
389
+ * logger.dir(obj, { depth: 1 }) // Limit nesting depth
390
+ * logger.dir(obj, { colors: true }) // Enable colors
391
+ * ```
392
+ */
393
+ dir(obj: unknown, options?: unknown | undefined): this;
394
+ /**
395
+ * Displays data as XML/HTML in a formatted way.
396
+ *
397
+ * Works like `console.dirxml()`. In Node.js, behaves the same as `dir()`.
398
+ *
399
+ * @param data - The data to display
400
+ * @returns The logger instance for chaining
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * logger.dirxml(document.body) // In browser environments
405
+ * logger.dirxml(xmlObject) // In Node.js
406
+ * ```
80
407
  */
81
408
  dirxml(...data: unknown[]): this;
82
409
  /**
83
- * Log an error message.
410
+ * Logs an error message to stderr.
411
+ *
412
+ * Automatically applies current indentation. All arguments are formatted
413
+ * and logged like `console.error()`.
414
+ *
415
+ * @param args - Message and additional arguments to log
416
+ * @returns The logger instance for chaining
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * logger.error('Build failed')
421
+ * logger.error('Error code:', 500)
422
+ * logger.error('Details:', { message: 'Not found' })
423
+ * ```
84
424
  */
85
425
  error(...args: unknown[]): this;
86
426
  /**
87
- * Log a newline to stderr if last line wasn't blank.
427
+ * Logs a newline to stderr only if the last line wasn't already blank.
428
+ *
429
+ * Prevents multiple consecutive blank lines. Useful for adding spacing
430
+ * between sections without creating excessive whitespace.
431
+ *
432
+ * @returns The logger instance for chaining
433
+ *
434
+ * @example
435
+ * ```typescript
436
+ * logger.error('Error message')
437
+ * logger.errorNewline() // Adds blank line
438
+ * logger.errorNewline() // Does nothing (already blank)
439
+ * logger.error('Next section')
440
+ * ```
88
441
  */
89
442
  errorNewline(): this;
90
443
  /**
91
- * Log a failure message with symbol.
444
+ * Logs a failure message with a red colored fail symbol.
445
+ *
446
+ * Automatically prefixes the message with `LOG_SYMBOLS.fail` (red ✖).
447
+ * Always outputs to stderr. If the message starts with an existing
448
+ * symbol, it will be stripped and replaced.
449
+ *
450
+ * @param args - Message and additional arguments to log
451
+ * @returns The logger instance for chaining
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * logger.fail('Build failed')
456
+ * logger.fail('Test suite failed:', { passed: 5, failed: 3 })
457
+ * ```
92
458
  */
93
459
  fail(...args: unknown[]): this;
94
460
  /**
95
- * Start a new log group.
461
+ * Starts a new indented log group.
462
+ *
463
+ * If a label is provided, it's logged before increasing indentation.
464
+ * Groups can be nested. Each group increases indentation by the
465
+ * `kGroupIndentWidth` (default 2 spaces). Call `groupEnd()` to close.
466
+ *
467
+ * @param label - Optional label to display before the group
468
+ * @returns The logger instance for chaining
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * logger.group('Processing files:')
473
+ * logger.log('file1.js')
474
+ * logger.log('file2.js')
475
+ * logger.groupEnd()
476
+ *
477
+ * // Nested groups
478
+ * logger.group('Outer')
479
+ * logger.log('Outer content')
480
+ * logger.group('Inner')
481
+ * logger.log('Inner content')
482
+ * logger.groupEnd()
483
+ * logger.groupEnd()
484
+ * ```
96
485
  */
97
486
  group(...label: unknown[]): this;
98
487
  /**
99
- * Start a new collapsed log group (alias for group).
488
+ * Starts a new collapsed log group (alias for `group()`).
489
+ *
490
+ * In browser consoles, this creates a collapsed group. In Node.js,
491
+ * it behaves identically to `group()`.
492
+ *
493
+ * @param label - Optional label to display before the group
494
+ * @returns The logger instance for chaining
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * logger.groupCollapsed('Details')
499
+ * logger.log('Hidden by default in browsers')
500
+ * logger.groupEnd()
501
+ * ```
100
502
  */
101
503
  // groupCollapsed is an alias of group.
102
504
  // https://nodejs.org/api/console.html#consolegroupcollapsed
103
505
  groupCollapsed(...label: unknown[]): this;
104
506
  /**
105
- * End the current log group.
507
+ * Ends the current log group and decreases indentation.
508
+ *
509
+ * Must be called once for each `group()` or `groupCollapsed()` call
510
+ * to properly close the group and restore indentation.
511
+ *
512
+ * @returns The logger instance for chaining
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * logger.group('Group 1')
517
+ * logger.log('Content')
518
+ * logger.groupEnd() // Closes 'Group 1'
519
+ * ```
106
520
  */
107
521
  groupEnd(): this;
108
522
  /**
109
- * Increase indentation level.
110
- * If called on main logger, affects both streams.
111
- * If called on stream-bound logger, affects only that stream.
523
+ * Increases the indentation level by adding spaces to the prefix.
524
+ *
525
+ * When called on the main logger, affects both stderr and stdout indentation.
526
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), affects
527
+ * only that stream's indentation. Maximum indentation is 1000 spaces.
528
+ *
529
+ * @param spaces - Number of spaces to add to indentation
530
+ * @default 2
531
+ * @returns The logger instance for chaining
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * logger.log('Level 0')
536
+ * logger.indent()
537
+ * logger.log('Level 1')
538
+ * logger.indent()
539
+ * logger.log('Level 2')
540
+ * logger.dedent()
541
+ * logger.dedent()
542
+ *
543
+ * // Custom indent amount
544
+ * logger.indent(4)
545
+ * logger.log('Indented 4 spaces')
546
+ * logger.dedent(4)
547
+ *
548
+ * // Stream-specific indent
549
+ * logger.stdout.indent()
550
+ * logger.stdout.log('Only stdout is indented')
551
+ * ```
112
552
  */
113
553
  indent(spaces?: number): this;
114
554
  /**
115
- * Log an info message with symbol.
555
+ * Logs an informational message with a blue colored info symbol.
556
+ *
557
+ * Automatically prefixes the message with `LOG_SYMBOLS.info` (blue ℹ).
558
+ * Always outputs to stderr. If the message starts with an existing
559
+ * symbol, it will be stripped and replaced.
560
+ *
561
+ * @param args - Message and additional arguments to log
562
+ * @returns The logger instance for chaining
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * logger.info('Starting build process')
567
+ * logger.info('Configuration loaded:', config)
568
+ * logger.info('Using cache directory:', cacheDir)
569
+ * ```
116
570
  */
117
571
  info(...args: unknown[]): this;
118
572
  /**
119
- * Log a message.
573
+ * Logs a message to stdout.
574
+ *
575
+ * Automatically applies current indentation. All arguments are formatted
576
+ * and logged like `console.log()`. This is the primary method for
577
+ * standard output.
578
+ *
579
+ * @param args - Message and additional arguments to log
580
+ * @returns The logger instance for chaining
581
+ *
582
+ * @example
583
+ * ```typescript
584
+ * logger.log('Processing complete')
585
+ * logger.log('Items processed:', 42)
586
+ * logger.log('Results:', { success: true, count: 10 })
587
+ *
588
+ * // Method chaining
589
+ * logger.log('Step 1').log('Step 2').log('Step 3')
590
+ * ```
120
591
  */
121
592
  log(...args: unknown[]): this;
122
593
  /**
123
- * Log a newline to stdout if last line wasn't blank.
594
+ * Logs a newline to stdout only if the last line wasn't already blank.
595
+ *
596
+ * Prevents multiple consecutive blank lines. Useful for adding spacing
597
+ * between sections without creating excessive whitespace.
598
+ *
599
+ * @returns The logger instance for chaining
600
+ *
601
+ * @example
602
+ * ```typescript
603
+ * logger.log('Section 1')
604
+ * logger.logNewline() // Adds blank line
605
+ * logger.logNewline() // Does nothing (already blank)
606
+ * logger.log('Section 2')
607
+ * ```
124
608
  */
125
609
  logNewline(): this;
126
610
  /**
127
- * Reset indentation to zero.
128
- * If called on main logger, resets both streams.
129
- * If called on stream-bound logger, resets only that stream.
611
+ * Resets all indentation to zero.
612
+ *
613
+ * When called on the main logger, resets both stderr and stdout indentation.
614
+ * When called on a stream-bound logger (`.stderr` or `.stdout`), resets
615
+ * only that stream's indentation.
616
+ *
617
+ * @returns The logger instance for chaining
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * logger.indent().indent().indent()
622
+ * logger.log('Very indented')
623
+ * logger.resetIndent()
624
+ * logger.log('Back to zero indentation')
625
+ *
626
+ * // Reset only stdout
627
+ * logger.stdout.resetIndent()
628
+ * ```
130
629
  */
131
630
  resetIndent(): this;
132
631
  /**
133
- * Log a main step with blank line before (stateless).
632
+ * Logs a main step message with a blank line before it (stateless).
633
+ *
634
+ * Automatically adds a blank line before the message unless the last
635
+ * line was already blank. Useful for marking major steps in a process
636
+ * with clear visual separation.
637
+ *
638
+ * @param msg - The step message to log
639
+ * @param extras - Additional arguments to log
640
+ * @returns The logger instance for chaining
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * logger.step('Building project')
645
+ * logger.log('Compiling TypeScript...')
646
+ * logger.step('Running tests')
647
+ * logger.log('Running test suite...')
648
+ * // Output:
649
+ * // [blank line]
650
+ * // Building project
651
+ * // Compiling TypeScript...
652
+ * // [blank line]
653
+ * // Running tests
654
+ * // Running test suite...
655
+ * ```
134
656
  */
135
657
  step(msg: string, ...extras: unknown[]): this;
136
658
  /**
137
- * Log an indented substep (stateless).
659
+ * Logs an indented substep message (stateless).
660
+ *
661
+ * Adds a 2-space indent to the message without affecting the logger's
662
+ * indentation state. Useful for showing sub-items under a main step.
663
+ *
664
+ * @param msg - The substep message to log
665
+ * @param extras - Additional arguments to log
666
+ * @returns The logger instance for chaining
667
+ *
668
+ * @example
669
+ * ```typescript
670
+ * logger.log('Installing dependencies:')
671
+ * logger.substep('Installing react')
672
+ * logger.substep('Installing typescript')
673
+ * logger.substep('Installing eslint')
674
+ * // Output:
675
+ * // Installing dependencies:
676
+ * // Installing react
677
+ * // Installing typescript
678
+ * // Installing eslint
679
+ * ```
138
680
  */
139
681
  substep(msg: string, ...extras: unknown[]): this;
140
682
  /**
141
- * Log a success message with symbol.
683
+ * Logs a success message with a green colored success symbol.
684
+ *
685
+ * Automatically prefixes the message with `LOG_SYMBOLS.success` (green ✔).
686
+ * Always outputs to stderr. If the message starts with an existing
687
+ * symbol, it will be stripped and replaced.
688
+ *
689
+ * @param args - Message and additional arguments to log
690
+ * @returns The logger instance for chaining
691
+ *
692
+ * @example
693
+ * ```typescript
694
+ * logger.success('Build completed')
695
+ * logger.success('Tests passed:', { total: 42, passed: 42 })
696
+ * logger.success('Deployment successful')
697
+ * ```
142
698
  */
143
699
  success(...args: unknown[]): this;
144
700
  /**
145
- * Log a done message (alias for success).
146
- * Does NOT auto-clear. Call clearLine() first if needed after progress().
701
+ * Logs a completion message with a success symbol (alias for `success()`).
702
+ *
703
+ * Provides semantic clarity when marking something as "done". Does NOT
704
+ * automatically clear the current line - call `clearLine()` first if
705
+ * needed after using `progress()`.
706
+ *
707
+ * @param args - Message and additional arguments to log
708
+ * @returns The logger instance for chaining
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * logger.done('Task completed')
713
+ *
714
+ * // After progress indicator
715
+ * logger.progress('Processing...')
716
+ * // ... do work ...
717
+ * logger.clearLine()
718
+ * logger.done('Processing complete')
719
+ * ```
147
720
  */
148
721
  done(...args: unknown[]): this;
149
722
  /**
150
- * Display data in a table format.
151
- */
152
- table(tabularData: unknown, properties?: readonly string[]): this;
153
- /**
154
- * End a timer and log the elapsed time.
155
- */
156
- timeEnd(label?: string): this;
157
- /**
158
- * Log the current timer value.
159
- */
160
- timeLog(label?: string, ...data: unknown[]): this;
161
- /**
162
- * Log a stack trace.
163
- */
164
- trace(message?: unknown, ...args: unknown[]): this;
165
- /**
166
- * Log a warning message with symbol.
723
+ * Displays data in a table format.
724
+ *
725
+ * Works like `console.table()`. Accepts arrays of objects or
726
+ * objects with nested objects. Optionally specify which properties
727
+ * to include in the table.
728
+ *
729
+ * @param tabularData - The data to display as a table
730
+ * @param properties - Optional array of property names to include
731
+ * @returns The logger instance for chaining
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * // Array of objects
736
+ * logger.table([
737
+ * { name: 'Alice', age: 30 },
738
+ * { name: 'Bob', age: 25 }
739
+ * ])
740
+ *
741
+ * // Specify properties to show
742
+ * logger.table(users, ['name', 'email'])
743
+ *
744
+ * // Object with nested objects
745
+ * logger.table({
746
+ * user1: { name: 'Alice', age: 30 },
747
+ * user2: { name: 'Bob', age: 25 }
748
+ * })
749
+ * ```
750
+ */
751
+ table(tabularData: unknown, properties?: readonly string[] | undefined): this;
752
+ /**
753
+ * Ends a timer and logs the elapsed time.
754
+ *
755
+ * Logs the duration since `console.time()` was called with the same
756
+ * label. The timer is stopped and removed.
757
+ *
758
+ * @param label - Optional label for the timer
759
+ * @default 'default'
760
+ * @returns The logger instance for chaining
761
+ *
762
+ * @example
763
+ * ```typescript
764
+ * console.time('operation')
765
+ * // ... do work ...
766
+ * logger.timeEnd('operation')
767
+ * // Logs: "operation: 123.456ms"
768
+ *
769
+ * console.time()
770
+ * // ... do work ...
771
+ * logger.timeEnd()
772
+ * // Logs: "default: 123.456ms"
773
+ * ```
774
+ */
775
+ timeEnd(label?: string | undefined): this;
776
+ /**
777
+ * Logs the current value of a timer without stopping it.
778
+ *
779
+ * Logs the duration since `console.time()` was called with the same
780
+ * label, but keeps the timer running. Can include additional data
781
+ * to log alongside the time.
782
+ *
783
+ * @param label - Optional label for the timer
784
+ * @param data - Additional data to log with the time
785
+ * @default 'default'
786
+ * @returns The logger instance for chaining
787
+ *
788
+ * @example
789
+ * ```typescript
790
+ * console.time('process')
791
+ * // ... partial work ...
792
+ * logger.timeLog('process', 'Checkpoint 1')
793
+ * // Logs: "process: 123.456ms Checkpoint 1"
794
+ * // ... more work ...
795
+ * logger.timeLog('process', 'Checkpoint 2')
796
+ * // Logs: "process: 234.567ms Checkpoint 2"
797
+ * console.timeEnd('process')
798
+ * ```
799
+ */
800
+ timeLog(label?: string | undefined, ...data: unknown[]): this;
801
+ /**
802
+ * Logs a stack trace to the console.
803
+ *
804
+ * Works like `console.trace()`. Shows the call stack leading to
805
+ * where this method was called. Useful for debugging.
806
+ *
807
+ * @param message - Optional message to display with the trace
808
+ * @param args - Additional arguments to log
809
+ * @returns The logger instance for chaining
810
+ *
811
+ * @example
812
+ * ```typescript
813
+ * function debugFunction() {
814
+ * logger.trace('Debug point reached')
815
+ * }
816
+ *
817
+ * logger.trace('Trace from here')
818
+ * logger.trace('Error context:', { userId: 123 })
819
+ * ```
820
+ */
821
+ trace(message?: unknown | undefined, ...args: unknown[]): this;
822
+ /**
823
+ * Logs a warning message with a yellow colored warning symbol.
824
+ *
825
+ * Automatically prefixes the message with `LOG_SYMBOLS.warn` (yellow ⚠).
826
+ * Always outputs to stderr. If the message starts with an existing
827
+ * symbol, it will be stripped and replaced.
828
+ *
829
+ * @param args - Message and additional arguments to log
830
+ * @returns The logger instance for chaining
831
+ *
832
+ * @example
833
+ * ```typescript
834
+ * logger.warn('Deprecated API used')
835
+ * logger.warn('Low memory:', { available: '100MB' })
836
+ * logger.warn('Missing optional configuration')
837
+ * ```
167
838
  */
168
839
  warn(...args: unknown[]): this;
169
840
  /**
170
- * Write to stdout without a newline or indentation.
841
+ * Writes text directly to stdout without a newline or indentation.
842
+ *
843
+ * Useful for progress indicators or custom formatting where you need
844
+ * low-level control. Does not apply any indentation or formatting.
845
+ *
846
+ * @param text - The text to write
847
+ * @returns The logger instance for chaining
848
+ *
849
+ * @example
850
+ * ```typescript
851
+ * logger.write('Processing... ')
852
+ * // ... do work ...
853
+ * logger.write('done\n')
854
+ *
855
+ * // Build a line incrementally
856
+ * logger.write('Step 1')
857
+ * logger.write('... Step 2')
858
+ * logger.write('... Step 3\n')
859
+ * ```
171
860
  */
172
861
  write(text: string): this;
173
862
  /**
174
- * Show a progress indicator (can be cleared with clearLine).
175
- * Simple status message without spinner animation.
863
+ * Shows a progress indicator that can be cleared with `clearLine()`.
864
+ *
865
+ * Displays a simple status message with a '∴' prefix. Does not include
866
+ * animation or spinner. Intended to be cleared once the operation completes.
867
+ * The output stream (stderr or stdout) depends on whether the logger is
868
+ * stream-bound.
869
+ *
870
+ * @param text - The progress message to display
871
+ * @returns The logger instance for chaining
872
+ *
873
+ * @example
874
+ * ```typescript
875
+ * logger.progress('Processing files...')
876
+ * // ... do work ...
877
+ * logger.clearLine()
878
+ * logger.success('Files processed')
879
+ *
880
+ * // Stream-specific progress
881
+ * logger.stdout.progress('Loading...')
882
+ * // ... do work ...
883
+ * logger.stdout.clearLine()
884
+ * logger.stdout.log('Done')
885
+ * ```
176
886
  */
177
887
  progress(text: string): this;
178
888
  /**
179
- * Clear the current line.
889
+ * Clears the current line in the terminal.
890
+ *
891
+ * Moves the cursor to the beginning of the line and clears all content.
892
+ * Works in both TTY and non-TTY environments. Useful for clearing
893
+ * progress indicators created with `progress()`.
894
+ *
895
+ * The stream to clear (stderr or stdout) depends on whether the logger
896
+ * is stream-bound.
897
+ *
898
+ * @returns The logger instance for chaining
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * logger.progress('Loading...')
903
+ * // ... do work ...
904
+ * logger.clearLine()
905
+ * logger.success('Loaded')
906
+ *
907
+ * // Clear multiple progress updates
908
+ * for (const file of files) {
909
+ * logger.progress(`Processing ${file}`)
910
+ * processFile(file)
911
+ * logger.clearLine()
912
+ * }
913
+ * logger.success('All files processed')
914
+ * ```
180
915
  */
181
916
  clearLine(): this;
182
917
  }
918
+ /**
919
+ * Default logger instance for the application.
920
+ *
921
+ * A pre-configured `Logger` instance that uses the standard `process.stdout`
922
+ * and `process.stderr` streams. This is the recommended logger to import
923
+ * and use throughout your application.
924
+ *
925
+ * @example
926
+ * ```typescript
927
+ * import { logger } from '@socketsecurity/lib'
928
+ *
929
+ * logger.log('Application started')
930
+ * logger.success('Configuration loaded')
931
+ * logger.indent()
932
+ * logger.log('Using port 3000')
933
+ * logger.dedent()
934
+ * ```
935
+ */
183
936
  export declare const logger: Logger;