tty-table 6.0.1 → 7.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/dist/cli.js CHANGED
@@ -26,351 +26,181 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
 
29
- // node_modules/clone/clone.js
30
- var require_clone = __commonJS({
31
- "node_modules/clone/clone.js"(exports2, module2) {
29
+ // node_modules/breakword/src/main.js
30
+ var require_main = __commonJS({
31
+ "node_modules/breakword/src/main.js"(exports2, module2) {
32
32
  "use strict";
33
- var clone = (function() {
34
- "use strict";
35
- function clone2(parent, circular, depth, prototype) {
36
- var filter;
37
- if (typeof circular === "object") {
38
- depth = circular.depth;
39
- prototype = circular.prototype;
40
- filter = circular.filter;
41
- circular = circular.circular;
42
- }
43
- var allParents = [];
44
- var allChildren = [];
45
- var useBuffer = typeof Buffer != "undefined";
46
- if (typeof circular == "undefined")
47
- circular = true;
48
- if (typeof depth == "undefined")
49
- depth = Infinity;
50
- function _clone(parent2, depth2) {
51
- if (parent2 === null)
52
- return null;
53
- if (depth2 == 0)
54
- return parent2;
55
- var child;
56
- var proto;
57
- if (typeof parent2 != "object") {
58
- return parent2;
59
- }
60
- if (clone2.__isArray(parent2)) {
61
- child = [];
62
- } else if (clone2.__isRegExp(parent2)) {
63
- child = new RegExp(parent2.source, __getRegExpFlags(parent2));
64
- if (parent2.lastIndex) child.lastIndex = parent2.lastIndex;
65
- } else if (clone2.__isDate(parent2)) {
66
- child = new Date(parent2.getTime());
67
- } else if (useBuffer && Buffer.isBuffer(parent2)) {
68
- if (Buffer.allocUnsafe) {
69
- child = Buffer.allocUnsafe(parent2.length);
70
- } else {
71
- child = new Buffer(parent2.length);
72
- }
73
- parent2.copy(child);
74
- return child;
75
- } else {
76
- if (typeof prototype == "undefined") {
77
- proto = Object.getPrototypeOf(parent2);
78
- child = Object.create(proto);
79
- } else {
80
- child = Object.create(prototype);
81
- proto = prototype;
82
- }
83
- }
84
- if (circular) {
85
- var index = allParents.indexOf(parent2);
86
- if (index != -1) {
87
- return allChildren[index];
88
- }
89
- allParents.push(parent2);
90
- allChildren.push(child);
91
- }
92
- for (var i in parent2) {
93
- var attrs;
94
- if (proto) {
95
- attrs = Object.getOwnPropertyDescriptor(proto, i);
96
- }
97
- if (attrs && attrs.set == null) {
98
- continue;
99
- }
100
- child[i] = _clone(parent2[i], depth2 - 1);
101
- }
102
- return child;
103
- }
104
- return _clone(parent, depth);
105
- }
106
- clone2.clonePrototype = function clonePrototype(parent) {
107
- if (parent === null)
108
- return null;
109
- var c = function() {
110
- };
111
- c.prototype = parent;
112
- return new c();
113
- };
114
- function __objToStr(o) {
115
- return Object.prototype.toString.call(o);
116
- }
117
- ;
118
- clone2.__objToStr = __objToStr;
119
- function __isDate(o) {
120
- return typeof o === "object" && __objToStr(o) === "[object Date]";
121
- }
122
- ;
123
- clone2.__isDate = __isDate;
124
- function __isArray(o) {
125
- return typeof o === "object" && __objToStr(o) === "[object Array]";
33
+ var UNICODE_VERSION = "18.0.0";
34
+ var WIDE_RANGES = [
35
+ [4352, 4447],
36
+ [8986, 8987],
37
+ [9001, 9002],
38
+ [9193, 9196],
39
+ [9200, 9200],
40
+ [9203, 9203],
41
+ [9725, 9726],
42
+ [9748, 9749],
43
+ [9776, 9783],
44
+ [9800, 9811],
45
+ [9855, 9855],
46
+ [9866, 9871],
47
+ [9875, 9875],
48
+ [9889, 9889],
49
+ [9898, 9899],
50
+ [9917, 9918],
51
+ [9924, 9925],
52
+ [9934, 9934],
53
+ [9940, 9940],
54
+ [9962, 9962],
55
+ [9970, 9971],
56
+ [9973, 9973],
57
+ [9978, 9978],
58
+ [9981, 9981],
59
+ [9989, 9989],
60
+ [9994, 9995],
61
+ [10024, 10024],
62
+ [10060, 10060],
63
+ [10062, 10062],
64
+ [10067, 10069],
65
+ [10071, 10071],
66
+ [10133, 10135],
67
+ [10160, 10160],
68
+ [10175, 10175],
69
+ [11035, 11036],
70
+ [11088, 11088],
71
+ [11093, 11093],
72
+ [11904, 11929],
73
+ [11931, 12019],
74
+ [12032, 12245],
75
+ [12272, 12350],
76
+ [12353, 12438],
77
+ [12441, 12543],
78
+ [12549, 12591],
79
+ [12593, 12686],
80
+ [12688, 12773],
81
+ [12783, 12830],
82
+ [12832, 12871],
83
+ [12880, 42124],
84
+ [42128, 42182],
85
+ [43360, 43388],
86
+ [44032, 55203],
87
+ [63744, 64255],
88
+ [65040, 65049],
89
+ [65072, 65106],
90
+ [65108, 65126],
91
+ [65128, 65131],
92
+ [65281, 65376],
93
+ [65504, 65510],
94
+ [94176, 94180],
95
+ [94192, 94198],
96
+ [94208, 101594],
97
+ [101631, 101664],
98
+ [101760, 101874],
99
+ [101888, 102801],
100
+ [102816, 102866],
101
+ [110576, 110579],
102
+ [110581, 110587],
103
+ [110589, 110590],
104
+ [110592, 110888],
105
+ [110898, 110898],
106
+ [110928, 110930],
107
+ [110933, 110933],
108
+ [110948, 110952],
109
+ [110960, 111355],
110
+ [119552, 119638],
111
+ [119648, 119670],
112
+ [126980, 126980],
113
+ [127183, 127183],
114
+ [127374, 127374],
115
+ [127377, 127386],
116
+ [127406, 127406],
117
+ [127488, 127490],
118
+ [127504, 127547],
119
+ [127552, 127560],
120
+ [127568, 127569],
121
+ [127584, 127589],
122
+ [127744, 127776],
123
+ [127789, 127797],
124
+ [127799, 127868],
125
+ [127870, 127891],
126
+ [127904, 127946],
127
+ [127951, 127955],
128
+ [127968, 127984],
129
+ [127988, 127988],
130
+ [127992, 128062],
131
+ [128064, 128064],
132
+ [128066, 128252],
133
+ [128255, 128317],
134
+ [128331, 128334],
135
+ [128336, 128359],
136
+ [128378, 128378],
137
+ [128405, 128406],
138
+ [128420, 128420],
139
+ [128507, 128591],
140
+ [128640, 128709],
141
+ [128716, 128716],
142
+ [128720, 128722],
143
+ [128725, 128729],
144
+ [128732, 128735],
145
+ [128747, 128748],
146
+ [128756, 128764],
147
+ [128986, 128986],
148
+ [128992, 129003],
149
+ [129008, 129008],
150
+ [129292, 129338],
151
+ [129340, 129349],
152
+ [129351, 129535],
153
+ [129648, 129660],
154
+ [129664, 129734],
155
+ [129736, 129736],
156
+ [129740, 129757],
157
+ [129759, 129771],
158
+ [129775, 129786],
159
+ [131072, 196605],
160
+ [196608, 262141]
161
+ ];
162
+ var cell = (cp) => cp <= 65535 ? `\\u${cp.toString(16).toUpperCase().padStart(4, "0")}` : `\\u{${cp.toString(16).toUpperCase()}}`;
163
+ var WIDE = new RegExp(
164
+ "[" + WIDE_RANGES.map(([lo, hi]) => cell(lo) + (hi > lo ? `-${cell(hi)}` : "")).join("") + "]",
165
+ "u"
166
+ );
167
+ var ZERO = /[\u200B\p{Mn}\p{Me}\p{Cf}\u1160-\u11FF]/u;
168
+ var EMOJI = /\p{Emoji_Presentation}/u;
169
+ function width(char) {
170
+ if (typeof char !== "string") {
171
+ throw new TypeError("width() expects a string");
126
172
  }
127
- ;
128
- clone2.__isArray = __isArray;
129
- function __isRegExp(o) {
130
- return typeof o === "object" && __objToStr(o) === "[object RegExp]";
173
+ if (char.length === 0) {
174
+ return 0;
131
175
  }
132
- ;
133
- clone2.__isRegExp = __isRegExp;
134
- function __getRegExpFlags(re) {
135
- var flags = "";
136
- if (re.global) flags += "g";
137
- if (re.ignoreCase) flags += "i";
138
- if (re.multiline) flags += "m";
139
- return flags;
176
+ if (char.length > 1 && [...char].length > 1) {
177
+ throw new TypeError("width() expects exactly one Unicode code point");
140
178
  }
141
- ;
142
- clone2.__getRegExpFlags = __getRegExpFlags;
143
- return clone2;
144
- })();
145
- if (typeof module2 === "object" && module2.exports) {
146
- module2.exports = clone;
179
+ const cp = char.codePointAt(0);
180
+ if (cp < 32 || cp >= 127 && cp < 160) return 0;
181
+ if (cp === 173) return 1;
182
+ if (ZERO.test(char)) return 0;
183
+ if (EMOJI.test(char) && !(cp >= 127462 && cp <= 127487)) return 2;
184
+ return WIDE.test(char) ? 2 : 1;
147
185
  }
148
- }
149
- });
150
-
151
- // node_modules/defaults/index.js
152
- var require_defaults = __commonJS({
153
- "node_modules/defaults/index.js"(exports2, module2) {
154
- "use strict";
155
- var clone = require_clone();
156
- module2.exports = function(options, defaults2) {
157
- options = options || {};
158
- Object.keys(defaults2).forEach(function(key) {
159
- if (typeof options[key] === "undefined") {
160
- options[key] = clone(defaults2[key]);
186
+ module2.exports = function breakword2(input, breakAtLength) {
187
+ const str = String(input);
188
+ let indexOfLastFitChar = 0;
189
+ let fittableLength = 0;
190
+ let index = 0;
191
+ for (const char of str) {
192
+ const currentLength = fittableLength + width(char);
193
+ if (currentLength > breakAtLength) {
194
+ break;
161
195
  }
162
- });
163
- return options;
164
- };
165
- }
166
- });
167
-
168
- // node_modules/wcwidth/combining.js
169
- var require_combining = __commonJS({
170
- "node_modules/wcwidth/combining.js"(exports2, module2) {
171
- "use strict";
172
- module2.exports = [
173
- [768, 879],
174
- [1155, 1158],
175
- [1160, 1161],
176
- [1425, 1469],
177
- [1471, 1471],
178
- [1473, 1474],
179
- [1476, 1477],
180
- [1479, 1479],
181
- [1536, 1539],
182
- [1552, 1557],
183
- [1611, 1630],
184
- [1648, 1648],
185
- [1750, 1764],
186
- [1767, 1768],
187
- [1770, 1773],
188
- [1807, 1807],
189
- [1809, 1809],
190
- [1840, 1866],
191
- [1958, 1968],
192
- [2027, 2035],
193
- [2305, 2306],
194
- [2364, 2364],
195
- [2369, 2376],
196
- [2381, 2381],
197
- [2385, 2388],
198
- [2402, 2403],
199
- [2433, 2433],
200
- [2492, 2492],
201
- [2497, 2500],
202
- [2509, 2509],
203
- [2530, 2531],
204
- [2561, 2562],
205
- [2620, 2620],
206
- [2625, 2626],
207
- [2631, 2632],
208
- [2635, 2637],
209
- [2672, 2673],
210
- [2689, 2690],
211
- [2748, 2748],
212
- [2753, 2757],
213
- [2759, 2760],
214
- [2765, 2765],
215
- [2786, 2787],
216
- [2817, 2817],
217
- [2876, 2876],
218
- [2879, 2879],
219
- [2881, 2883],
220
- [2893, 2893],
221
- [2902, 2902],
222
- [2946, 2946],
223
- [3008, 3008],
224
- [3021, 3021],
225
- [3134, 3136],
226
- [3142, 3144],
227
- [3146, 3149],
228
- [3157, 3158],
229
- [3260, 3260],
230
- [3263, 3263],
231
- [3270, 3270],
232
- [3276, 3277],
233
- [3298, 3299],
234
- [3393, 3395],
235
- [3405, 3405],
236
- [3530, 3530],
237
- [3538, 3540],
238
- [3542, 3542],
239
- [3633, 3633],
240
- [3636, 3642],
241
- [3655, 3662],
242
- [3761, 3761],
243
- [3764, 3769],
244
- [3771, 3772],
245
- [3784, 3789],
246
- [3864, 3865],
247
- [3893, 3893],
248
- [3895, 3895],
249
- [3897, 3897],
250
- [3953, 3966],
251
- [3968, 3972],
252
- [3974, 3975],
253
- [3984, 3991],
254
- [3993, 4028],
255
- [4038, 4038],
256
- [4141, 4144],
257
- [4146, 4146],
258
- [4150, 4151],
259
- [4153, 4153],
260
- [4184, 4185],
261
- [4448, 4607],
262
- [4959, 4959],
263
- [5906, 5908],
264
- [5938, 5940],
265
- [5970, 5971],
266
- [6002, 6003],
267
- [6068, 6069],
268
- [6071, 6077],
269
- [6086, 6086],
270
- [6089, 6099],
271
- [6109, 6109],
272
- [6155, 6157],
273
- [6313, 6313],
274
- [6432, 6434],
275
- [6439, 6440],
276
- [6450, 6450],
277
- [6457, 6459],
278
- [6679, 6680],
279
- [6912, 6915],
280
- [6964, 6964],
281
- [6966, 6970],
282
- [6972, 6972],
283
- [6978, 6978],
284
- [7019, 7027],
285
- [7616, 7626],
286
- [7678, 7679],
287
- [8203, 8207],
288
- [8234, 8238],
289
- [8288, 8291],
290
- [8298, 8303],
291
- [8400, 8431],
292
- [12330, 12335],
293
- [12441, 12442],
294
- [43014, 43014],
295
- [43019, 43019],
296
- [43045, 43046],
297
- [64286, 64286],
298
- [65024, 65039],
299
- [65056, 65059],
300
- [65279, 65279],
301
- [65529, 65531],
302
- [68097, 68099],
303
- [68101, 68102],
304
- [68108, 68111],
305
- [68152, 68154],
306
- [68159, 68159],
307
- [119143, 119145],
308
- [119155, 119170],
309
- [119173, 119179],
310
- [119210, 119213],
311
- [119362, 119364],
312
- [917505, 917505],
313
- [917536, 917631],
314
- [917760, 917999]
315
- ];
316
- }
317
- });
318
-
319
- // node_modules/wcwidth/index.js
320
- var require_wcwidth = __commonJS({
321
- "node_modules/wcwidth/index.js"(exports2, module2) {
322
- "use strict";
323
- var defaults2 = require_defaults();
324
- var combining = require_combining();
325
- var DEFAULTS = {
326
- nul: 0,
327
- control: 0
328
- };
329
- module2.exports = function wcwidth3(str) {
330
- return wcswidth(str, DEFAULTS);
331
- };
332
- module2.exports.config = function(opts) {
333
- opts = defaults2(opts || {}, DEFAULTS);
334
- return function wcwidth3(str) {
335
- return wcswidth(str, opts);
336
- };
337
- };
338
- function wcswidth(str, opts) {
339
- if (typeof str !== "string") return wcwidth2(str, opts);
340
- var s = 0;
341
- for (var i = 0; i < str.length; i++) {
342
- var n = wcwidth2(str.charCodeAt(i), opts);
343
- if (n < 0) return -1;
344
- s += n;
345
- }
346
- return s;
347
- }
348
- function wcwidth2(ucs, opts) {
349
- if (ucs === 0) return opts.nul;
350
- if (ucs < 32 || ucs >= 127 && ucs < 160) return opts.control;
351
- if (bisearch(ucs)) return 0;
352
- return 1 + (ucs >= 4352 && (ucs <= 4447 || // Hangul Jamo init. consonants
353
- ucs == 9001 || ucs == 9002 || ucs >= 11904 && ucs <= 42191 && ucs != 12351 || // CJK ... Yi
354
- ucs >= 44032 && ucs <= 55203 || // Hangul Syllables
355
- ucs >= 63744 && ucs <= 64255 || // CJK Compatibility Ideographs
356
- ucs >= 65040 && ucs <= 65049 || // Vertical forms
357
- ucs >= 65072 && ucs <= 65135 || // CJK Compatibility Forms
358
- ucs >= 65280 && ucs <= 65376 || // Fullwidth Forms
359
- ucs >= 65504 && ucs <= 65510 || ucs >= 131072 && ucs <= 196605 || ucs >= 196608 && ucs <= 262141));
360
- }
361
- function bisearch(ucs) {
362
- var min = 0;
363
- var max = combining.length - 1;
364
- var mid;
365
- if (ucs < combining[0][0] || ucs > combining[max][1]) return false;
366
- while (max >= min) {
367
- mid = Math.floor((min + max) / 2);
368
- if (ucs > combining[mid][1]) min = mid + 1;
369
- else if (ucs < combining[mid][0]) max = mid - 1;
370
- else return true;
196
+ indexOfLastFitChar = index;
197
+ fittableLength = currentLength;
198
+ index += 1;
371
199
  }
372
- return false;
373
- }
200
+ return indexOfLastFitChar;
201
+ };
202
+ module2.exports.width = width;
203
+ module2.exports.internals = { UNICODE_VERSION, WIDE_RANGES, WIDE, ZERO, EMOJI, width };
374
204
  }
375
205
  });
376
206
 
@@ -502,20 +332,53 @@ var isColorEnabled = () => {
502
332
  };
503
333
 
504
334
  // src/format.ts
505
- var import_strip_ansi2 = __toESM(require("strip-ansi"));
506
335
  var import_smartwrap = __toESM(require("smartwrap"));
507
- var import_wcwidth = __toESM(require_wcwidth());
336
+
337
+ // src/ansi.ts
338
+ var import_breakword = __toESM(require_main());
339
+ var ANSI = /\u001B\[[0-?]*[ -\/]*[@-~]/g;
340
+ var codes = {
341
+ reset: "0",
342
+ bold: "1",
343
+ dim: "2",
344
+ italic: "3",
345
+ underline: "4",
346
+ inverse: "7",
347
+ hidden: "8",
348
+ strikethrough: "9",
349
+ black: "30",
350
+ red: "31",
351
+ green: "32",
352
+ yellow: "33",
353
+ blue: "34",
354
+ magenta: "35",
355
+ cyan: "36",
356
+ white: "37",
357
+ gray: "90",
358
+ grey: "90",
359
+ bgBlack: "40",
360
+ bgRed: "41",
361
+ bgGreen: "42",
362
+ bgYellow: "43",
363
+ bgBlue: "44",
364
+ bgMagenta: "45",
365
+ bgCyan: "46",
366
+ bgWhite: "47"
367
+ };
368
+ var stripAnsi2 = (value) => value.replace(ANSI, "");
369
+ var codePointWidth = (value) => [...value].reduce((total, char) => total + import_breakword.default.width(char), 0);
370
+ var displayWidth = (value) => Math.max(0, ...stripAnsi2(value).split(/\r?\n/).map(codePointWidth));
371
+ var style2 = (value, ...styles) => {
372
+ const active = styles.map((s) => codes[s]).filter(Boolean);
373
+ return active.length ? `\x1B[${active.join(";")}m${value}\x1B[0m` : value;
374
+ };
375
+
376
+ // src/format.ts
508
377
  var addPadding = (config, width) => {
509
378
  return width + config.paddingLeft + config.paddingRight;
510
379
  };
511
380
  var getDisplayWidth = (value) => {
512
- const lines = (0, import_strip_ansi2.default)(value.toString()).split(/[\n\r]/);
513
- let widest = 0;
514
- for (const line of lines) {
515
- const width = (0, import_wcwidth.default)(line);
516
- if (width > widest) widest = width;
517
- }
518
- return widest;
381
+ return displayWidth(value.toString());
519
382
  };
520
383
  var getMaxLength = (columnOptions, rows, columnIndex) => {
521
384
  let widest = 0;
@@ -549,7 +412,7 @@ var getAvailableWidth = (config) => {
549
412
  return config.COLUMNS - config.marginLeft;
550
413
  };
551
414
  var getStringLength = (str) => {
552
- return (0, import_wcwidth.default)((0, import_strip_ansi2.default)(str));
415
+ return displayWidth(str);
553
416
  };
554
417
  var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
555
418
  const startAnsiRegexp = /^(\x1b\[[0-9;]*m)+/;
@@ -608,10 +471,10 @@ var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
608
471
  return { cell, innerWidth };
609
472
  };
610
473
  var truncate = (str, cellOptions, maxWidth) => {
611
- const stringWidth = (0, import_wcwidth.default)(str);
474
+ const stringWidth = displayWidth(str);
612
475
  if (maxWidth < stringWidth) {
613
476
  str = (0, import_smartwrap.default)(str, {
614
- width: maxWidth - cellOptions.truncate.length,
477
+ width: maxWidth - displayWidth(cellOptions.truncate),
615
478
  breakword: true
616
479
  }).split("\n")[0];
617
480
  str = str + cellOptions.truncate;
@@ -669,7 +532,7 @@ var getColumnWidths = (config, rows) => {
669
532
  };
670
533
 
671
534
  // src/render.ts
672
- var import_strip_ansi3 = __toESM(require("strip-ansi"));
535
+ var import_strip_ansi2 = __toESM(require("strip-ansi"));
673
536
  var stringifyData = (config, inputData) => {
674
537
  const sections = { header: [], body: [], footer: [] };
675
538
  const marginLeft = " ".repeat(config.marginLeft);
@@ -778,7 +641,7 @@ var buildCell = (config, elem, columnIndex, rowType, rowIndex, rowData, inputDat
778
641
  switch (true) {
779
642
  case (typeof elem === "undefined" || elem === null):
780
643
  cellValue = config.errorOnNull ? config.defaultErrorValue : config.defaultValue;
781
- if (!isColorEnabled()) cellValue = (0, import_strip_ansi3.default)(cellValue);
644
+ if (!isColorEnabled()) cellValue = (0, import_strip_ansi2.default)(cellValue);
782
645
  cellOptions.isNull = true;
783
646
  break;
784
647
  case (typeof elem === "object" && elem !== null && typeof elem.value !== "undefined"):
@@ -952,40 +815,6 @@ var factory_default = Table;
952
815
  // src/index.ts
953
816
  var src_default = factory_default;
954
817
 
955
- // src/ansi.ts
956
- var codes = {
957
- reset: "0",
958
- bold: "1",
959
- dim: "2",
960
- italic: "3",
961
- underline: "4",
962
- inverse: "7",
963
- hidden: "8",
964
- strikethrough: "9",
965
- black: "30",
966
- red: "31",
967
- green: "32",
968
- yellow: "33",
969
- blue: "34",
970
- magenta: "35",
971
- cyan: "36",
972
- white: "37",
973
- gray: "90",
974
- grey: "90",
975
- bgBlack: "40",
976
- bgRed: "41",
977
- bgGreen: "42",
978
- bgYellow: "43",
979
- bgBlue: "44",
980
- bgMagenta: "45",
981
- bgCyan: "46",
982
- bgWhite: "47"
983
- };
984
- var style2 = (value, ...styles) => {
985
- const active = styles.map((s) => codes[s]).filter(Boolean);
986
- return active.length ? `\x1B[${active.join(";")}m${value}\x1B[0m` : value;
987
- };
988
-
989
818
  // src/cli.ts
990
819
  var main = async () => {
991
820
  const argv = await (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).options({