tty-table 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/dist/browser/tty-table.global.js +58 -119
- package/dist/browser/tty-table.global.js.map +1 -1
- package/dist/browser.js +58 -119
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +58 -119
- package/dist/browser.mjs.map +1 -1
- package/dist/cli.js +58 -119
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +58 -119
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +58 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -119
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.d.mts +54 -0
- package/dist/mcp.d.ts +54 -0
- package/dist/mcp.js +1107 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp.mjs +1099 -0
- package/dist/mcp.mjs.map +1 -0
- package/package.json +7 -4
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,1107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// node_modules/clone/clone.js
|
|
35
|
+
var require_clone = __commonJS({
|
|
36
|
+
"node_modules/clone/clone.js"(exports2, module2) {
|
|
37
|
+
"use strict";
|
|
38
|
+
var clone = (function() {
|
|
39
|
+
"use strict";
|
|
40
|
+
function clone2(parent, circular, depth, prototype) {
|
|
41
|
+
var filter;
|
|
42
|
+
if (typeof circular === "object") {
|
|
43
|
+
depth = circular.depth;
|
|
44
|
+
prototype = circular.prototype;
|
|
45
|
+
filter = circular.filter;
|
|
46
|
+
circular = circular.circular;
|
|
47
|
+
}
|
|
48
|
+
var allParents = [];
|
|
49
|
+
var allChildren = [];
|
|
50
|
+
var useBuffer = typeof Buffer != "undefined";
|
|
51
|
+
if (typeof circular == "undefined")
|
|
52
|
+
circular = true;
|
|
53
|
+
if (typeof depth == "undefined")
|
|
54
|
+
depth = Infinity;
|
|
55
|
+
function _clone(parent2, depth2) {
|
|
56
|
+
if (parent2 === null)
|
|
57
|
+
return null;
|
|
58
|
+
if (depth2 == 0)
|
|
59
|
+
return parent2;
|
|
60
|
+
var child;
|
|
61
|
+
var proto;
|
|
62
|
+
if (typeof parent2 != "object") {
|
|
63
|
+
return parent2;
|
|
64
|
+
}
|
|
65
|
+
if (clone2.__isArray(parent2)) {
|
|
66
|
+
child = [];
|
|
67
|
+
} else if (clone2.__isRegExp(parent2)) {
|
|
68
|
+
child = new RegExp(parent2.source, __getRegExpFlags(parent2));
|
|
69
|
+
if (parent2.lastIndex) child.lastIndex = parent2.lastIndex;
|
|
70
|
+
} else if (clone2.__isDate(parent2)) {
|
|
71
|
+
child = new Date(parent2.getTime());
|
|
72
|
+
} else if (useBuffer && Buffer.isBuffer(parent2)) {
|
|
73
|
+
if (Buffer.allocUnsafe) {
|
|
74
|
+
child = Buffer.allocUnsafe(parent2.length);
|
|
75
|
+
} else {
|
|
76
|
+
child = new Buffer(parent2.length);
|
|
77
|
+
}
|
|
78
|
+
parent2.copy(child);
|
|
79
|
+
return child;
|
|
80
|
+
} else {
|
|
81
|
+
if (typeof prototype == "undefined") {
|
|
82
|
+
proto = Object.getPrototypeOf(parent2);
|
|
83
|
+
child = Object.create(proto);
|
|
84
|
+
} else {
|
|
85
|
+
child = Object.create(prototype);
|
|
86
|
+
proto = prototype;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (circular) {
|
|
90
|
+
var index = allParents.indexOf(parent2);
|
|
91
|
+
if (index != -1) {
|
|
92
|
+
return allChildren[index];
|
|
93
|
+
}
|
|
94
|
+
allParents.push(parent2);
|
|
95
|
+
allChildren.push(child);
|
|
96
|
+
}
|
|
97
|
+
for (var i in parent2) {
|
|
98
|
+
var attrs;
|
|
99
|
+
if (proto) {
|
|
100
|
+
attrs = Object.getOwnPropertyDescriptor(proto, i);
|
|
101
|
+
}
|
|
102
|
+
if (attrs && attrs.set == null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
child[i] = _clone(parent2[i], depth2 - 1);
|
|
106
|
+
}
|
|
107
|
+
return child;
|
|
108
|
+
}
|
|
109
|
+
return _clone(parent, depth);
|
|
110
|
+
}
|
|
111
|
+
clone2.clonePrototype = function clonePrototype(parent) {
|
|
112
|
+
if (parent === null)
|
|
113
|
+
return null;
|
|
114
|
+
var c = function() {
|
|
115
|
+
};
|
|
116
|
+
c.prototype = parent;
|
|
117
|
+
return new c();
|
|
118
|
+
};
|
|
119
|
+
function __objToStr(o) {
|
|
120
|
+
return Object.prototype.toString.call(o);
|
|
121
|
+
}
|
|
122
|
+
;
|
|
123
|
+
clone2.__objToStr = __objToStr;
|
|
124
|
+
function __isDate(o) {
|
|
125
|
+
return typeof o === "object" && __objToStr(o) === "[object Date]";
|
|
126
|
+
}
|
|
127
|
+
;
|
|
128
|
+
clone2.__isDate = __isDate;
|
|
129
|
+
function __isArray(o) {
|
|
130
|
+
return typeof o === "object" && __objToStr(o) === "[object Array]";
|
|
131
|
+
}
|
|
132
|
+
;
|
|
133
|
+
clone2.__isArray = __isArray;
|
|
134
|
+
function __isRegExp(o) {
|
|
135
|
+
return typeof o === "object" && __objToStr(o) === "[object RegExp]";
|
|
136
|
+
}
|
|
137
|
+
;
|
|
138
|
+
clone2.__isRegExp = __isRegExp;
|
|
139
|
+
function __getRegExpFlags(re) {
|
|
140
|
+
var flags = "";
|
|
141
|
+
if (re.global) flags += "g";
|
|
142
|
+
if (re.ignoreCase) flags += "i";
|
|
143
|
+
if (re.multiline) flags += "m";
|
|
144
|
+
return flags;
|
|
145
|
+
}
|
|
146
|
+
;
|
|
147
|
+
clone2.__getRegExpFlags = __getRegExpFlags;
|
|
148
|
+
return clone2;
|
|
149
|
+
})();
|
|
150
|
+
if (typeof module2 === "object" && module2.exports) {
|
|
151
|
+
module2.exports = clone;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// node_modules/defaults/index.js
|
|
157
|
+
var require_defaults = __commonJS({
|
|
158
|
+
"node_modules/defaults/index.js"(exports2, module2) {
|
|
159
|
+
"use strict";
|
|
160
|
+
var clone = require_clone();
|
|
161
|
+
module2.exports = function(options, defaults2) {
|
|
162
|
+
options = options || {};
|
|
163
|
+
Object.keys(defaults2).forEach(function(key) {
|
|
164
|
+
if (typeof options[key] === "undefined") {
|
|
165
|
+
options[key] = clone(defaults2[key]);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return options;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// node_modules/wcwidth/combining.js
|
|
174
|
+
var require_combining = __commonJS({
|
|
175
|
+
"node_modules/wcwidth/combining.js"(exports2, module2) {
|
|
176
|
+
"use strict";
|
|
177
|
+
module2.exports = [
|
|
178
|
+
[768, 879],
|
|
179
|
+
[1155, 1158],
|
|
180
|
+
[1160, 1161],
|
|
181
|
+
[1425, 1469],
|
|
182
|
+
[1471, 1471],
|
|
183
|
+
[1473, 1474],
|
|
184
|
+
[1476, 1477],
|
|
185
|
+
[1479, 1479],
|
|
186
|
+
[1536, 1539],
|
|
187
|
+
[1552, 1557],
|
|
188
|
+
[1611, 1630],
|
|
189
|
+
[1648, 1648],
|
|
190
|
+
[1750, 1764],
|
|
191
|
+
[1767, 1768],
|
|
192
|
+
[1770, 1773],
|
|
193
|
+
[1807, 1807],
|
|
194
|
+
[1809, 1809],
|
|
195
|
+
[1840, 1866],
|
|
196
|
+
[1958, 1968],
|
|
197
|
+
[2027, 2035],
|
|
198
|
+
[2305, 2306],
|
|
199
|
+
[2364, 2364],
|
|
200
|
+
[2369, 2376],
|
|
201
|
+
[2381, 2381],
|
|
202
|
+
[2385, 2388],
|
|
203
|
+
[2402, 2403],
|
|
204
|
+
[2433, 2433],
|
|
205
|
+
[2492, 2492],
|
|
206
|
+
[2497, 2500],
|
|
207
|
+
[2509, 2509],
|
|
208
|
+
[2530, 2531],
|
|
209
|
+
[2561, 2562],
|
|
210
|
+
[2620, 2620],
|
|
211
|
+
[2625, 2626],
|
|
212
|
+
[2631, 2632],
|
|
213
|
+
[2635, 2637],
|
|
214
|
+
[2672, 2673],
|
|
215
|
+
[2689, 2690],
|
|
216
|
+
[2748, 2748],
|
|
217
|
+
[2753, 2757],
|
|
218
|
+
[2759, 2760],
|
|
219
|
+
[2765, 2765],
|
|
220
|
+
[2786, 2787],
|
|
221
|
+
[2817, 2817],
|
|
222
|
+
[2876, 2876],
|
|
223
|
+
[2879, 2879],
|
|
224
|
+
[2881, 2883],
|
|
225
|
+
[2893, 2893],
|
|
226
|
+
[2902, 2902],
|
|
227
|
+
[2946, 2946],
|
|
228
|
+
[3008, 3008],
|
|
229
|
+
[3021, 3021],
|
|
230
|
+
[3134, 3136],
|
|
231
|
+
[3142, 3144],
|
|
232
|
+
[3146, 3149],
|
|
233
|
+
[3157, 3158],
|
|
234
|
+
[3260, 3260],
|
|
235
|
+
[3263, 3263],
|
|
236
|
+
[3270, 3270],
|
|
237
|
+
[3276, 3277],
|
|
238
|
+
[3298, 3299],
|
|
239
|
+
[3393, 3395],
|
|
240
|
+
[3405, 3405],
|
|
241
|
+
[3530, 3530],
|
|
242
|
+
[3538, 3540],
|
|
243
|
+
[3542, 3542],
|
|
244
|
+
[3633, 3633],
|
|
245
|
+
[3636, 3642],
|
|
246
|
+
[3655, 3662],
|
|
247
|
+
[3761, 3761],
|
|
248
|
+
[3764, 3769],
|
|
249
|
+
[3771, 3772],
|
|
250
|
+
[3784, 3789],
|
|
251
|
+
[3864, 3865],
|
|
252
|
+
[3893, 3893],
|
|
253
|
+
[3895, 3895],
|
|
254
|
+
[3897, 3897],
|
|
255
|
+
[3953, 3966],
|
|
256
|
+
[3968, 3972],
|
|
257
|
+
[3974, 3975],
|
|
258
|
+
[3984, 3991],
|
|
259
|
+
[3993, 4028],
|
|
260
|
+
[4038, 4038],
|
|
261
|
+
[4141, 4144],
|
|
262
|
+
[4146, 4146],
|
|
263
|
+
[4150, 4151],
|
|
264
|
+
[4153, 4153],
|
|
265
|
+
[4184, 4185],
|
|
266
|
+
[4448, 4607],
|
|
267
|
+
[4959, 4959],
|
|
268
|
+
[5906, 5908],
|
|
269
|
+
[5938, 5940],
|
|
270
|
+
[5970, 5971],
|
|
271
|
+
[6002, 6003],
|
|
272
|
+
[6068, 6069],
|
|
273
|
+
[6071, 6077],
|
|
274
|
+
[6086, 6086],
|
|
275
|
+
[6089, 6099],
|
|
276
|
+
[6109, 6109],
|
|
277
|
+
[6155, 6157],
|
|
278
|
+
[6313, 6313],
|
|
279
|
+
[6432, 6434],
|
|
280
|
+
[6439, 6440],
|
|
281
|
+
[6450, 6450],
|
|
282
|
+
[6457, 6459],
|
|
283
|
+
[6679, 6680],
|
|
284
|
+
[6912, 6915],
|
|
285
|
+
[6964, 6964],
|
|
286
|
+
[6966, 6970],
|
|
287
|
+
[6972, 6972],
|
|
288
|
+
[6978, 6978],
|
|
289
|
+
[7019, 7027],
|
|
290
|
+
[7616, 7626],
|
|
291
|
+
[7678, 7679],
|
|
292
|
+
[8203, 8207],
|
|
293
|
+
[8234, 8238],
|
|
294
|
+
[8288, 8291],
|
|
295
|
+
[8298, 8303],
|
|
296
|
+
[8400, 8431],
|
|
297
|
+
[12330, 12335],
|
|
298
|
+
[12441, 12442],
|
|
299
|
+
[43014, 43014],
|
|
300
|
+
[43019, 43019],
|
|
301
|
+
[43045, 43046],
|
|
302
|
+
[64286, 64286],
|
|
303
|
+
[65024, 65039],
|
|
304
|
+
[65056, 65059],
|
|
305
|
+
[65279, 65279],
|
|
306
|
+
[65529, 65531],
|
|
307
|
+
[68097, 68099],
|
|
308
|
+
[68101, 68102],
|
|
309
|
+
[68108, 68111],
|
|
310
|
+
[68152, 68154],
|
|
311
|
+
[68159, 68159],
|
|
312
|
+
[119143, 119145],
|
|
313
|
+
[119155, 119170],
|
|
314
|
+
[119173, 119179],
|
|
315
|
+
[119210, 119213],
|
|
316
|
+
[119362, 119364],
|
|
317
|
+
[917505, 917505],
|
|
318
|
+
[917536, 917631],
|
|
319
|
+
[917760, 917999]
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// node_modules/wcwidth/index.js
|
|
325
|
+
var require_wcwidth = __commonJS({
|
|
326
|
+
"node_modules/wcwidth/index.js"(exports2, module2) {
|
|
327
|
+
"use strict";
|
|
328
|
+
var defaults2 = require_defaults();
|
|
329
|
+
var combining = require_combining();
|
|
330
|
+
var DEFAULTS = {
|
|
331
|
+
nul: 0,
|
|
332
|
+
control: 0
|
|
333
|
+
};
|
|
334
|
+
module2.exports = function wcwidth3(str) {
|
|
335
|
+
return wcswidth(str, DEFAULTS);
|
|
336
|
+
};
|
|
337
|
+
module2.exports.config = function(opts) {
|
|
338
|
+
opts = defaults2(opts || {}, DEFAULTS);
|
|
339
|
+
return function wcwidth3(str) {
|
|
340
|
+
return wcswidth(str, opts);
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
function wcswidth(str, opts) {
|
|
344
|
+
if (typeof str !== "string") return wcwidth2(str, opts);
|
|
345
|
+
var s = 0;
|
|
346
|
+
for (var i = 0; i < str.length; i++) {
|
|
347
|
+
var n = wcwidth2(str.charCodeAt(i), opts);
|
|
348
|
+
if (n < 0) return -1;
|
|
349
|
+
s += n;
|
|
350
|
+
}
|
|
351
|
+
return s;
|
|
352
|
+
}
|
|
353
|
+
function wcwidth2(ucs, opts) {
|
|
354
|
+
if (ucs === 0) return opts.nul;
|
|
355
|
+
if (ucs < 32 || ucs >= 127 && ucs < 160) return opts.control;
|
|
356
|
+
if (bisearch(ucs)) return 0;
|
|
357
|
+
return 1 + (ucs >= 4352 && (ucs <= 4447 || // Hangul Jamo init. consonants
|
|
358
|
+
ucs == 9001 || ucs == 9002 || ucs >= 11904 && ucs <= 42191 && ucs != 12351 || // CJK ... Yi
|
|
359
|
+
ucs >= 44032 && ucs <= 55203 || // Hangul Syllables
|
|
360
|
+
ucs >= 63744 && ucs <= 64255 || // CJK Compatibility Ideographs
|
|
361
|
+
ucs >= 65040 && ucs <= 65049 || // Vertical forms
|
|
362
|
+
ucs >= 65072 && ucs <= 65135 || // CJK Compatibility Forms
|
|
363
|
+
ucs >= 65280 && ucs <= 65376 || // Fullwidth Forms
|
|
364
|
+
ucs >= 65504 && ucs <= 65510 || ucs >= 131072 && ucs <= 196605 || ucs >= 196608 && ucs <= 262141));
|
|
365
|
+
}
|
|
366
|
+
function bisearch(ucs) {
|
|
367
|
+
var min = 0;
|
|
368
|
+
var max = combining.length - 1;
|
|
369
|
+
var mid;
|
|
370
|
+
if (ucs < combining[0][0] || ucs > combining[max][1]) return false;
|
|
371
|
+
while (max >= min) {
|
|
372
|
+
mid = Math.floor((min + max) / 2);
|
|
373
|
+
if (ucs > combining[mid][1]) min = mid + 1;
|
|
374
|
+
else if (ucs < combining[mid][0]) max = mid - 1;
|
|
375
|
+
else return true;
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// src/mcp.ts
|
|
383
|
+
var mcp_exports = {};
|
|
384
|
+
__export(mcp_exports, {
|
|
385
|
+
createMcpServer: () => createMcpServer,
|
|
386
|
+
handleRenderTable: () => handleRenderTable,
|
|
387
|
+
renderTableInputSchema: () => renderTableInputSchema
|
|
388
|
+
});
|
|
389
|
+
module.exports = __toCommonJS(mcp_exports);
|
|
390
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
391
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
392
|
+
var import_zod = require("zod");
|
|
393
|
+
|
|
394
|
+
// src/defaults.ts
|
|
395
|
+
var defaults = {
|
|
396
|
+
borderCharacters: {
|
|
397
|
+
invisible: [
|
|
398
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " },
|
|
399
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " },
|
|
400
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " }
|
|
401
|
+
],
|
|
402
|
+
solid: [
|
|
403
|
+
{ v: "\u2502", l: "\u250C", j: "\u252C", h: "\u2500", r: "\u2510" },
|
|
404
|
+
{ v: "\u2502", l: "\u251C", j: "\u253C", h: "\u2500", r: "\u2524" },
|
|
405
|
+
{ v: "\u2502", l: "\u2514", j: "\u2534", h: "\u2500", r: "\u2518" }
|
|
406
|
+
],
|
|
407
|
+
dashed: [
|
|
408
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" },
|
|
409
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" },
|
|
410
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" }
|
|
411
|
+
],
|
|
412
|
+
none: [
|
|
413
|
+
{ v: "", l: "", j: "", h: "", r: "" },
|
|
414
|
+
{ v: "", l: "", j: "", h: "", r: "" },
|
|
415
|
+
{ v: "", l: "", j: "", h: "", r: "" }
|
|
416
|
+
]
|
|
417
|
+
},
|
|
418
|
+
align: "center",
|
|
419
|
+
borderColor: null,
|
|
420
|
+
borderStyle: "solid",
|
|
421
|
+
color: false,
|
|
422
|
+
COLUMNS: 80,
|
|
423
|
+
// if !process.stdout.columns assume redirecting to write stream 80 columns is VT200 standard
|
|
424
|
+
compact: false,
|
|
425
|
+
defaultErrorValue: "\uFFFD",
|
|
426
|
+
defaultValue: "",
|
|
427
|
+
errorOnNull: false,
|
|
428
|
+
FIXED_WIDTH: false,
|
|
429
|
+
footerAlign: "center",
|
|
430
|
+
footerColor: false,
|
|
431
|
+
formatter: null,
|
|
432
|
+
headerAlign: "center",
|
|
433
|
+
headerColor: "yellow",
|
|
434
|
+
isNull: false,
|
|
435
|
+
// undocumented cell setting
|
|
436
|
+
marginLeft: 2,
|
|
437
|
+
marginTop: 1,
|
|
438
|
+
paddingBottom: 0,
|
|
439
|
+
paddingLeft: 1,
|
|
440
|
+
paddingRight: 1,
|
|
441
|
+
paddingTop: 0,
|
|
442
|
+
showHeader: null,
|
|
443
|
+
// undocumented
|
|
444
|
+
truncate: false,
|
|
445
|
+
width: "100%",
|
|
446
|
+
GUTTER: 1,
|
|
447
|
+
// undocumented
|
|
448
|
+
columnSettings: [],
|
|
449
|
+
// save so cell options can be merged into column options
|
|
450
|
+
table: {
|
|
451
|
+
body: "",
|
|
452
|
+
columnInnerWidths: [],
|
|
453
|
+
columnWidths: [],
|
|
454
|
+
columns: [],
|
|
455
|
+
footer: "",
|
|
456
|
+
header: "",
|
|
457
|
+
// post-rendered strings.
|
|
458
|
+
height: 0,
|
|
459
|
+
typeLocked: false
|
|
460
|
+
// once a table type is selected can't switch
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
defaults.borderCharacters["0"] = defaults.borderCharacters.none;
|
|
464
|
+
defaults.borderCharacters["1"] = defaults.borderCharacters.solid;
|
|
465
|
+
defaults.borderCharacters["2"] = defaults.borderCharacters.dashed;
|
|
466
|
+
var defaults_default = defaults;
|
|
467
|
+
|
|
468
|
+
// src/style.ts
|
|
469
|
+
var import_chalk = __toESM(require("chalk"));
|
|
470
|
+
var import_kleur = __toESM(require("kleur"));
|
|
471
|
+
var import_strip_ansi = __toESM(require("strip-ansi"));
|
|
472
|
+
var colorLib = process && process.stdout ? import_chalk.default : import_kleur.default;
|
|
473
|
+
var style = (str, ...colors) => {
|
|
474
|
+
const out = colors.reduce(function(input, color) {
|
|
475
|
+
return colorLib[color](input);
|
|
476
|
+
}, str);
|
|
477
|
+
return out;
|
|
478
|
+
};
|
|
479
|
+
var styleEachChar = (str, ...colors) => {
|
|
480
|
+
const chars = [...(0, import_strip_ansi.default)(str)];
|
|
481
|
+
const out = chars.reduce((prev, current) => {
|
|
482
|
+
const coded = colors.reduce((input, color) => {
|
|
483
|
+
return colorLib[color](input);
|
|
484
|
+
}, current);
|
|
485
|
+
return prev + coded;
|
|
486
|
+
}, "");
|
|
487
|
+
return out;
|
|
488
|
+
};
|
|
489
|
+
var resetStyle = function(str) {
|
|
490
|
+
this.configure({ reset: true });
|
|
491
|
+
return (0, import_strip_ansi.default)(str);
|
|
492
|
+
};
|
|
493
|
+
var colorizeCell = (str, cellOptions, rowType) => {
|
|
494
|
+
let color = false;
|
|
495
|
+
switch (true) {
|
|
496
|
+
case rowType === "body":
|
|
497
|
+
color = cellOptions.color || color;
|
|
498
|
+
break;
|
|
499
|
+
case rowType === "header":
|
|
500
|
+
color = cellOptions.headerColor || color;
|
|
501
|
+
break;
|
|
502
|
+
default:
|
|
503
|
+
color = cellOptions.footerColor || color;
|
|
504
|
+
}
|
|
505
|
+
if (color) {
|
|
506
|
+
str = style(str, color);
|
|
507
|
+
}
|
|
508
|
+
return str;
|
|
509
|
+
};
|
|
510
|
+
var isColorEnabled = () => {
|
|
511
|
+
return process && process.stdout ? colorLib.level > 0 : colorLib.enabled;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
// src/format.ts
|
|
515
|
+
var import_strip_ansi2 = __toESM(require("strip-ansi"));
|
|
516
|
+
var import_smartwrap = __toESM(require("smartwrap"));
|
|
517
|
+
var import_wcwidth = __toESM(require_wcwidth());
|
|
518
|
+
var addPadding = (config, width) => {
|
|
519
|
+
return width + config.paddingLeft + config.paddingRight;
|
|
520
|
+
};
|
|
521
|
+
var getDisplayWidth = (value) => {
|
|
522
|
+
const lines = (0, import_strip_ansi2.default)(value.toString()).split(/[\n\r]/);
|
|
523
|
+
let widest = 0;
|
|
524
|
+
for (const line of lines) {
|
|
525
|
+
const width = (0, import_wcwidth.default)(line);
|
|
526
|
+
if (width > widest) widest = width;
|
|
527
|
+
}
|
|
528
|
+
return widest;
|
|
529
|
+
};
|
|
530
|
+
var getMaxLength = (columnOptions, rows, columnIndex) => {
|
|
531
|
+
let widest = 0;
|
|
532
|
+
if (columnOptions && (columnOptions.value || columnOptions.alias)) {
|
|
533
|
+
const value = columnOptions.alias || columnOptions.value;
|
|
534
|
+
widest = getDisplayWidth(value);
|
|
535
|
+
}
|
|
536
|
+
for (const row of rows) {
|
|
537
|
+
if (row[columnIndex]) {
|
|
538
|
+
const value = row[columnIndex].value ? row[columnIndex].value : row[columnIndex];
|
|
539
|
+
const width = getDisplayWidth(value);
|
|
540
|
+
if (width > widest) widest = width;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return widest;
|
|
544
|
+
};
|
|
545
|
+
var getAvailableWidth = (config) => {
|
|
546
|
+
if (process && (process.stdout && process.stdout.columns || process.env && process.env.COLUMNS)) {
|
|
547
|
+
let viewport = process.stdout && process.stdout.columns ? process.stdout.columns : process.env.COLUMNS;
|
|
548
|
+
viewport = viewport - config.marginLeft;
|
|
549
|
+
if (config.width !== "auto" && /^\d+%$/.test(config.width)) {
|
|
550
|
+
return Math.min(1, config.width.slice(0, -1) * 0.01) * viewport;
|
|
551
|
+
}
|
|
552
|
+
if (config.width !== "auto" && /^\d+$/.test(config.width)) {
|
|
553
|
+
config.FIXED_WIDTH = true;
|
|
554
|
+
return config.width;
|
|
555
|
+
}
|
|
556
|
+
return viewport;
|
|
557
|
+
}
|
|
558
|
+
if (typeof globalThis.window !== "undefined") return globalThis.window.innerWidth;
|
|
559
|
+
return config.COLUMNS - config.marginLeft;
|
|
560
|
+
};
|
|
561
|
+
var getStringLength = (str) => {
|
|
562
|
+
return (0, import_wcwidth.default)((0, import_strip_ansi2.default)(str));
|
|
563
|
+
};
|
|
564
|
+
var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
|
|
565
|
+
const startAnsiRegexp = /^(\x1b\[[0-9;]*m)+/;
|
|
566
|
+
const endAnsiRegexp = /(\x1b\[[0-9;]*m)+$/;
|
|
567
|
+
let str = cellValue.toString();
|
|
568
|
+
const startMatches = str.match(startAnsiRegexp) || [""];
|
|
569
|
+
str = str.replace(startAnsiRegexp, "");
|
|
570
|
+
const endMatches = str.match(endAnsiRegexp) || [""];
|
|
571
|
+
str = str.replace(endAnsiRegexp, "");
|
|
572
|
+
let alignTgt;
|
|
573
|
+
switch (rowType) {
|
|
574
|
+
case "header":
|
|
575
|
+
alignTgt = "headerAlign";
|
|
576
|
+
break;
|
|
577
|
+
case "body":
|
|
578
|
+
alignTgt = "align";
|
|
579
|
+
break;
|
|
580
|
+
default:
|
|
581
|
+
alignTgt = "footerAlign";
|
|
582
|
+
}
|
|
583
|
+
if (cellOptions[alignTgt] === "center") {
|
|
584
|
+
cellOptions.paddingLeft = cellOptions.paddingRight = Math.max(
|
|
585
|
+
cellOptions.paddingRight,
|
|
586
|
+
cellOptions.paddingLeft,
|
|
587
|
+
0
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
const columnWidth = config.table.columnWidths[columnIndex];
|
|
591
|
+
const innerWidth = columnWidth - cellOptions.paddingLeft - cellOptions.paddingRight - config.GUTTER;
|
|
592
|
+
if (typeof config.truncate === "string") {
|
|
593
|
+
str = truncate(str, cellOptions, innerWidth);
|
|
594
|
+
} else {
|
|
595
|
+
str = wrap(str, cellOptions, innerWidth);
|
|
596
|
+
}
|
|
597
|
+
const cell = str.split("\n").map((line) => {
|
|
598
|
+
line = line.trim();
|
|
599
|
+
const lineLength = getStringLength(line);
|
|
600
|
+
if (lineLength < columnWidth) {
|
|
601
|
+
let emptySpace = columnWidth - lineLength;
|
|
602
|
+
switch (true) {
|
|
603
|
+
case cellOptions[alignTgt] === "center":
|
|
604
|
+
emptySpace--;
|
|
605
|
+
const padBoth = Math.floor(emptySpace / 2);
|
|
606
|
+
const padRemainder = emptySpace % 2;
|
|
607
|
+
line = " ".repeat(padBoth) + line + " ".repeat(padBoth + padRemainder);
|
|
608
|
+
break;
|
|
609
|
+
case cellOptions[alignTgt] === "right":
|
|
610
|
+
line = " ".repeat(emptySpace - cellOptions.paddingRight - 1) + line + " ".repeat(cellOptions.paddingRight);
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
line = " ".repeat(cellOptions.paddingLeft) + line + " ".repeat(emptySpace - cellOptions.paddingLeft - 1);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return startMatches[0] + line + endMatches[0];
|
|
617
|
+
});
|
|
618
|
+
return { cell, innerWidth };
|
|
619
|
+
};
|
|
620
|
+
var truncate = (str, cellOptions, maxWidth) => {
|
|
621
|
+
const stringWidth = (0, import_wcwidth.default)(str);
|
|
622
|
+
if (maxWidth < stringWidth) {
|
|
623
|
+
str = (0, import_smartwrap.default)(str, {
|
|
624
|
+
width: maxWidth - cellOptions.truncate.length,
|
|
625
|
+
breakword: true
|
|
626
|
+
}).split("\n")[0];
|
|
627
|
+
str = str + cellOptions.truncate;
|
|
628
|
+
}
|
|
629
|
+
return str;
|
|
630
|
+
};
|
|
631
|
+
var wrap = (str, cellOptions, innerWidth) => {
|
|
632
|
+
const outstring = (0, import_smartwrap.default)(str, {
|
|
633
|
+
errorChar: cellOptions.defaultErrorValue,
|
|
634
|
+
minWidth: 1,
|
|
635
|
+
trim: true,
|
|
636
|
+
width: innerWidth
|
|
637
|
+
});
|
|
638
|
+
return outstring;
|
|
639
|
+
};
|
|
640
|
+
var getColumnWidths = (config, rows) => {
|
|
641
|
+
const availableWidth = getAvailableWidth(config);
|
|
642
|
+
const iterable = config.table.header[0] && config.table.header[0].length > 0 ? config.table.header[0] : rows[0];
|
|
643
|
+
let widths = iterable.map((column, columnIndex) => {
|
|
644
|
+
let result;
|
|
645
|
+
switch (true) {
|
|
646
|
+
// column width is a percentage of table width specified in column header
|
|
647
|
+
case (typeof column === "object" && /^\d+%$/.test(column.width)):
|
|
648
|
+
result = column.width.slice(0, -1) * 0.01 * availableWidth;
|
|
649
|
+
result = addPadding(config, result);
|
|
650
|
+
break;
|
|
651
|
+
// column width is specified in column header
|
|
652
|
+
case (typeof column === "object" && /^\d+$/.test(column.width)):
|
|
653
|
+
result = column.width;
|
|
654
|
+
break;
|
|
655
|
+
// 'auto' sets column width to its longest value in the initial data set
|
|
656
|
+
default: {
|
|
657
|
+
const columnOptions = config.table.header[0][columnIndex] ? config.table.header[0][columnIndex] : {};
|
|
658
|
+
const measurableRows = rows.length ? rows : config.table.header[0];
|
|
659
|
+
result = getMaxLength(columnOptions, measurableRows, columnIndex);
|
|
660
|
+
result = addPadding(config, result);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
result = result + config.GUTTER;
|
|
664
|
+
return result;
|
|
665
|
+
});
|
|
666
|
+
const totalWidth = widths.reduce((prev, current) => prev + current);
|
|
667
|
+
if (totalWidth > availableWidth || config.FIXED_WIDTH) {
|
|
668
|
+
const proportion = (availableWidth / totalWidth).toFixed(2) - 0.01;
|
|
669
|
+
const relativeWidths = widths.map((value) => Math.max(2, Math.floor(proportion * value)));
|
|
670
|
+
if (config.FIXED_WIDTH) return relativeWidths;
|
|
671
|
+
if (proportion > 0) {
|
|
672
|
+
const totalRelativeWidths = relativeWidths.reduce((prev, current) => prev + current);
|
|
673
|
+
widths = totalRelativeWidths < totalWidth ? relativeWidths : widths;
|
|
674
|
+
}
|
|
675
|
+
} else {
|
|
676
|
+
widths = widths.map(Math.floor);
|
|
677
|
+
}
|
|
678
|
+
return widths;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// src/render.ts
|
|
682
|
+
var import_strip_ansi3 = __toESM(require("strip-ansi"));
|
|
683
|
+
var stringifyData = (config, inputData) => {
|
|
684
|
+
const sections = { header: [], body: [], footer: [] };
|
|
685
|
+
const marginLeft = " ".repeat(config.marginLeft);
|
|
686
|
+
const borderStyle = config.borderCharacters[config.borderStyle];
|
|
687
|
+
const borders = [];
|
|
688
|
+
const constructorType = getConstructorGeometry(inputData[0] || [], config);
|
|
689
|
+
const rows = coerceConstructorGeometry(config, inputData, constructorType);
|
|
690
|
+
if (!global.columnWidths) global.columnWidths = {};
|
|
691
|
+
if (global.columnWidths[config.tableId]) {
|
|
692
|
+
config.table.columnWidths = global.columnWidths[config.tableId];
|
|
693
|
+
} else {
|
|
694
|
+
const formattedRows = rows.map((row, rowIndex) => {
|
|
695
|
+
return row.map((cell, cellIndex) => buildCell(config, cell, cellIndex, "body", rowIndex, rows, inputData, true));
|
|
696
|
+
});
|
|
697
|
+
global.columnWidths[config.tableId] = config.table.columnWidths = getColumnWidths(config, formattedRows);
|
|
698
|
+
}
|
|
699
|
+
switch (true) {
|
|
700
|
+
case (config.showHeader !== null && !config.showHeader):
|
|
701
|
+
sections.header = [];
|
|
702
|
+
break;
|
|
703
|
+
case config.showHeader === true:
|
|
704
|
+
case !!config.table.header[0].find((obj) => obj.value || obj.alias):
|
|
705
|
+
sections.header = config.table.header.map((row) => buildRow(config, row, "header", null, rows, inputData));
|
|
706
|
+
break;
|
|
707
|
+
default:
|
|
708
|
+
sections.header = [];
|
|
709
|
+
}
|
|
710
|
+
sections.body = rows.map((row, rowIndex) => buildRow(config, row, "body", rowIndex, rows, inputData));
|
|
711
|
+
sections.footer = config.table.footer instanceof Array && config.table.footer.length > 0 ? [config.table.footer] : [];
|
|
712
|
+
sections.footer = sections.footer.map((row) => buildRow(config, row, "footer", null, rows, inputData));
|
|
713
|
+
for (let a = 0; a < 3; a++) {
|
|
714
|
+
borders[a] = borderStyle[a].l;
|
|
715
|
+
config.table.columnWidths.forEach((columnWidth, index, arr) => {
|
|
716
|
+
borders[a] += borderStyle[a].h.repeat(Math.max(columnWidth, 2) - 1);
|
|
717
|
+
borders[a] += index + 1 < arr.length ? borderStyle[a].j : "";
|
|
718
|
+
});
|
|
719
|
+
borders[a] += borderStyle[a].r;
|
|
720
|
+
borders[a] = a < 2 ? `${marginLeft + borders[a]}
|
|
721
|
+
` : marginLeft + borders[a];
|
|
722
|
+
}
|
|
723
|
+
const output = [borders[0]];
|
|
724
|
+
for (const [sectionIndex, sectionName] of Object.keys(sections).entries()) {
|
|
725
|
+
const section = sections[sectionName];
|
|
726
|
+
for (let rowIndex = 0; rowIndex < section.length; rowIndex++) {
|
|
727
|
+
const row = section[rowIndex];
|
|
728
|
+
row.forEach((line) => {
|
|
729
|
+
output.push(marginLeft + borderStyle[1].v + line.join(borderStyle[1].v) + borderStyle[1].v + "\n");
|
|
730
|
+
});
|
|
731
|
+
switch (true) {
|
|
732
|
+
case (rowIndex === section.length - 1 && sectionIndex === 1 && sections.footer.length === 0):
|
|
733
|
+
break;
|
|
734
|
+
case (rowIndex === section.length - 1 && sectionIndex === 2):
|
|
735
|
+
break;
|
|
736
|
+
case (config.compact && sectionName === "body" && !row.empty):
|
|
737
|
+
break;
|
|
738
|
+
case (config.borderStyle === "none" && config.compact):
|
|
739
|
+
break;
|
|
740
|
+
default:
|
|
741
|
+
output.push(borders[1]);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
output.push(borders[2]);
|
|
746
|
+
const finalOutput = "\n".repeat(config.marginTop) + output.join("");
|
|
747
|
+
config.height = finalOutput.split(/\r\n|\r|\n/).length;
|
|
748
|
+
return finalOutput;
|
|
749
|
+
};
|
|
750
|
+
var buildRow = (config, row, rowType, rowIndex, rowData, inputData) => {
|
|
751
|
+
let minRowHeight = 0;
|
|
752
|
+
if (row.length === 0 && config.compact) {
|
|
753
|
+
row.empty = true;
|
|
754
|
+
return row;
|
|
755
|
+
}
|
|
756
|
+
const lengthDifference = config.table.columnWidths.length - row.length;
|
|
757
|
+
if (lengthDifference > 0) row = row.concat(Array.apply(null, new Array(lengthDifference)).map(() => null));
|
|
758
|
+
else if (lengthDifference < 0) row.length = config.table.columnWidths.length;
|
|
759
|
+
row = row.map((elem, elemIndex) => {
|
|
760
|
+
const cell = buildCell(config, elem, elemIndex, rowType, rowIndex, rowData, inputData);
|
|
761
|
+
minRowHeight = minRowHeight < cell.length ? cell.length : minRowHeight;
|
|
762
|
+
return cell;
|
|
763
|
+
});
|
|
764
|
+
minRowHeight = rowType === "header" ? minRowHeight : minRowHeight + (config.paddingBottom + config.paddingTop);
|
|
765
|
+
const linedRow = Array.apply(null, { length: minRowHeight }).map(Function.call, () => []);
|
|
766
|
+
row.forEach(function(cell, a) {
|
|
767
|
+
const whitespace = " ".repeat(Math.max(config.table.columnWidths[a] - 1, 0));
|
|
768
|
+
if (rowType === "body") {
|
|
769
|
+
for (let i = 0; i < config.paddingTop; i++) cell.unshift(whitespace);
|
|
770
|
+
for (let i = 0; i < config.paddingBottom; i++) cell.push(whitespace);
|
|
771
|
+
}
|
|
772
|
+
for (let i = 0; i < minRowHeight; i++) linedRow[i].push(typeof cell[i] !== "undefined" ? cell[i] : whitespace);
|
|
773
|
+
});
|
|
774
|
+
return linedRow;
|
|
775
|
+
};
|
|
776
|
+
var buildCell = (config, elem, columnIndex, rowType, rowIndex, rowData, inputData, dryRun = false) => {
|
|
777
|
+
let cellValue = null;
|
|
778
|
+
const cellOptions = Object.assign(
|
|
779
|
+
{ reset: false },
|
|
780
|
+
config,
|
|
781
|
+
rowType !== "header" ? config.columnSettings[columnIndex] : {},
|
|
782
|
+
typeof elem === "object" ? elem : {}
|
|
783
|
+
);
|
|
784
|
+
if (rowType === "header") {
|
|
785
|
+
config.table.columns.push(cellOptions);
|
|
786
|
+
cellValue = cellOptions.alias || cellOptions.value || "";
|
|
787
|
+
} else {
|
|
788
|
+
switch (true) {
|
|
789
|
+
case (typeof elem === "undefined" || elem === null):
|
|
790
|
+
cellValue = config.errorOnNull ? config.defaultErrorValue : config.defaultValue;
|
|
791
|
+
if (!isColorEnabled()) cellValue = (0, import_strip_ansi3.default)(cellValue);
|
|
792
|
+
cellOptions.isNull = true;
|
|
793
|
+
break;
|
|
794
|
+
case (typeof elem === "object" && elem !== null && typeof elem.value !== "undefined"):
|
|
795
|
+
cellValue = elem.value;
|
|
796
|
+
break;
|
|
797
|
+
case typeof elem === "function":
|
|
798
|
+
cellValue = elem.bind({
|
|
799
|
+
configure: function(object) {
|
|
800
|
+
return Object.assign(cellOptions, object);
|
|
801
|
+
},
|
|
802
|
+
style,
|
|
803
|
+
resetStyle
|
|
804
|
+
})(cellValue, columnIndex, rowIndex, rowData, inputData);
|
|
805
|
+
break;
|
|
806
|
+
default:
|
|
807
|
+
cellValue = elem;
|
|
808
|
+
}
|
|
809
|
+
if (rowType === "body" && typeof cellOptions.formatter === "function") {
|
|
810
|
+
cellValue = cellOptions.formatter.bind({
|
|
811
|
+
configure: function(object) {
|
|
812
|
+
return Object.assign(cellOptions, object);
|
|
813
|
+
},
|
|
814
|
+
style,
|
|
815
|
+
resetStyle
|
|
816
|
+
})(cellValue, columnIndex, rowIndex, rowData, inputData);
|
|
817
|
+
}
|
|
818
|
+
if (dryRun) return cellValue;
|
|
819
|
+
}
|
|
820
|
+
if (!cellOptions.reset) cellValue = colorizeCell(cellValue, cellOptions, rowType);
|
|
821
|
+
const { cell, innerWidth } = wrapCellText(cellOptions, cellValue, columnIndex, cellOptions, rowType);
|
|
822
|
+
if (rowType === "header") config.table.columnInnerWidths.push(innerWidth);
|
|
823
|
+
return cell;
|
|
824
|
+
};
|
|
825
|
+
var getConstructorGeometry = (row, config) => {
|
|
826
|
+
let type;
|
|
827
|
+
if (typeof row === "object" && !(row instanceof Array)) {
|
|
828
|
+
const keys = Object.keys(row);
|
|
829
|
+
if (config.adapter === "automattic") {
|
|
830
|
+
const key = keys[0];
|
|
831
|
+
type = row[key] instanceof Array ? "automattic-cross" : "automattic-vertical";
|
|
832
|
+
} else type = "o-horizontal";
|
|
833
|
+
} else type = "a-horizontal";
|
|
834
|
+
return type;
|
|
835
|
+
};
|
|
836
|
+
var coerceConstructorGeometry = (config, rows, constructorType) => {
|
|
837
|
+
let output = [];
|
|
838
|
+
switch (constructorType) {
|
|
839
|
+
case "automattic-cross":
|
|
840
|
+
config.columnSettings[0] = config.columnSettings[0] || {};
|
|
841
|
+
config.columnSettings[0].color = config.headerColor;
|
|
842
|
+
output = rows.map((obj) => {
|
|
843
|
+
const key = Object.keys(obj)[0];
|
|
844
|
+
return [key].concat(obj[key]);
|
|
845
|
+
});
|
|
846
|
+
break;
|
|
847
|
+
case "automattic-vertical":
|
|
848
|
+
config.columnSettings[0] = config.columnSettings[0] || {};
|
|
849
|
+
config.columnSettings[0].color = config.headerColor;
|
|
850
|
+
output = rows.map((value) => {
|
|
851
|
+
const key = Object.keys(value)[0];
|
|
852
|
+
return [key, value[key]];
|
|
853
|
+
});
|
|
854
|
+
break;
|
|
855
|
+
case "o-horizontal":
|
|
856
|
+
if (config.table.header[0].length && config.table.header[0].every((obj) => obj.value)) {
|
|
857
|
+
output = rows.map((row) => config.table.header[0].map((obj) => row[obj.value]));
|
|
858
|
+
} else output = rows.map((obj) => Object.values(obj));
|
|
859
|
+
break;
|
|
860
|
+
case "a-horizontal":
|
|
861
|
+
output = rows;
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
return output;
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// src/factory.ts
|
|
868
|
+
var counter = 0;
|
|
869
|
+
var Factory = function(paramsArr) {
|
|
870
|
+
const _configKey = Symbol.config;
|
|
871
|
+
let header = [];
|
|
872
|
+
const body = [];
|
|
873
|
+
let footer = [];
|
|
874
|
+
let options = {};
|
|
875
|
+
switch (true) {
|
|
876
|
+
// header, rows, footer, and options
|
|
877
|
+
case paramsArr.length === 4:
|
|
878
|
+
header = paramsArr[0];
|
|
879
|
+
body.push(...paramsArr[1]);
|
|
880
|
+
footer = paramsArr[2];
|
|
881
|
+
options = paramsArr[3];
|
|
882
|
+
break;
|
|
883
|
+
// header, rows, footer
|
|
884
|
+
case (paramsArr.length === 3 && paramsArr[2] instanceof Array):
|
|
885
|
+
header = paramsArr[0];
|
|
886
|
+
body.push(...paramsArr[1]);
|
|
887
|
+
footer = paramsArr[2];
|
|
888
|
+
break;
|
|
889
|
+
// header, rows, options
|
|
890
|
+
case (paramsArr.length === 3 && typeof paramsArr[2] === "object"):
|
|
891
|
+
header = paramsArr[0];
|
|
892
|
+
body.push(...paramsArr[1]);
|
|
893
|
+
options = paramsArr[2];
|
|
894
|
+
break;
|
|
895
|
+
// header, rows (rows, footer is not an option)
|
|
896
|
+
case (paramsArr.length === 2 && paramsArr[1] instanceof Array):
|
|
897
|
+
header = paramsArr[0];
|
|
898
|
+
body.push(...paramsArr[1]);
|
|
899
|
+
break;
|
|
900
|
+
// rows, options
|
|
901
|
+
case (paramsArr.length === 2 && typeof paramsArr[1] === "object"):
|
|
902
|
+
body.push(...paramsArr[0]);
|
|
903
|
+
options = paramsArr[1];
|
|
904
|
+
break;
|
|
905
|
+
// rows
|
|
906
|
+
case (paramsArr.length === 1 && paramsArr[0] instanceof Array):
|
|
907
|
+
body.push(...paramsArr[0]);
|
|
908
|
+
break;
|
|
909
|
+
// adapter called: i.e. `require('tty-table')('automattic-cli-table')`
|
|
910
|
+
case (paramsArr.length === 1 && typeof paramsArr[0] === "string"): {
|
|
911
|
+
const adapters = {
|
|
912
|
+
"automattic-cli-table": () => require("../adapters/automattic-cli-table.js"),
|
|
913
|
+
"default-adapter": () => require("../adapters/default-adapter.js"),
|
|
914
|
+
"terminal-adapter": () => require("../adapters/terminal-adapter.js")
|
|
915
|
+
};
|
|
916
|
+
const load = adapters[paramsArr[0]];
|
|
917
|
+
if (!load) throw new Error(`Unknown adapter: "${paramsArr[0]}". Available adapters: ${Object.keys(adapters).join(", ")}`);
|
|
918
|
+
return load();
|
|
919
|
+
}
|
|
920
|
+
/* istanbul ignore next */
|
|
921
|
+
default:
|
|
922
|
+
console.log("Error: Bad params. \nSee docs at github.com/tecfu/tty-table");
|
|
923
|
+
process.exit();
|
|
924
|
+
}
|
|
925
|
+
const cloneddefaults = JSON.parse(JSON.stringify(defaults_default));
|
|
926
|
+
const config = Object.assign({}, cloneddefaults, options);
|
|
927
|
+
config.align = config.alignment || config.align;
|
|
928
|
+
config.headerAlign = config.headerAlignment || config.headerAlign;
|
|
929
|
+
if (config.truncate === true) config.truncate = "";
|
|
930
|
+
if (config.borderColor) {
|
|
931
|
+
config.borderCharacters[config.borderStyle] = config.borderCharacters[config.borderStyle].map(function(obj) {
|
|
932
|
+
Object.keys(obj).forEach(function(key) {
|
|
933
|
+
obj[key] = style(obj[key], config.borderColor);
|
|
934
|
+
});
|
|
935
|
+
return obj;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
config.columnSettings = header.slice(0);
|
|
939
|
+
config.table.header = header;
|
|
940
|
+
config.table.header = [config.table.header];
|
|
941
|
+
config.table.footer = footer;
|
|
942
|
+
if (config.terminalAdapter !== true) {
|
|
943
|
+
counter++;
|
|
944
|
+
}
|
|
945
|
+
config.tableId = counter;
|
|
946
|
+
const tableObject = Object.create(body);
|
|
947
|
+
tableObject[_configKey] = config;
|
|
948
|
+
tableObject.render = function() {
|
|
949
|
+
const output = stringifyData(this[_configKey], this.slice(0));
|
|
950
|
+
tableObject.height = this[_configKey].height;
|
|
951
|
+
return output;
|
|
952
|
+
};
|
|
953
|
+
return tableObject;
|
|
954
|
+
};
|
|
955
|
+
var Table = function(...params) {
|
|
956
|
+
return Factory(params);
|
|
957
|
+
};
|
|
958
|
+
Table.resetStyle = resetStyle;
|
|
959
|
+
Table.style = styleEachChar;
|
|
960
|
+
var factory_default = Table;
|
|
961
|
+
|
|
962
|
+
// src/index.ts
|
|
963
|
+
var src_default = factory_default;
|
|
964
|
+
|
|
965
|
+
// package.json
|
|
966
|
+
var package_default = {
|
|
967
|
+
name: "tty-table",
|
|
968
|
+
version: "6.1.0",
|
|
969
|
+
description: "Typed terminal table renderer for Node.js and browsers",
|
|
970
|
+
main: "dist/index.js",
|
|
971
|
+
module: "dist/index.mjs",
|
|
972
|
+
types: "dist/index.d.ts",
|
|
973
|
+
browser: "dist/browser/tty-table.global.js",
|
|
974
|
+
exports: {
|
|
975
|
+
".": {
|
|
976
|
+
types: "./dist/index.d.ts",
|
|
977
|
+
import: "./dist/index.mjs",
|
|
978
|
+
require: "./dist/index.js"
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
engines: {
|
|
982
|
+
node: ">=20"
|
|
983
|
+
},
|
|
984
|
+
bin: {
|
|
985
|
+
"tty-table": "adapters/terminal-adapter.js",
|
|
986
|
+
"tty-table-mcp": "dist/mcp.js"
|
|
987
|
+
},
|
|
988
|
+
files: [
|
|
989
|
+
"dist/",
|
|
990
|
+
"adapters/",
|
|
991
|
+
"README.md",
|
|
992
|
+
"LICENSE.txt"
|
|
993
|
+
],
|
|
994
|
+
scripts: {
|
|
995
|
+
build: "tsup && tsup --config tsup.browser.config.ts",
|
|
996
|
+
test: "npx mocha",
|
|
997
|
+
"test:watch": "vitest",
|
|
998
|
+
typecheck: "tsc --noEmit",
|
|
999
|
+
lint: "eslint .",
|
|
1000
|
+
"lint:fix": "eslint . --fix",
|
|
1001
|
+
prepublishOnly: "npm run typecheck && npm run build && npm test && npm run test:unit",
|
|
1002
|
+
"test:unit": "vitest run",
|
|
1003
|
+
"view-examples": "node npm_scripts/run-examples.js view",
|
|
1004
|
+
"save-tests": "node npm_scripts/run-examples.js save"
|
|
1005
|
+
},
|
|
1006
|
+
repository: {
|
|
1007
|
+
type: "git",
|
|
1008
|
+
url: "https://github.com/tecfu/tty-table.git"
|
|
1009
|
+
},
|
|
1010
|
+
keywords: [
|
|
1011
|
+
"table",
|
|
1012
|
+
"cli-table",
|
|
1013
|
+
"terminal table",
|
|
1014
|
+
"console table",
|
|
1015
|
+
"ascii table"
|
|
1016
|
+
],
|
|
1017
|
+
author: "Tecfu",
|
|
1018
|
+
license: "MIT",
|
|
1019
|
+
bugs: {
|
|
1020
|
+
url: "https://github.com/tecfu/tty-table/issues"
|
|
1021
|
+
},
|
|
1022
|
+
homepage: "https://github.com/tecfu/tty-table",
|
|
1023
|
+
dependencies: {
|
|
1024
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
1025
|
+
chalk: "^4.1.2",
|
|
1026
|
+
csv: "^6.3.11",
|
|
1027
|
+
kleur: "^4.1.5",
|
|
1028
|
+
smartwrap: "^2.0.2",
|
|
1029
|
+
"strip-ansi": "^6.0.1",
|
|
1030
|
+
wcwidth: "^1.0.1",
|
|
1031
|
+
yargs: "^17.7.2",
|
|
1032
|
+
zod: "^4.6.5"
|
|
1033
|
+
},
|
|
1034
|
+
devDependencies: {
|
|
1035
|
+
"@eslint/js": "^9.30.0",
|
|
1036
|
+
"@types/node": "^22.15.0",
|
|
1037
|
+
"@types/wcwidth": "^1.0.2",
|
|
1038
|
+
"@types/yargs": "^17.0.33",
|
|
1039
|
+
chai: "^4.5.0",
|
|
1040
|
+
commander: "^4.1.1",
|
|
1041
|
+
eslint: "^9.30.0",
|
|
1042
|
+
glob: "^13.0.6",
|
|
1043
|
+
mocha: "^12.0.0",
|
|
1044
|
+
tsup: "^8.5.0",
|
|
1045
|
+
typescript: "^5.8.3",
|
|
1046
|
+
"typescript-eslint": "^8.35.0",
|
|
1047
|
+
vitest: "^4.1.11"
|
|
1048
|
+
},
|
|
1049
|
+
defaultTestColumns: 90
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
// src/mcp.ts
|
|
1053
|
+
var headerEntry = import_zod.z.union([
|
|
1054
|
+
import_zod.z.string(),
|
|
1055
|
+
import_zod.z.object({
|
|
1056
|
+
value: import_zod.z.string(),
|
|
1057
|
+
align: import_zod.z.enum(["left", "center", "right"]).optional(),
|
|
1058
|
+
width: import_zod.z.union([import_zod.z.number(), import_zod.z.string()]).optional()
|
|
1059
|
+
})
|
|
1060
|
+
]);
|
|
1061
|
+
var renderTableInputSchema = {
|
|
1062
|
+
header: import_zod.z.array(headerEntry).optional().describe("Column definitions: names, or {value, align, width} objects"),
|
|
1063
|
+
rows: import_zod.z.array(import_zod.z.union([import_zod.z.array(import_zod.z.unknown()), import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())])).describe("Row data: arrays of cells, or objects keyed by column name"),
|
|
1064
|
+
options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional().describe('tty-table options, e.g. {width: 80, borderStyle: "solid"}')
|
|
1065
|
+
};
|
|
1066
|
+
function handleRenderTable({ header, rows, options }) {
|
|
1067
|
+
try {
|
|
1068
|
+
const opts = options ?? {};
|
|
1069
|
+
const head = header;
|
|
1070
|
+
const table = head?.length ? src_default(head, rows, opts) : src_default(rows, opts);
|
|
1071
|
+
return { content: [{ type: "text", text: table.render() }] };
|
|
1072
|
+
} catch (error) {
|
|
1073
|
+
return {
|
|
1074
|
+
isError: true,
|
|
1075
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }]
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
function createMcpServer() {
|
|
1080
|
+
const server = new import_mcp.McpServer({ name: "tty-table", version: package_default.version });
|
|
1081
|
+
server.registerTool(
|
|
1082
|
+
"render_table",
|
|
1083
|
+
{
|
|
1084
|
+
title: "Render a terminal table",
|
|
1085
|
+
description: "Render data as an ASCII/Unicode terminal table (tty-table). Pass header (column names or {value, align, width} objects), rows (array of arrays, or objects whose keys match the header), and optional options (any tty-table table option, e.g. width, borderStyle, align, compact). Returns the rendered table as text.",
|
|
1086
|
+
inputSchema: renderTableInputSchema
|
|
1087
|
+
},
|
|
1088
|
+
(args) => handleRenderTable(args)
|
|
1089
|
+
);
|
|
1090
|
+
return server;
|
|
1091
|
+
}
|
|
1092
|
+
var isMain = typeof process !== "undefined" && process.argv[1] && (process.argv[1].endsWith("mcp.js") || process.argv[1].endsWith("mcp.mjs") || process.argv[1].endsWith("mcp.ts") || process.argv[1].includes("tty-table-mcp"));
|
|
1093
|
+
if (isMain) {
|
|
1094
|
+
const server = createMcpServer();
|
|
1095
|
+
void server.connect(new import_stdio.StdioServerTransport()).catch((error) => {
|
|
1096
|
+
process.stderr.write(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
1097
|
+
process.exit(1);
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1101
|
+
0 && (module.exports = {
|
|
1102
|
+
createMcpServer,
|
|
1103
|
+
handleRenderTable,
|
|
1104
|
+
renderTableInputSchema
|
|
1105
|
+
});
|
|
1106
|
+
;if (typeof module !== "undefined" && typeof module.exports?.default === "function") { module.exports = Object.assign(module.exports.default, module.exports) }
|
|
1107
|
+
//# sourceMappingURL=mcp.js.map
|