@gesslar/toolkit 2.4.0 → 2.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gesslar/toolkit",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A collection of utilities for Node.js and browser environments.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/lib/Glog.js CHANGED
@@ -33,6 +33,15 @@ export const loggerColours = {
33
33
  reset: "{/}", // Reset
34
34
  }
35
35
 
36
+ // Symbol alternatives for tags
37
+ export const logSymbols = {
38
+ debug: "?",
39
+ info: "i",
40
+ warn: "!",
41
+ error: "✗",
42
+ success: "✓"
43
+ }
44
+
36
45
  // Set up convenient aliases for common log colors
37
46
  c.alias.set("debug", "{F033}")
38
47
  c.alias.set("info", "{F036}")
@@ -50,6 +59,7 @@ class Glog {
50
59
  static colors = null
51
60
  static stackTrace = false
52
61
  static name = ""
62
+ static tagsAsStrings = false
53
63
 
54
64
  // Instance properties (for configured loggers)
55
65
  #logLevel = 0
@@ -57,6 +67,8 @@ class Glog {
57
67
  #colors = null
58
68
  #stackTrace = false
59
69
  #name = ""
70
+ #tagsAsStrings = false
71
+ #displayName = true
60
72
  #vscodeError = null
61
73
  #vscodeWarn = null
62
74
  #vscodeInfo = null
@@ -87,6 +99,8 @@ class Glog {
87
99
  this.#logPrefix = options.prefix ?? this.#logPrefix
88
100
  this.#colors = options.colors ?? this.#colors
89
101
  this.#stackTrace = options.stackTrace ?? this.#stackTrace
102
+ this.#tagsAsStrings = options.tagsAsStrings ?? this.#tagsAsStrings
103
+ this.#displayName = options.displayName ?? this.#displayName
90
104
 
91
105
  return this
92
106
  }
@@ -123,6 +137,12 @@ class Glog {
123
137
  return this
124
138
  }
125
139
 
140
+ static withTagsAsStrings(enabled = false) {
141
+ this.tagsAsStrings = enabled
142
+
143
+ return this
144
+ }
145
+
126
146
  // === FLUENT INSTANCE CREATION ===
127
147
 
128
148
  static create(options = {}) {
@@ -159,6 +179,18 @@ class Glog {
159
179
  return this
160
180
  }
161
181
 
182
+ withTagsAsStrings(enabled = false) {
183
+ this.#tagsAsStrings = enabled
184
+
185
+ return this
186
+ }
187
+
188
+ noDisplayName() {
189
+ this.#displayName = false
190
+
191
+ return this
192
+ }
193
+
162
194
  // === UTILITY METHODS ===
163
195
 
164
196
  get name() {
@@ -182,19 +214,28 @@ class Glog {
182
214
  #compose(level, message, debugLevel = 0) {
183
215
  const colors = this.#colors || Glog.colors || loggerColours
184
216
  const name = this.#name || Glog.name || "Log"
185
- const tag = Util.capitalize(level)
217
+ const useStrings = this.#tagsAsStrings || Glog.tagsAsStrings
218
+ const showName = this.#displayName
219
+ const tag = useStrings ? Util.capitalize(level) : logSymbols[level]
220
+ const namePrefix = showName ? `[${name}] ` : ""
186
221
 
187
222
  if(!colors) {
188
- return `[${name}] ${tag}: ${message}`
223
+ return useStrings
224
+ ? `${namePrefix}${tag}: ${message}`
225
+ : `${namePrefix}${tag} ${message}`
189
226
  }
190
227
 
191
228
  if(level === "debug") {
192
229
  const colorCode = colors[level][debugLevel] || colors[level][0]
193
230
 
194
- return c`[${name}] ${colorCode}${tag}{/}: ${message}`
231
+ return useStrings
232
+ ? c`${namePrefix}${colorCode}${tag}{/}: ${message}`
233
+ : c`${namePrefix}${colorCode}${tag}{/} ${message}`
195
234
  }
196
235
 
197
- return c`[${name}] ${colors[level]}${tag}{/}: ${message}`
236
+ return useStrings
237
+ ? c`${namePrefix}${colors[level]}${tag}{/}: ${message}`
238
+ : c`${namePrefix}${colors[level]}${tag}{/} ${message}`
198
239
  }
199
240
 
200
241
  // Stack trace functionality - simplified for now
@@ -342,7 +383,16 @@ class Glog {
342
383
  * @param {...unknown} args - Additional arguments
343
384
  */
344
385
  success(message, ...args) {
345
- Term.log(c`[${this.#name || Glog.name || "Log"}] {success}Success{/}: ${message}`, ...args)
386
+ const name = this.#name || Glog.name || "Log"
387
+ const useStrings = this.#tagsAsStrings || Glog.tagsAsStrings
388
+ const showName = this.#displayName
389
+ const tag = useStrings ? "Success" : logSymbols.success
390
+ const namePrefix = showName ? `[${name}] ` : ""
391
+ const formatted = useStrings
392
+ ? c`${namePrefix}{success}${tag}{/}: ${message}`
393
+ : c`${namePrefix}{success}${tag}{/} ${message}`
394
+
395
+ Term.log(formatted, ...args)
346
396
  }
347
397
 
348
398
  /**
@@ -352,7 +402,143 @@ class Glog {
352
402
  * @param {...unknown} args - Additional arguments to log
353
403
  */
354
404
  static success(message, ...args) {
355
- Term.log(c`[${this.name || "Log"}] {success}Success{/}: ${message}`, ...args)
405
+ const name = this.name || "Log"
406
+ const useStrings = this.tagsAsStrings
407
+ const tag = useStrings ? "Success" : logSymbols.success
408
+ const formatted = useStrings
409
+ ? c`[${name}] {success}${tag}{/}: ${message}`
410
+ : c`[${name}] {success}${tag}{/} ${message}`
411
+
412
+ Term.log(formatted, ...args)
413
+ }
414
+
415
+ /**
416
+ * Static group method - start a console group for indented output
417
+ *
418
+ * @param {...unknown} args - Optional group label
419
+ */
420
+ static group(...args) {
421
+ const name = this.name || "Log"
422
+ const label = args.length > 0 ? ` ${args.join(" ")}` : ""
423
+
424
+ Term.group(`[${name}]${label}`)
425
+ }
426
+
427
+ /**
428
+ * Static groupEnd method - end the current console group
429
+ */
430
+ static groupEnd() {
431
+ Term.groupEnd()
432
+ }
433
+
434
+ /**
435
+ * Static groupDebug - start a debug-tagged group
436
+ *
437
+ * @param {string} message - Group label
438
+ * @param {number} [level=1] - Debug level
439
+ */
440
+ static groupDebug(message, level = 1) {
441
+ const colors = this.colors || loggerColours
442
+ const name = this.name || "Log"
443
+ const useStrings = this.tagsAsStrings
444
+ const tag = useStrings ? "Debug" : logSymbols.debug
445
+ const colorCode = colors.debug[level] || colors.debug[0]
446
+ const label = useStrings
447
+ ? c`[${name}] ${colorCode}${tag}{/}: ${message}`
448
+ : c`[${name}] ${colorCode}${tag}{/} ${message}`
449
+
450
+ Term.group(label)
451
+ }
452
+
453
+ /**
454
+ * Static groupInfo - start an info-tagged group
455
+ *
456
+ * @param {string} message - Group label
457
+ */
458
+ static groupInfo(message) {
459
+ const colors = this.colors || loggerColours
460
+ const name = this.name || "Log"
461
+ const useStrings = this.tagsAsStrings
462
+ const tag = useStrings ? "Info" : logSymbols.info
463
+ const label = useStrings
464
+ ? c`[${name}] ${colors.info}${tag}{/}: ${message}`
465
+ : c`[${name}] ${colors.info}${tag}{/} ${message}`
466
+
467
+ Term.group(label)
468
+ }
469
+
470
+ /**
471
+ * Static groupSuccess - start a success-tagged group
472
+ *
473
+ * @param {string} message - Group label
474
+ */
475
+ static groupSuccess(message) {
476
+ const name = this.name || "Log"
477
+ const useStrings = this.tagsAsStrings
478
+ const tag = useStrings ? "Success" : logSymbols.success
479
+ const label = useStrings
480
+ ? c`[${name}] {success}${tag}{/}: ${message}`
481
+ : c`[${name}] {success}${tag}{/} ${message}`
482
+
483
+ Term.group(label)
484
+ }
485
+
486
+ /**
487
+ * Start a console group for indented output
488
+ *
489
+ * @param {...unknown} args - Optional group label
490
+ */
491
+ group(...args) {
492
+ const name = this.#name || Glog.name || "Log"
493
+ const showName = this.#displayName
494
+ const label = args.length > 0 ? ` ${args.join(" ")}` : ""
495
+ const output = showName ? `[${name}]${label}` : label.trim()
496
+
497
+ Term.group(output)
498
+ }
499
+
500
+ /**
501
+ * End the current console group
502
+ */
503
+ groupEnd() {
504
+ Term.groupEnd()
505
+ }
506
+
507
+ /**
508
+ * Start a debug-tagged group
509
+ *
510
+ * @param {string} message - Group label
511
+ * @param {number} [level=1] - Debug level
512
+ */
513
+ groupDebug(message, level = 1) {
514
+ Term.group(this.#compose("debug", message, level))
515
+ }
516
+
517
+ /**
518
+ * Start an info-tagged group
519
+ *
520
+ * @param {string} message - Group label
521
+ */
522
+ groupInfo(message) {
523
+ Term.group(this.#compose("info", message))
524
+ }
525
+
526
+ /**
527
+ * Start a success-tagged group
528
+ *
529
+ * @param {string} message - Group label
530
+ */
531
+ groupSuccess(message) {
532
+ const name = this.#name || Glog.name || "Log"
533
+ const useStrings = this.#tagsAsStrings || Glog.tagsAsStrings
534
+ const showName = this.#displayName
535
+ const tag = useStrings ? "Success" : logSymbols.success
536
+ const namePrefix = showName ? `[${name}] ` : ""
537
+ const label = useStrings
538
+ ? c`${namePrefix}{success}${tag}{/}: ${message}`
539
+ : c`${namePrefix}{success}${tag}{/} ${message}`
540
+
541
+ Term.group(label)
356
542
  }
357
543
 
358
544
  /**
@@ -434,6 +620,44 @@ class Glog {
434
620
  get colours() {
435
621
  return c
436
622
  }
623
+
624
+ /**
625
+ * Get a raw logger that outputs without name/tag formatting
626
+ *
627
+ * @returns {object} Raw logger interface
628
+ */
629
+ get raw() {
630
+ return {
631
+ debug: (message, ...args) => Term.debug(message, ...args),
632
+ info: (message, ...args) => Term.info(message, ...args),
633
+ warn: (message, ...args) => Term.warn(message, ...args),
634
+ error: (message, ...args) => Term.error(message, ...args),
635
+ log: (...args) => Term.log(...args),
636
+ success: (message, ...args) => Term.log(message, ...args),
637
+ table: (data, options) => Term.table(data, options || {}),
638
+ group: (...args) => Term.group(...args),
639
+ groupEnd: () => Term.groupEnd()
640
+ }
641
+ }
642
+
643
+ /**
644
+ * Static raw logger that outputs without name/tag formatting
645
+ *
646
+ * @returns {object} Raw logger interface
647
+ */
648
+ static get raw() {
649
+ return {
650
+ debug: (message, ...args) => Term.debug(message, ...args),
651
+ info: (message, ...args) => Term.info(message, ...args),
652
+ warn: (message, ...args) => Term.warn(message, ...args),
653
+ error: (message, ...args) => Term.error(message, ...args),
654
+ log: (...args) => Term.log(...args),
655
+ success: (message, ...args) => Term.log(message, ...args),
656
+ table: (data, options) => Term.table(data, options || {}),
657
+ group: (...args) => Term.group(...args),
658
+ groupEnd: () => Term.groupEnd()
659
+ }
660
+ }
437
661
  }
438
662
 
439
663
  // Wrap in proxy for dual usage
@@ -5,6 +5,17 @@ export namespace loggerColours {
5
5
  let error: string;
6
6
  let reset: string;
7
7
  }
8
+ export namespace logSymbols {
9
+ let debug_1: string;
10
+ export { debug_1 as debug };
11
+ let info_1: string;
12
+ export { info_1 as info };
13
+ let warn_1: string;
14
+ export { warn_1 as warn };
15
+ let error_1: string;
16
+ export { error_1 as error };
17
+ export let success: string;
18
+ }
8
19
  declare const _default: typeof Glog;
9
20
  export default _default;
10
21
  declare class Glog {
@@ -13,6 +24,7 @@ declare class Glog {
13
24
  static colors: any;
14
25
  static stackTrace: boolean;
15
26
  static name: string;
27
+ static tagsAsStrings: boolean;
16
28
  static setLogPrefix(prefix: any): typeof Glog;
17
29
  static setLogLevel(level: any): typeof Glog;
18
30
  static withName(name: any): typeof Glog;
@@ -24,6 +36,7 @@ declare class Glog {
24
36
  reset: string;
25
37
  }): typeof Glog;
26
38
  static withStackTrace(enabled?: boolean): typeof Glog;
39
+ static withTagsAsStrings(enabled?: boolean): typeof Glog;
27
40
  static create(options?: {}): Glog;
28
41
  static execute(...args: any[]): void;
29
42
  /**
@@ -40,6 +53,35 @@ declare class Glog {
40
53
  * @param {...unknown} args - Additional arguments to log
41
54
  */
42
55
  static success(message: string, ...args: unknown[]): void;
56
+ /**
57
+ * Static group method - start a console group for indented output
58
+ *
59
+ * @param {...unknown} args - Optional group label
60
+ */
61
+ static group(...args: unknown[]): void;
62
+ /**
63
+ * Static groupEnd method - end the current console group
64
+ */
65
+ static groupEnd(): void;
66
+ /**
67
+ * Static groupDebug - start a debug-tagged group
68
+ *
69
+ * @param {string} message - Group label
70
+ * @param {number} [level=1] - Debug level
71
+ */
72
+ static groupDebug(message: string, level?: number): void;
73
+ /**
74
+ * Static groupInfo - start an info-tagged group
75
+ *
76
+ * @param {string} message - Group label
77
+ */
78
+ static groupInfo(message: string): void;
79
+ /**
80
+ * Static groupSuccess - start a success-tagged group
81
+ *
82
+ * @param {string} message - Group label
83
+ */
84
+ static groupSuccess(message: string): void;
43
85
  /**
44
86
  * Static table method
45
87
  *
@@ -63,6 +105,12 @@ declare class Glog {
63
105
  * @returns {Glog} The Glog class for chaining.
64
106
  */
65
107
  static setAlias(alias: string, colorCode: string): Glog;
108
+ /**
109
+ * Static raw logger that outputs without name/tag formatting
110
+ *
111
+ * @returns {object} Raw logger interface
112
+ */
113
+ static get raw(): object;
66
114
  constructor(options?: {});
67
115
  setOptions(options: any): this;
68
116
  withName(name: any): this;
@@ -76,6 +124,8 @@ declare class Glog {
76
124
  reset: string;
77
125
  }): this;
78
126
  withStackTrace(enabled?: boolean): this;
127
+ withTagsAsStrings(enabled?: boolean): this;
128
+ noDisplayName(): this;
79
129
  get name(): string;
80
130
  get debugLevel(): number;
81
131
  get options(): {
@@ -117,6 +167,35 @@ declare class Glog {
117
167
  * @param {...unknown} args - Additional arguments
118
168
  */
119
169
  success(message: string, ...args: unknown[]): void;
170
+ /**
171
+ * Start a console group for indented output
172
+ *
173
+ * @param {...unknown} args - Optional group label
174
+ */
175
+ group(...args: unknown[]): void;
176
+ /**
177
+ * End the current console group
178
+ */
179
+ groupEnd(): void;
180
+ /**
181
+ * Start a debug-tagged group
182
+ *
183
+ * @param {string} message - Group label
184
+ * @param {number} [level=1] - Debug level
185
+ */
186
+ groupDebug(message: string, level?: number): void;
187
+ /**
188
+ * Start an info-tagged group
189
+ *
190
+ * @param {string} message - Group label
191
+ */
192
+ groupInfo(message: string): void;
193
+ /**
194
+ * Start a success-tagged group
195
+ *
196
+ * @param {string} message - Group label
197
+ */
198
+ groupSuccess(message: string): void;
120
199
  /**
121
200
  * Display tabular data as a table
122
201
  *
@@ -138,6 +217,12 @@ declare class Glog {
138
217
  * @returns {import('@gesslar/colours')} The colours template function from \@gesslar/colours
139
218
  */
140
219
  get colours(): typeof import("@gesslar/colours");
220
+ /**
221
+ * Get a raw logger that outputs without name/tag formatting
222
+ *
223
+ * @returns {object} Raw logger interface
224
+ */
225
+ get raw(): object;
141
226
  #private;
142
227
  }
143
228
  //# sourceMappingURL=Glog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Glog.d.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OAIG;IACH,iDAEC;;CACF"}
1
+ {"version":3,"file":"Glog.d.ts","sourceRoot":"","sources":["../../lib/Glog.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAsDA;IAEE,wBAAmB;IACnB,yBAAqB;IACrB,mBAAoB;IACpB,2BAAyB;IACzB,oBAAgB;IAChB,8BAA4B;IAgD5B,8CAIC;IAED,4CAIC;IAED,wCAIC;IAED;;;;;;oBAIC;IAED,sDAIC;IAED,yDAIC;IAID,kCAEC;IA6KD,qCAoBC;IAuBD;;;;;OAKG;IACH,yBAHW,KAAK,CAAC,MAAM,CAAC,aACV,OAAO,EAAA,QAOpB;IAqBD;;;;;OAKG;IACH,wBAHW,MAAM,WACH,OAAO,EAAA,QAWpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAOpB;IAED;;OAEG;IACH,wBAEC;IAED;;;;;OAKG;IACH,2BAHW,MAAM,UACN,MAAM,QAahB;IAED;;;;OAIG;IACH,0BAFW,MAAM,QAYhB;IAED;;;;OAIG;IACH,6BAFW,MAAM,QAWhB;IAyFD;;;;;;;;;OASG;IACH,mBAPW,MAAM,QAAQ,mBACd,MAAM,GAAG,MAAM,YAEvB;QAAgC,UAAU,GAAlC,KAAK,CAAC,MAAM,CAAC;QACK,UAAU,GAA5B,OAAO;QACW,aAAa,GAA/B,OAAO;KACjB,QAkBA;IAED;;;;;;OAMG;IACH,uBAJW,MAAM,aACN,MAAM,GACJ,IAAI,CAMhB;IA8BD;;;;OAIG;IACH,kBAFa,MAAM,CAclB;IAxkBD,0BAgBC;IAID,+BAUC;IA8CD,0BAIC;IAED,+BAIC;IAED,8BAIC;IAED;;;;;;aAIC;IAED,wCAIC;IAED,2CAIC;IAED,sBAIC;IAID,mBAEC;IAED,yBAEC;IAED;;;;;;MAQC;IA8BD,8BAGC;IAED,wBAQC;IA8BD;;;;;;;;;OASG;IACH,eALW,MAAM,UACN,MAAM,UACH,OAAO,EAAA,QAapB;IAED,wCAGC;IAED,wCAG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