@gesslar/toolkit 2.3.1 → 2.4.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 +1 -1
- package/src/browser/lib/Util.js +5 -2
- package/src/lib/Glog.js +60 -1
- package/src/lib/Term.js +71 -0
- package/src/types/browser/lib/Util.d.ts +1 -1
- package/src/types/browser/lib/Util.d.ts.map +1 -1
- package/src/types/lib/Glog.d.ts +30 -0
- package/src/types/lib/Glog.d.ts.map +1 -1
- package/src/types/lib/Term.d.ts +14 -0
- package/src/types/lib/Term.d.ts.map +1 -1
package/package.json
CHANGED
package/src/browser/lib/Util.js
CHANGED
|
@@ -139,8 +139,11 @@ export default class Util {
|
|
|
139
139
|
* @param {Array<object>} rejected - Array of rejected results.
|
|
140
140
|
* @throws {Error} Throws a Tantrum error with rejection reasons.
|
|
141
141
|
*/
|
|
142
|
-
static throwRejected(message="GIGO",
|
|
143
|
-
throw Tantrum.new(
|
|
142
|
+
static throwRejected(message="GIGO", settled) {
|
|
143
|
+
throw Tantrum.new(
|
|
144
|
+
message,
|
|
145
|
+
this.rejectedReasons(this.settledAndRejected(settled))
|
|
146
|
+
)
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
/**
|
package/src/lib/Glog.js
CHANGED
|
@@ -63,6 +63,7 @@ class Glog {
|
|
|
63
63
|
|
|
64
64
|
constructor(options = {}) {
|
|
65
65
|
this.setOptions(options)
|
|
66
|
+
this.constructor.name = "Glog"
|
|
66
67
|
|
|
67
68
|
// VSCode integration if specified
|
|
68
69
|
if(options.env === "extension") {
|
|
@@ -125,7 +126,7 @@ class Glog {
|
|
|
125
126
|
// === FLUENT INSTANCE CREATION ===
|
|
126
127
|
|
|
127
128
|
static create(options = {}) {
|
|
128
|
-
return new
|
|
129
|
+
return new this(options)
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
withName(name) {
|
|
@@ -354,6 +355,64 @@ class Glog {
|
|
|
354
355
|
Term.log(c`[${this.name || "Log"}] {success}Success{/}: ${message}`, ...args)
|
|
355
356
|
}
|
|
356
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Display tabular data as a table
|
|
360
|
+
*
|
|
361
|
+
* @param {object | Array} data - Object or array to display
|
|
362
|
+
* @param {string | object} [labelOrOptions] - Optional label (string) or options (object)
|
|
363
|
+
* @param {object} [options] - Optional options when label is provided
|
|
364
|
+
* @param {Array<string>} [options.properties] - Column properties to display
|
|
365
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row
|
|
366
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings
|
|
367
|
+
*/
|
|
368
|
+
table(data, labelOrOptions, options) {
|
|
369
|
+
let label
|
|
370
|
+
let tableOptions = {}
|
|
371
|
+
|
|
372
|
+
// Parse polymorphic parameters
|
|
373
|
+
if(typeof labelOrOptions === "string") {
|
|
374
|
+
label = labelOrOptions
|
|
375
|
+
tableOptions = options || {}
|
|
376
|
+
} else if(typeof labelOrOptions === "object" && labelOrOptions !== null) {
|
|
377
|
+
tableOptions = labelOrOptions
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if(label) {
|
|
381
|
+
Term.log(c`[${this.#name || Glog.name || "Log"}] {info}Table{/}: ${label}`)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
Term.table(data, tableOptions)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Static table method
|
|
389
|
+
*
|
|
390
|
+
* @param {object | Array} data - Object or array to display
|
|
391
|
+
* @param {string | object} [labelOrOptions] - Optional label (string) or options (object)
|
|
392
|
+
* @param {object} [options] - Optional options when label is provided
|
|
393
|
+
* @param {Array<string>} [options.properties] - Column properties to display
|
|
394
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row
|
|
395
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings
|
|
396
|
+
*/
|
|
397
|
+
static table(data, labelOrOptions, options) {
|
|
398
|
+
let label
|
|
399
|
+
let tableOptions = {}
|
|
400
|
+
|
|
401
|
+
// Parse polymorphic parameters
|
|
402
|
+
if(typeof labelOrOptions === "string") {
|
|
403
|
+
label = labelOrOptions
|
|
404
|
+
tableOptions = options || {}
|
|
405
|
+
} else if(typeof labelOrOptions === "object" && labelOrOptions !== null) {
|
|
406
|
+
tableOptions = labelOrOptions
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if(label) {
|
|
410
|
+
Term.log(c`[${this.name || "Log"}] {info}Table{/}: ${label}`)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
Term.table(data, tableOptions)
|
|
414
|
+
}
|
|
415
|
+
|
|
357
416
|
/**
|
|
358
417
|
* Set a color alias for convenient usage
|
|
359
418
|
*
|
package/src/lib/Term.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import console from "node:console"
|
|
2
2
|
import process from "node:process"
|
|
3
|
+
import {Console} from "node:console"
|
|
4
|
+
import {Writable} from "node:stream"
|
|
3
5
|
|
|
4
6
|
import Sass from "./Sass.js"
|
|
5
7
|
|
|
@@ -65,6 +67,75 @@ export default class Term {
|
|
|
65
67
|
console.groupEnd()
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Display tabular data as a table.
|
|
72
|
+
*
|
|
73
|
+
* @param {object | Array} tabularData - Object or array to display.
|
|
74
|
+
* @param {object} [options] - Table options.
|
|
75
|
+
* @param {Array<string>} [options.properties] - Optional column properties to display.
|
|
76
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row with column names.
|
|
77
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings.
|
|
78
|
+
*/
|
|
79
|
+
static table(tabularData, options = {}) {
|
|
80
|
+
const {properties, showHeader = false, quotedStrings = false} = options
|
|
81
|
+
|
|
82
|
+
if(showHeader && quotedStrings) {
|
|
83
|
+
// Simple case: use default console.table
|
|
84
|
+
console.table(tabularData, properties)
|
|
85
|
+
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Capture console.table output
|
|
90
|
+
let output = ""
|
|
91
|
+
const stream = new Writable({
|
|
92
|
+
write(chunk, encoding, callback) {
|
|
93
|
+
output += chunk.toString()
|
|
94
|
+
callback()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Make stream appear as a TTY to preserve colors
|
|
99
|
+
stream.isTTY = true
|
|
100
|
+
stream.columns = process.stdout.columns
|
|
101
|
+
stream.rows = process.stdout.rows
|
|
102
|
+
stream.getColorDepth = () => process.stdout.getColorDepth?.() ?? 8
|
|
103
|
+
|
|
104
|
+
const tempConsole = new Console(stream)
|
|
105
|
+
|
|
106
|
+
tempConsole.table(tabularData, properties)
|
|
107
|
+
|
|
108
|
+
// Process output
|
|
109
|
+
let processed = output
|
|
110
|
+
|
|
111
|
+
// Remove quotes if requested
|
|
112
|
+
if(!quotedStrings) {
|
|
113
|
+
// Replace 'string' with string + 2 spaces to maintain alignment
|
|
114
|
+
// Use a more precise regex to avoid matching color codes
|
|
115
|
+
processed = processed.replace(/'([^']*)'/g, (match, content) => {
|
|
116
|
+
// Add 2 spaces to compensate for removed quotes
|
|
117
|
+
return content + " "
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Remove header row and separator line
|
|
122
|
+
const lines = processed.split("\n")
|
|
123
|
+
|
|
124
|
+
if(lines.length > 3 && !showHeader) {
|
|
125
|
+
// Remove the header row (line 1) and separator (line 2)
|
|
126
|
+
// Keep: top border (line 0), data rows (line 3+)
|
|
127
|
+
const modified = [lines[0], ...lines.slice(3)]
|
|
128
|
+
|
|
129
|
+
process.stdout.write(modified.join("\n"))
|
|
130
|
+
} else if(showHeader) {
|
|
131
|
+
// Keep header but remove quotes if requested
|
|
132
|
+
process.stdout.write(processed)
|
|
133
|
+
} else {
|
|
134
|
+
// Fallback: just output as-is if format unexpected
|
|
135
|
+
process.stdout.write(processed)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
68
139
|
/**
|
|
69
140
|
* Emit a status line to the terminal.
|
|
70
141
|
*
|
|
@@ -83,7 +83,7 @@ export default class Util {
|
|
|
83
83
|
* @param {Array<object>} rejected - Array of rejected results.
|
|
84
84
|
* @throws {Error} Throws a Tantrum error with rejection reasons.
|
|
85
85
|
*/
|
|
86
|
-
static throwRejected(message: string,
|
|
86
|
+
static throwRejected(message: string, settled: any): void;
|
|
87
87
|
/**
|
|
88
88
|
* Filters and returns all fulfilled results from a settled promise array.
|
|
89
89
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../browser/lib/Util.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,wBAHW,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;;OAMG;IACH,YAJa,CAAC,MACH,MAAM,OAAO,CAAC,CAAC,CAAC,GACd,OAAO,CAAC;QAAC,MAAM,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC,CAQ9C;IAED;;;;;;;OAOG;IACH,4BAJW,MAAM,GAAC,MAAM,UACb,MAAM,GACJ,MAAM,CAWlB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,MAAM,UACb,MAAM,GACJ,MAAM,CAalB;IAED;;;;;;OAMG;IACH,0BAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAInC;IAED;;;;;;OAMG;IACH,2BAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAIlC;IAED;;;;;OAKG;IACH,2BAHW,KAAK,CAAC,MAAM,CAAC,GACX,OAAO,CAInB;IAED;;;;;OAKG;IACH,kCAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC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;IACH,+BAHW,KAAK,CAAC,MAAM,CAAC,GACX,KAAK,CAAC,OAAO,CAAC,CAI1B;IAED;;;;;;OAMG;IACH,sBAHW,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrB,OAAO,CAAC,OAAO,CAAC,CAI5B;IAED;;;;;;OAMG;IACH,8BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;;;;OAQG;IACH,+BALW,MAAM,iBACN,KAAK,CAAC,MAAM,CAAC,cACb,MAAM,GACJ,MAAM,CAwBlB;IAED,mEAiBC;CACF"}
|
package/src/types/lib/Glog.d.ts
CHANGED
|
@@ -40,6 +40,21 @@ declare class Glog {
|
|
|
40
40
|
* @param {...unknown} args - Additional arguments to log
|
|
41
41
|
*/
|
|
42
42
|
static success(message: string, ...args: unknown[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Static table method
|
|
45
|
+
*
|
|
46
|
+
* @param {object | Array} data - Object or array to display
|
|
47
|
+
* @param {string | object} [labelOrOptions] - Optional label (string) or options (object)
|
|
48
|
+
* @param {object} [options] - Optional options when label is provided
|
|
49
|
+
* @param {Array<string>} [options.properties] - Column properties to display
|
|
50
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row
|
|
51
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings
|
|
52
|
+
*/
|
|
53
|
+
static table(data: object | any[], labelOrOptions?: string | object, options?: {
|
|
54
|
+
properties?: Array<string>;
|
|
55
|
+
showHeader?: boolean;
|
|
56
|
+
quotedStrings?: boolean;
|
|
57
|
+
}): void;
|
|
43
58
|
/**
|
|
44
59
|
* Set a color alias for convenient usage
|
|
45
60
|
*
|
|
@@ -102,6 +117,21 @@ declare class Glog {
|
|
|
102
117
|
* @param {...unknown} args - Additional arguments
|
|
103
118
|
*/
|
|
104
119
|
success(message: string, ...args: unknown[]): void;
|
|
120
|
+
/**
|
|
121
|
+
* Display tabular data as a table
|
|
122
|
+
*
|
|
123
|
+
* @param {object | Array} data - Object or array to display
|
|
124
|
+
* @param {string | object} [labelOrOptions] - Optional label (string) or options (object)
|
|
125
|
+
* @param {object} [options] - Optional options when label is provided
|
|
126
|
+
* @param {Array<string>} [options.properties] - Column properties to display
|
|
127
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row
|
|
128
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings
|
|
129
|
+
*/
|
|
130
|
+
table(data: object | any[], labelOrOptions?: string | object, options?: {
|
|
131
|
+
properties?: Array<string>;
|
|
132
|
+
showHeader?: boolean;
|
|
133
|
+
quotedStrings?: boolean;
|
|
134
|
+
}): void;
|
|
105
135
|
/**
|
|
106
136
|
* Get access to the colours template function for instance usage
|
|
107
137
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Glog.d.ts","sourceRoot":"","sources":["../../lib/Glog.js"],"names":[],"mappings":";;;;;;;;;AA6CA;IAEE,wBAAmB;IACnB,yBAAqB;IACrB,mBAAoB;IACpB,2BAAyB;IACzB,oBAAgB;
|
|
1
|
+
{"version":3,"file":"Glog.d.ts","sourceRoot":"","sources":["../../lib/Glog.js"],"names":[],"mappings":";;;;;;;;;AA6CA;IAEE,wBAAmB;IACnB,yBAAqB;IACrB,mBAAoB;IACpB,2BAAyB;IACzB,oBAAgB;IA4ChB,8CAIC;IAED,4CAIC;IAED,wCAIC;IAED;;;;;;oBAIC;IAED,sDAIC;IAID,kCAEC;IAwJD,qCAoBC;IAuBD;;;;;OAKG;IACH,yBAHW,KAAK,CAAC,MAAM,CAAC,aACV,OAAO,EAAA,QAOpB;IAYD;;;;;OAKG;IACH,wBAHW,MAAM,WACH,OAAO,EAAA,QAIpB;IA+BD;;;;;;;;;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;IA3WD,0BAgBC;IAID,+BAQC;IAwCD,0BAIC;IAED,+BAIC;IAED,8BAIC;IAED;;;;;;aAIC;IAED,wCAIC;IAID,mBAEC;IAED,yBAEC;IAED;;;;;;MAQC;IAqBD,8BAGC;IAED,wBAQC;IA8BD;;;;;;;;;OASG;IACH,eALW,MAAM,UACN,MAAM,UACH,OAAO,EAAA,QAapB;IAED,wCAGC;IAED,wCAGC;IAED,yCAGC;IA0BD,8BAEC;IAID;;;;;;OAMG;IACH,kBAJW,KAAK,CAAC,MAAM,CAAC,aACV,OAAO,EAAA,QAQpB;IAeD;;;;;OAKG;IACH,iBAHW,MAAM,WACH,OAAO,EAAA,QAIpB;IAYD;;;;;;;;;OASG;IACH,YAPW,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;IA4CD;;;;OAIG;IACH,iDAEC;;CACF"}
|
package/src/types/lib/Term.d.ts
CHANGED
|
@@ -39,6 +39,20 @@ export default class Term {
|
|
|
39
39
|
* End the current console group.
|
|
40
40
|
*/
|
|
41
41
|
static groupEnd(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Display tabular data as a table.
|
|
44
|
+
*
|
|
45
|
+
* @param {object | Array} tabularData - Object or array to display.
|
|
46
|
+
* @param {object} [options] - Table options.
|
|
47
|
+
* @param {Array<string>} [options.properties] - Optional column properties to display.
|
|
48
|
+
* @param {boolean} [options.showHeader=false] - Whether to show the header row with column names.
|
|
49
|
+
* @param {boolean} [options.quotedStrings=false] - Whether to show quotes around strings.
|
|
50
|
+
*/
|
|
51
|
+
static table(tabularData: object | any[], options?: {
|
|
52
|
+
properties?: Array<string>;
|
|
53
|
+
showHeader?: boolean;
|
|
54
|
+
quotedStrings?: boolean;
|
|
55
|
+
}): void;
|
|
42
56
|
/**
|
|
43
57
|
* Emit a status line to the terminal.
|
|
44
58
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Term.d.ts","sourceRoot":"","sources":["../../lib/Term.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Term.d.ts","sourceRoot":"","sources":["../../lib/Term.js"],"names":[],"mappings":"AAOA;IACE;;;;OAIG;IACH,oBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,qBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,qBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;;;OAIG;IACH,sBAFc,OAAO,EAAA,QAIpB;IAED;;OAEG;IACH,wBAEC;IAED;;;;;;;;OAQG;IACH,0BANW,MAAM,QAAQ,YAEtB;QAAgC,UAAU,GAAlC,KAAK,CAAC,MAAM,CAAC;QACK,UAAU,GAA5B,OAAO;QACW,aAAa,GAA/B,OAAO;KACjB,QA2DA;IAED;;;;;;;;;;;;;;OAcG;IACH,oBALW,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,eAEjD;QAAyB,MAAM,EAAvB,OAAO;KACf,GAAU,IAAI,CAOhB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,gCAHW,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,GAClE,IAAI,CA4BhB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,gDAJW,KAAK,CAAC,MAAM,CAAC,GACX,MAAM,CASlB;IAED,sCAGC;IAED,2CAEC;IAED,8CAIC;CACF"}
|