@nejs/basic-extensions 2.19.0 → 2.21.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 (68) hide show
  1. package/bin/repl.basics.js +36 -6
  2. package/bin/repl.signature.js +63 -0
  3. package/dist/@nejs/basic-extensions.bundle.2.21.0.js +25 -0
  4. package/dist/@nejs/basic-extensions.bundle.2.21.0.js.map +7 -0
  5. package/dist/cjs/classes/descriptor.d.ts +1 -1
  6. package/dist/cjs/classes/enum.d.ts +37 -19
  7. package/dist/cjs/classes/enum.js +192 -64
  8. package/dist/cjs/classes/enum.js.map +1 -1
  9. package/dist/cjs/classes/iterable.d.ts +3 -3
  10. package/dist/cjs/classes/param.parser.d.ts +1 -7
  11. package/dist/cjs/classes/pluggable.proxy.d.ts +2 -1
  12. package/dist/cjs/classes/property.d.ts +2 -9
  13. package/dist/cjs/classes/refset.d.ts +2 -2
  14. package/dist/cjs/classes/symkeys.d.ts +1 -1
  15. package/dist/cjs/global.this.js +17 -7
  16. package/dist/cjs/global.this.js.map +1 -1
  17. package/dist/cjs/index.d.ts +8 -5
  18. package/dist/cjs/index.js +13 -8
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/cjs/string.extensions.js +38 -0
  21. package/dist/cjs/string.extensions.js.map +1 -1
  22. package/dist/cjs/utils/copy.object.d.ts +2 -2
  23. package/dist/cjs/utils/descriptor.utils.d.ts +152 -0
  24. package/dist/cjs/utils/descriptor.utils.js +274 -13
  25. package/dist/cjs/utils/descriptor.utils.js.map +1 -1
  26. package/dist/cjs/utils/index.d.ts +15 -0
  27. package/dist/cjs/utils/index.js +9 -0
  28. package/dist/cjs/utils/index.js.map +1 -1
  29. package/dist/cjs/utils/stdout.d.ts +742 -0
  30. package/dist/cjs/utils/stdout.js +1042 -0
  31. package/dist/cjs/utils/stdout.js.map +1 -0
  32. package/dist/mjs/classes/descriptor.d.ts +1 -1
  33. package/dist/mjs/classes/enum.d.ts +37 -19
  34. package/dist/mjs/classes/enum.js +192 -65
  35. package/dist/mjs/classes/enum.js.map +1 -1
  36. package/dist/mjs/classes/iterable.d.ts +3 -3
  37. package/dist/mjs/classes/param.parser.d.ts +1 -7
  38. package/dist/mjs/classes/pluggable.proxy.d.ts +2 -1
  39. package/dist/mjs/classes/property.d.ts +2 -9
  40. package/dist/mjs/classes/refset.d.ts +2 -2
  41. package/dist/mjs/classes/symkeys.d.ts +1 -1
  42. package/dist/mjs/index.d.ts +8 -5
  43. package/dist/mjs/index.js +13 -8
  44. package/dist/mjs/index.js.map +1 -1
  45. package/dist/mjs/string.extensions.js +38 -0
  46. package/dist/mjs/string.extensions.js.map +1 -1
  47. package/dist/mjs/utils/copy.object.d.ts +2 -2
  48. package/dist/mjs/utils/descriptor.utils.d.ts +152 -0
  49. package/dist/mjs/utils/descriptor.utils.js +268 -13
  50. package/dist/mjs/utils/descriptor.utils.js.map +1 -1
  51. package/dist/mjs/utils/index.d.ts +15 -0
  52. package/dist/mjs/utils/index.js +10 -1
  53. package/dist/mjs/utils/index.js.map +1 -1
  54. package/dist/mjs/utils/stdout.d.ts +742 -0
  55. package/dist/mjs/utils/stdout.js +1037 -0
  56. package/dist/mjs/utils/stdout.js.map +1 -0
  57. package/package.json +6 -20
  58. package/repl.bootstrap.js +24 -16
  59. package/repl.history +30 -15
  60. package/src/classes/enum.js +278 -133
  61. package/src/index.js +22 -8
  62. package/src/string.extensions.js +41 -0
  63. package/src/utils/descriptor.utils.js +332 -14
  64. package/src/utils/index.js +20 -0
  65. package/src/utils/stdout.js +1151 -0
  66. package/tests/utils/descriptor.utils.test.js +130 -0
  67. package/dist/@nejs/basic-extensions.bundle.2.19.0.js +0 -19
  68. package/dist/@nejs/basic-extensions.bundle.2.19.0.js.map +0 -7
