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