@@ -0,0 +1,742 @@
1
+ /**
2
+ * Captures the output written to `process.stdout` during the execution of
3
+ * a callback function. This function temporarily overrides the standard
4
+ * output stream to capture any data written to it, allowing for inspection
5
+ * or testing of console output.
6
+ *
7
+ * @param {Function|*} callback - The function to execute, during which
8
+ * `process.stdout` is captured. If not a function, it will be treated
9
+ * as the first argument to a console log.
10
+ * @param {Array} [args=[]] - Arguments to pass to the callback function.
11
+ * @param {Object} [thisArg=console] - The value of `this` provided for
12
+ * the call to `callback`.
13
+ * @returns {string} The captured output from `process.stdout`.
14
+ *
15
+ * @example
16
+ * const output = captureStdout(() => {
17
+ * console.log('Hello, World!')
18
+ * })
19
+ * console.log(output) // Outputs: 'Hello, World!'
20
+ *
21
+ * @description
22
+ * This function is useful for testing or capturing console output without
23
+ * displaying it in the terminal. It works by temporarily replacing
24
+ * `process.stdout.write` with a custom function that appends output to a
25
+ * string. After the callback is executed, the original `process.stdout.write`
26
+ * is restored.
27
+ */
28
+ export function captureStdout(callback: Function | any, args?: any[], thisArg?: Object): string;
29
+ /**
30
+ * A class that simulates a console for capturing and manipulating console
31
+ * output as strings. This class provides methods to log messages, format
32
+ * them with colors, and store them in a buffer for later inspection or
33
+ * manipulation.
34
+ *
35
+ * @example
36
+ * const stringConsole = new StringConsole()
37
+ * stringConsole.log('Hello, World!')
38
+ * stringConsole.buffer // ['Hello, World!']
39
+ *
40
+ * @description
41
+ * The StringConsole class is designed to capture console output without
42
+ * displaying it in the terminal. It stores the output in a buffer, allowing
43
+ * for easy retrieval and manipulation. This is particularly useful for
44
+ * testing or when console output needs to be processed programmatically.
45
+ */
46
+ export class StringConsole {
47
+ /**
48
+ * Captures a single line of text that would be logged to the console if
49
+ * the console function of the same name were to be invoked. The string
50
+ * is formatted according to the log colors, or any pre-existing colors as
51
+ * those are untouched. After formatting, the string is returned.
52
+ *
53
+ * @param {...*} args the arguments to be logged. These can be of any
54
+ * type and will be passed to the underlying console's method of the same
55
+ * name.
56
+ *
57
+ * @returns {string}
58
+ *
59
+ * @example
60
+ * const string = StringConsole.debug('[debug]: %o', someVariable)
61
+ */
62
+ static debug(...args: any[]): string;
63
+ /**
64
+ * Captures a single line of text that would be logged to the console if
65
+ * the console function of the same name were to be invoked. The string
66
+ * is formatted according to the log colors, or any pre-existing colors as
67
+ * those are untouched. After formatting, the string is returned.
68
+ *
69
+ * @param {...*} args the arguments to be logged. These can be of any
70
+ * type and will be passed to the underlying console's method of the same
71
+ * name.
72
+ *
73
+ * @returns {string}
74
+ *
75
+ * @example
76
+ * const string = StringConsole.error('[error]: %o', someVariable)
77
+ */
78
+ static error(...args: any[]): string;
79
+ /**
80
+ * Groups console output under a specified group name and captures the
81
+ * output. No content will actually be logged to the console, just
82
+ * the output that normally would be is formatted in a string and returned
83
+ * instead.
84
+ *
85
+ * This method allows you to format multiple messages under a single
86
+ * group name. It captures the output of each invocation and stores it in
87
+ * a buffer. The captured output is returned as a single string.
88
+ *
89
+ * @param {string} groupName - The name of the group under which the
90
+ * messages will be logged.
91
+ * @param {...Array} invocations - An array of invocations where each
92
+ * invocation is an array. The first element is the log level (e.g.,
93
+ * 'log', 'info'), and the remaining elements are the arguments to be
94
+ * logged.
95
+ *
96
+ * @returns {string} The captured console output as a string.
97
+ *
98
+ * @example
99
+ * const console = new StringConsole()
100
+ * const output = console.group('MyGroup',
101
+ * ['log', 'Hello'],
102
+ * ['warn', 'Warning!']
103
+ * )
104
+ *
105
+ * console.buffer // Contains the captured group output
106
+ */
107
+ static group(groupName: string, ...invocations: any[][]): string;
108
+ /**
109
+ * Captures a single line of text that would be logged to the console if
110
+ * the console function of the same name were to be invoked. The string
111
+ * is formatted according to the log colors, or any pre-existing colors as
112
+ * those are untouched. After formatting, the string is returned.
113
+ *
114
+ * @param {...*} args the arguments to be logged. These can be of any
115
+ * type and will be passed to the underlying console's method of the same
116
+ * name.
117
+ *
118
+ * @returns {string}
119
+ *
120
+ * @example
121
+ * const string = StringConsole.info('[info]: %o', someVariable)
122
+ */
123
+ static info(...args: any[]): string;
124
+ /**
125
+ * Captures a single line of text that would be logged to the console if
126
+ * the console function of the same name were to be invoked. The string
127
+ * is formatted according to the log colors, or any pre-existing colors as
128
+ * those are untouched. After formatting, the string is returned.
129
+ *
130
+ * @param {...*} args the arguments to be logged. These can be of any
131
+ * type and will be passed to the underlying console's method of the same
132
+ * name.
133
+ *
134
+ * @returns {string}
135
+ *
136
+ * @example
137
+ * const string = StringConsole.log('[log]: %o', someVariable)
138
+ */
139
+ static log(...args: any[]): string;
140
+ /**
141
+ * Captures a single line of text that would be logged to the console if
142
+ * the console function of the same name were to be invoked. The string
143
+ * is formatted according to the log colors, or any pre-existing colors as
144
+ * those are untouched. After formatting, the string is returned.
145
+ *
146
+ * @param {...*} args the arguments to be logged. These can be of any
147
+ * type and will be passed to the underlying console's method of the same
148
+ * name.
149
+ *
150
+ * @returns {string}
151
+ *
152
+ * @example
153
+ * const string = StringConsole.trace('[trace]: %o', someVariable)
154
+ */
155
+ static trace(...args: any[]): string;
156
+ /**
157
+ * Captures a single line of text that would be logged to the console if
158
+ * the console function of the same name were to be invoked. The string
159
+ * is formatted according to the log colors, or any pre-existing colors as
160
+ * those are untouched. After formatting, the string is returned.
161
+ *
162
+ * @param {...*} args the arguments to be logged. These can be of any
163
+ * type and will be passed to the underlying console's method of the same
164
+ * name.
165
+ *
166
+ * @returns {string}
167
+ *
168
+ * @example
169
+ * const string = StringConsole.warn('[warn]: %o', someVariable)
170
+ */
171
+ static warn(...args: any[]): string;
172
+ /**
173
+ * Internal instance of {@link StringConsole} used for static logging
174
+ * methods.
175
+ *
176
+ * @type {StringConsole}
177
+ */
178
+ static "__#9@#console": StringConsole;
179
+ /**
180
+ * A static map defining color codes for console output. Each color is
181
+ * associated with an array containing two numbers, which represent
182
+ * the ANSI escape codes for styling text in the terminal.
183
+ *
184
+ * The first number in the array is the suffix code for the standard
185
+ * color, while the second number suffix code to undo the color. These
186
+ * codes are useless without the pen prefix code.
187
+ *
188
+ * @type {Map<string, number[]>}
189
+ * @see {@link StringConsole.pens}
190
+ *
191
+ * @example
192
+ * // Accessing the color codes for 'red'
193
+ * const redCodes = StringConsole.colors.get('red')
194
+ * const fgCodes = StringConsole.pens.get('foreground')
195
+ * const prefix = `\x1b[${fgCodes[0]}${redCodes[0]}m`
196
+ * const suffix = `\x1b[${fgCodes[1]}${redCodes[1]}m`
197
+ * // Outputs: "Text" in red but "!!" in the default color
198
+ * console.log(`${prefix}Text!!${suffix}`)
199
+ *
200
+ * @description
201
+ * This map is used to apply color coding to console messages, enhancing
202
+ * readability and providing visual cues for different log levels.
203
+ */
204
+ static colors: Map<string, number[]>;
205
+ /**
206
+ * A static map defining the color schemes for different logging levels.
207
+ * Each log level is associated with an array of color styles that are
208
+ * applied to the console output for that level.
209
+ *
210
+ * The available log levels and their corresponding color styles are:
211
+ * - 'log': White
212
+ * - 'info': Cyan
213
+ * - 'warn': Yellow
214
+ * - 'error': Red
215
+ * - 'trace': Magenta
216
+ * - 'debug': Bold Yellow
217
+ *
218
+ * @type {Map<string, string[]>}
219
+ *
220
+ * @example
221
+ * const logColor = StringConsole.levels.get('log') // ['white']
222
+ * const errorColor = StringConsole.levels.get('error') // ['red']
223
+ */
224
+ static levels: Map<string, string[]>;
225
+ /**
226
+ * A static map defining the ANSI escape codes for different pen styles
227
+ * used in console output. Each pen style is associated with an array
228
+ * containing two numbers: the first for setting the style and the second
229
+ * for resetting it.
230
+ *
231
+ * The available pen styles and their corresponding ANSI codes are:
232
+ * - 'foreground': [3, 3] - Standard foreground color
233
+ * - 'background': [4, 4] - Standard background color
234
+ * - 'bright.foreground': [9, 3] - Bright foreground color
235
+ * - 'bright.background': [10, 4] - Bright background color
236
+ *
237
+ * These are prefixes for both enabling and disabling. Normally a red color
238
+ * is represented using SGR (Select Graphic Rendition) codes like \x1b[31m
239
+ * for the foreground and \x1b[39m to return to normal color. So the 3
240
+ * determines a foreground prefix for starting and stopping (the 3's in 31
241
+ * and 39). Background prefixes are usually 4. These change for bright
242
+ * colors which use 9 and 3, and 10 and 4, respectively.
243
+ *
244
+ * @type {Map<string, number[]>}
245
+ *
246
+ * @example
247
+ * // [3, 3]
248
+ * const foregroundPen = StringConsole.pens.get('foreground')
249
+ *
250
+ * // [10, 4]
251
+ * const brightBackgroundPen = StringConsole.pens.get('bright.background')
252
+ */
253
+ static pens: Map<string, number[]>;
254
+ /**
255
+ * A static map defining ANSI escape codes for various text styles used
256
+ * in console output. Each style is associated with an array containing
257
+ * two escape codes: one for enabling the style and one for disabling it.
258
+ *
259
+ * The available styles and their corresponding ANSI codes are:
260
+ * - 'reset': Resets all styles to default.
261
+ * - 'blink': Enables blinking text.
262
+ * - 'bold': Makes text bold.
263
+ * - 'conceal': Conceals text.
264
+ * - 'dim': Dims the text.
265
+ * - 'italics': Italicizes the text.
266
+ * - 'negative': Inverts the foreground and background colors.
267
+ * - 'strike': Strikes through the text.
268
+ * - 'underline': Underlines the text.
269
+ *
270
+ * @type {Map<string, string[]>}
271
+ *
272
+ * @example
273
+ * const boldStyle = StringConsole.styles.get('bold')
274
+ * // ['\x1b[1m', '\x1b[22m']
275
+ */
276
+ static styles: Map<string, string[]>;
277
+ /**
278
+ * Applies ANSI color codes to a given string based on specified options.
279
+ * This method checks if the string already contains color codes or if
280
+ * the input is not a string, in which case it returns the original input.
281
+ * Otherwise, it formats the string with the specified color and pen
282
+ * options.
283
+ *
284
+ * @param {string} string - The string to be colorized.
285
+ * @param {Object} [options] - Configuration options for colorization.
286
+ * @param {string} [options.level] - The log level determining
287
+ * which colors to apply.
288
+ * @param {number[]} [options.rgb8] a single color code where 0 - 7, for
289
+ * the 'standard' colors specified by the SGR sequences 30 to 37; 8-15 are
290
+ * high intensity or bright colors,
291
+ * @param {number[]} [options.rgb24] An array of three values, ordered, red,
292
+ * green and then blue. The values should range from 0 to 255.
293
+ * @param {string|string[]} [options.styles] defaulting to an empty array, if
294
+ * supplied with a single known style {@link ~styles}, or an array of them.
295
+ * @param {string} [options.pen='foreground'] - The pen type for color
296
+ * application, either 'foreground' or 'background'.
297
+ * @param {Array} [options.buffer=[]] - An array to prepend to the
298
+ * formatted string.
299
+ * @param {Array} [options.before=[]] - An array of strings to prepend
300
+ * before the main string.
301
+ * @param {Array} [options.after=[]] - An array of strings to append
302
+ * after the main string. 16 - 231, for the colors in the 6 × 6 × 6 cube
303
+ * defined by 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5); 232-255:
304
+ * grayscale from dark to light in 24 steps.
305
+ *
306
+ * @returns {string} The colorized string with ANSI codes applied.
307
+ *
308
+ * @example
309
+ * const coloredString = StringConsole.color('Hello', {
310
+ * level: 'info',
311
+ * pen: 'bright.foreground'
312
+ * })
313
+ * console.log(coloredString)
314
+ */
315
+ static color(string: string, options?: {
316
+ level?: string | undefined;
317
+ rgb8?: number[] | undefined;
318
+ rgb24?: number[] | undefined;
319
+ styles?: string | string[] | undefined;
320
+ pen?: string | undefined;
321
+ buffer?: any[] | undefined;
322
+ before?: any[] | undefined;
323
+ after?: any[] | undefined;
324
+ }): string;
325
+ /**
326
+ * Applies color formatting to each argument based on the specified log level.
327
+ *
328
+ * This method processes an array of arguments, applying color formatting
329
+ * to each one according to the provided log level. The color formatting
330
+ * is determined by the `color` method, which uses the log level to
331
+ * select the appropriate color scheme.
332
+ *
333
+ * @param {string} level - The log level that determines the color scheme
334
+ * to be applied. Common levels include 'log', 'info', 'warn', 'error',
335
+ * etc.
336
+ * @param {Array} args - An array of arguments to be formatted. Each
337
+ * argument will be processed individually to apply the color formatting.
338
+ *
339
+ * @returns {Array} A new array containing the formatted arguments with
340
+ * color applied.
341
+ *
342
+ * @example
343
+ * const formattedArgs = StringConsole.colorArgs(
344
+ * 'info',
345
+ * ['Message 1', 'Message 2']
346
+ * )
347
+ * // formattedArgs will contain the messages with 'info' level
348
+ * // color formatting
349
+ */
350
+ static colorArgs(level: string, args: any[]): any[];
351
+ /**
352
+ * Determines if a given string contains ANSI color codes.
353
+ *
354
+ * This method checks for the presence of ANSI escape codes in the
355
+ * provided string, which are used for color formatting in terminal
356
+ * outputs. The presence of these codes indicates that the string
357
+ * has color formatting applied.
358
+ *
359
+ * @param {string} string - The string to be checked for ANSI color codes.
360
+ *
361
+ * @returns {boolean} Returns true if the string contains ANSI color codes,
362
+ * otherwise false.
363
+ *
364
+ * @example
365
+ * const hasColor = StringConsole.hasColor('\x1b[31mRed Text\x1b[0m')
366
+ * // hasColor will be true
367
+ *
368
+ * const noColor = StringConsole.hasColor('Plain Text')
369
+ * // noColor will be false
370
+ */
371
+ static hasColor(string: string): boolean;
372
+ /**
373
+ * Applies a series of styles to a given string using ANSI escape codes.
374
+ *
375
+ * This method takes a string and an array of style names or style arrays,
376
+ * and applies the corresponding ANSI escape codes to the string. The
377
+ * styles are defined in the `styles` map, which associates style names
378
+ * with their respective ANSI codes.
379
+ *
380
+ * @param {string} string - The string to which styles will be applied.
381
+ * @param {string|string[]} styles - A style name or an array of style
382
+ * names/arrays to be applied. Each style can be a string that matches
383
+ * a key in the `styles` map or an array containing ANSI codes.
384
+ *
385
+ * @returns {string} The styled string with ANSI escape codes applied.
386
+ *
387
+ * @example
388
+ * const styledText = StringConsole.style('Hello', ['bold', 'underline'])
389
+ * // styledText will have 'Hello' with bold and underline styles
390
+ */
391
+ static style(string: string, styles: string | string[]): string;
392
+ /**
393
+ * Initializes a new instance of the StringConsole class.
394
+ *
395
+ * @param {string|string[]} [initialContents] - The initial contents to
396
+ * populate the buffer. If an array is provided, it will be used directly
397
+ * as the buffer. If a single string is provided, it will be converted
398
+ * to a string and added to the buffer.
399
+ *
400
+ * @example
401
+ * const console1 = new StringConsole('Hello')
402
+ * console1.buffer // ['Hello']
403
+ *
404
+ * const console2 = new StringConsole(['Hello', 'World'])
405
+ * console2.buffer // ['Hello', 'World']
406
+ */
407
+ constructor(captureOutput?: boolean, initialContents?: string | string[]);
408
+ /**
409
+ * @type {Array}
410
+ * @description
411
+ * The buffer array is used to store captured console output. It is
412
+ * initialized as an empty array and can be populated with strings
413
+ * representing console messages. This buffer serves as a temporary
414
+ * storage for output that can be manipulated or inspected later.
415
+ *
416
+ * @example
417
+ * const console = new StringConsole()
418
+ * console.buffer.push('Hello, World!')
419
+ * console.buffer // ['Hello, World!']
420
+ */
421
+ buffer: any[];
422
+ /**
423
+ * The last index of the buffer when capture began. This number should be
424
+ * set to `NaN` when not in use.
425
+ *
426
+ * @type {number|NaN}
427
+ */
428
+ capturedAt: number | number;
429
+ /**
430
+ * If this is `true`, all "logged" output will be captured in an ever
431
+ * growing buffer.
432
+ *
433
+ * @type {boolean}
434
+ * @see {@link StringConsole.buffer}
435
+ */
436
+ captureOutput: boolean;
437
+ /**
438
+ * @typedef {
439
+ * Int8Array|Int16Array|Int32Array|Float32Array|Float64Array
440
+ * } TypedArray
441
+ */
442
+ /**
443
+ * @typedef {(
444
+ * chunk: string|Buffer|TypedArray|DataView,
445
+ * encoding: string|null,
446
+ * callback: ()=>{}
447
+ * )=>boolean} StringConsoleRecorder
448
+ * @property {boolean} [Symbol.for('StringConsole.recorder')]
449
+ */
450
+ /**
451
+ * The recorder function is what is subsituted for the `process.stdout.write`
452
+ * function whenever we need to temporarily capture the output of data bound
453
+ * for the bidirectional read-write stream, `stdout`.
454
+ *
455
+ * @type {StringConsoleRecorder}
456
+ * @param {string|Buffer|TypedArray|DataView|any} chunk Optional data to
457
+ * write. For streams not operating in object mode, chunk must be a
458
+ * {@link String}, {@link Buffer}, {@link Int8Array}, {@link Int16Array},
459
+ * {@link Int32Array}, {@link Float32Array}, {@link Float64Array} or
460
+ * {@link DataView}. For object mode streams, chunk may be any JavaScript
461
+ * value other than `null`.
462
+ * @param {string|null} encoding the encoding, if chunk is a string.
463
+ * Default: `'utf8'`
464
+ * @param {Function} callback callback for when this chunk of data is
465
+ * flushed.
466
+ *
467
+ * @returns {boolean} false if the stream wishes for the calling code to
468
+ * wait for the 'drain' event to be emitted before continuing to write
469
+ * additional data; otherwise true.
470
+ */
471
+ recorder: (chunk: string | Buffer | TypedArray | DataView, encoding: string | null, callback: () => {}) => boolean;
472
+ /**
473
+ * Clears the buffer by removing all elements.
474
+ *
475
+ * This method utilizes the `splice` function to remove all elements
476
+ * from the buffer array, effectively resetting it to an empty state.
477
+ * This is useful when you want to discard all previously captured
478
+ * console output and start fresh.
479
+ *
480
+ * @returns {StringConsole} `this` to allow for calling `clear()`
481
+ * before immediately invoking a console method.
482
+ *
483
+ * @example
484
+ * const console = new StringConsole(['Hello', 'World'])
485
+ * console.clear()
486
+ * console.buffer // []
487
+ */
488
+ clear(): StringConsole;
489
+ /**
490
+ * Checks if the console output is currently being captured.
491
+ *
492
+ * This method determines if the `process.stdout.write` function has been
493
+ * overridden to capture console output by checking for the presence of
494
+ * a specific symbol.
495
+ *
496
+ * @returns {boolean} True if capturing is active, false otherwise.
497
+ *
498
+ * @example
499
+ * const stringConsole = new StringConsole()
500
+ * stringConsole.startCapture()
501
+ * console.log(stringConsole.isCapturing()) // Stores 'true' in the buffer
502
+ */
503
+ isCapturing(): boolean;
504
+ /**
505
+ * Starts capturing console output.
506
+ *
507
+ * This method overrides the `process.stdout.write` function with a custom
508
+ * recorder function to capture all console output.
509
+ *
510
+ * @returns {number} the last index of the buffer in its current state or
511
+ * 0 if it is empty
512
+ *
513
+ * @example
514
+ * const stringConsole = new StringConsole()
515
+ * stringConsole.startCapture()
516
+ * console.log('This will be stored in stringConsole.buffer')
517
+ */
518
+ startCapture(): number;
519
+ /**
520
+ * An object containing two properties covering the captured content
521
+ * while `process.stdout.write` was swapped. It should contain the
522
+ * range of line indicies as well as the content as an array of strings
523
+ *
524
+ * @typedef {object} StringConsoleCapturedOutput
525
+ * @property {number[]} range an array of two numbers, a starting index
526
+ * and an ending index. This value will be [NaN,NaN] if this instance
527
+ * has indicated that storing captured output is disabled.
528
+ * @property {string[]} lines an array of strings of captured output
529
+ * that occurred in between calls to {@link ~startCapture} and then
530
+ * ending call to {@link ~stopCapture}
531
+ */
532
+ /**
533
+ * Stops capturing console output.
534
+ *
535
+ * This method restores the original `process.stdout.write` function,
536
+ * ceasing the capture of console output.
537
+ *
538
+ * @returns {StringConsoleCapturedOutput} the range of indices capturing
539
+ * the lines of the buffer that have been added since capturing was
540
+ * started.
541
+ *
542
+ * @example
543
+ * const stringConsole = new StringConsole()
544
+ * stringConsole.startCapture()
545
+ * console.log('This will be stored in stringConsole.buffer')
546
+ * stringConsole.stopCapture()
547
+ * console.log('This will not be captured')
548
+ */
549
+ stopCapture(): {
550
+ /**
551
+ * an array of two numbers, a starting index
552
+ * and an ending index. This value will be [NaN,NaN] if this instance
553
+ * has indicated that storing captured output is disabled.
554
+ */
555
+ range: number[];
556
+ /**
557
+ * an array of strings of captured output
558
+ * that occurred in between calls to {@link ~startCapture} and then
559
+ * ending call to {@link ~stopCapture}
560
+ */
561
+ lines: string[];
562
+ };
563
+ /**
564
+ * Joins the StringConsole output as a single string. By default, each entry
565
+ * captured so far is joined on a new line. Pass a different joiner such as
566
+ * an empty string or a whitespace character, as examples, to change the
567
+ * output string.
568
+ *
569
+ * @param {string} joinOn the string to join the output buffer on, defaults
570
+ * to a new line character
571
+ * @returns a single string of contatenated entries so far to this buffer.
572
+ */
573
+ toString(joinOn?: string): string;
574
+ /**
575
+ * Captures formatted debug messages as though they'd been printed. The
576
+ * resulting output that would have been printed is stored in the buffer
577
+ * as well as being returned.
578
+ *
579
+ * This method formats the provided arguments with color coding specific
580
+ * to the 'debug' level as though `console.debug` were used. The output
581
+ * is captured and stored in the buffer for later inspection, but not
582
+ * actually printed to the standard output.
583
+ *
584
+ * @param {any[]} args - The arguments to be log captured. These can be
585
+ * of any type and will be formatted with color coding without being logged.
586
+ *
587
+ * @returns {string} The captured console output as a string.
588
+ *
589
+ * @example
590
+ * const stringConsole = new StringConsole()
591
+ * stringConsole.debug('[debug]', 'message')
592
+ * stringConsole.buffer // Contains the captured messages so far as an array
593
+ */
594
+ debug(...args: any[]): string;
595
+ /**
596
+ * Captures formatted error messages as though they'd been printed. The
597
+ * resulting output that would have been printed is stored in the buffer
598
+ * as well as being returned.
599
+ *
600
+ * This method formats the provided arguments with color coding specific
601
+ * to the 'error' level as though `console.error` were used. The output
602
+ * is captured and stored in the buffer for later inspection, but not
603
+ * actually printed to the standard output.
604
+ *
605
+ * @param {any[]} args - The arguments to be log captured. These can be
606
+ * of any type and will be formatted with color coding without being logged.
607
+ *
608
+ * @returns {string} The captured console output as a string.
609
+ *
610
+ * @example
611
+ * const stringConsole = new StringConsole()
612
+ * stringConsole.error('[error]', 'message')
613
+ * stringConsole.buffer // Contains the captured messages so far as an array
614
+ */
615
+ error(...args: any[]): string;
616
+ /**
617
+ * Groups console output under a specified group name and captures the
618
+ * output. No content will actually be logged to the console, just
619
+ * the output that normally would be is formatted in a string and returned
620
+ * instead.
621
+ *
622
+ * This method allows you to format multiple messages under a single
623
+ * group name. It captures the output of each invocation and stores it in
624
+ * a buffer. The captured output is returned as a single string.
625
+ *
626
+ * @param {string} groupName - The name of the group under which the
627
+ * messages will be logged.
628
+ * @param {...Array} invocations - An array of invocations where each
629
+ * invocation is an array. The first element is the log level (e.g.,
630
+ * 'log', 'info'), and the remaining elements are the arguments to be
631
+ * logged.
632
+ *
633
+ * @returns {string} The captured console output as a string.
634
+ *
635
+ * @example
636
+ * const console = new StringConsole()
637
+ * const output = console.group('MyGroup',
638
+ * ['log', 'Hello'],
639
+ * ['warn', 'Warning!']
640
+ * )
641
+ *
642
+ * console.buffer // Contains the captured group output
643
+ */
644
+ group(groupName: string, ...invocations: any[][]): string;
645
+ /**
646
+ * Captures formatted info messages as though they'd been printed. The
647
+ * resulting output that would have been printed is stored in the buffer
648
+ * as well as being returned.
649
+ *
650
+ * This method formats the provided arguments with color coding specific
651
+ * to the 'info' level as though `console.info` were used. The output
652
+ * is captured and stored in the buffer for later inspection, but not
653
+ * actually printed to the standard output.
654
+ *
655
+ * @param {any[]} args - The arguments to be log captured. These can be
656
+ * of any type and will be formatted with color coding without being logged.
657
+ *
658
+ * @returns {string} The captured console output as a string.
659
+ *
660
+ * @example
661
+ * const stringConsole = new StringConsole()
662
+ * stringConsole.info('[info]', 'message')
663
+ * stringConsole.buffer // Contains the captured messages so far as an array
664
+ */
665
+ info(...args: any[]): string;
666
+ /**
667
+ * Captures formatted log messages as though they'd been printed. The
668
+ * resulting output that would have been printed is stored in the buffer
669
+ * as well as being returned.
670
+ *
671
+ * This method formats the provided arguments with color coding specific
672
+ * to the 'log' level as though `console.log` were used. The output
673
+ * is captured and stored in the buffer for later inspection, but not
674
+ * actually printed to the standard output.
675
+ *
676
+ * @param {any[]} args - The arguments to be log captured. These can be
677
+ * of any type and will be formatted with color coding without being logged.
678
+ *
679
+ * @returns {string} The captured console output as a string.
680
+ *
681
+ * @example
682
+ * const stringConsole = new StringConsole()
683
+ * stringConsole.log('[log]', 'message')
684
+ * stringConsole.buffer // Contains the captured messages so far as an array
685
+ */
686
+ log(...args: any[]): string;
687
+ /**
688
+ * Captures formatted trace messages as though they'd been printed. The
689
+ * resulting output that would have been printed is stored in the buffer
690
+ * as well as being returned.
691
+ *
692
+ * This method formats the provided arguments with color coding specific
693
+ * to the 'trace' level as though `console.trace` were used. The output
694
+ * is captured and stored in the buffer for later inspection, but not
695
+ * actually printed to the standard output.
696
+ *
697
+ * @param {any[]} args - The arguments to be log captured. These can be
698
+ * of any type and will be formatted with color coding without being logged.
699
+ *
700
+ * @returns {string} The captured console output as a string.
701
+ *
702
+ * @example
703
+ * const stringConsole = new StringConsole()
704
+ * stringConsole.trace('[trace]', 'message')
705
+ * stringConsole.buffer // Contains the captured messages so far as an array
706
+ */
707
+ trace(...args: any[]): string;
708
+ /**
709
+ * Captures formatted warn messages as though they'd been printed. The
710
+ * resulting output that would have been printed is stored in the buffer
711
+ * as well as being returned.
712
+ *
713
+ * This method formats the provided arguments with color coding specific
714
+ * to the 'warn' level as though `console.warn` were used. The output
715
+ * is captured and stored in the buffer for later inspection, but not
716
+ * actually printed to the standard output.
717
+ *
718
+ * @param {any[]} args - The arguments to be log captured. These can be
719
+ * of any type and will be formatted with color coding without being logged.
720
+ *
721
+ * @returns {string} The captured console output as a string.
722
+ *
723
+ * @example
724
+ * const stringConsole = new StringConsole()
725
+ * stringConsole.warn('[warn]', 'message')
726
+ * stringConsole.buffer // Contains the captured messages so far as an array
727
+ */
728
+ warn(...args: any[]): string;
729
+ }
730
+ export const SC: typeof StringConsole;
731
+ export const StringConsoleExtension: Extension;
732
+ export const StdoutGlobalPatches: Patch;
733
+ declare namespace _default {
734
+ export { StringConsole as SC };
735
+ export { StringConsole };
736
+ export { StringConsoleExtension };
737
+ export { StdoutGlobalPatches };
738
+ export { captureStdout };
739
+ }
740
+ export default _default;
741
+ import { Extension } from '@nejs/extension';
742
+ import { Patch } from '@nejs/extension';