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/browser.js CHANGED
@@ -30,351 +30,181 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // node_modules/clone/clone.js
34
- var require_clone = __commonJS({
35
- "node_modules/clone/clone.js"(exports2, module2) {
33
+ // node_modules/breakword/src/main.js
34
+ var require_main = __commonJS({
35
+ "node_modules/breakword/src/main.js"(exports2, module2) {
36
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]";
37
+ var UNICODE_VERSION = "18.0.0";
38
+ var WIDE_RANGES = [
39
+ [4352, 4447],
40
+ [8986, 8987],
41
+ [9001, 9002],
42
+ [9193, 9196],
43
+ [9200, 9200],
44
+ [9203, 9203],
45
+ [9725, 9726],
46
+ [9748, 9749],
47
+ [9776, 9783],
48
+ [9800, 9811],
49
+ [9855, 9855],
50
+ [9866, 9871],
51
+ [9875, 9875],
52
+ [9889, 9889],
53
+ [9898, 9899],
54
+ [9917, 9918],
55
+ [9924, 9925],
56
+ [9934, 9934],
57
+ [9940, 9940],
58
+ [9962, 9962],
59
+ [9970, 9971],
60
+ [9973, 9973],
61
+ [9978, 9978],
62
+ [9981, 9981],
63
+ [9989, 9989],
64
+ [9994, 9995],
65
+ [10024, 10024],
66
+ [10060, 10060],
67
+ [10062, 10062],
68
+ [10067, 10069],
69
+ [10071, 10071],
70
+ [10133, 10135],
71
+ [10160, 10160],
72
+ [10175, 10175],
73
+ [11035, 11036],
74
+ [11088, 11088],
75
+ [11093, 11093],
76
+ [11904, 11929],
77
+ [11931, 12019],
78
+ [12032, 12245],
79
+ [12272, 12350],
80
+ [12353, 12438],
81
+ [12441, 12543],
82
+ [12549, 12591],
83
+ [12593, 12686],
84
+ [12688, 12773],
85
+ [12783, 12830],
86
+ [12832, 12871],
87
+ [12880, 42124],
88
+ [42128, 42182],
89
+ [43360, 43388],
90
+ [44032, 55203],
91
+ [63744, 64255],
92
+ [65040, 65049],
93
+ [65072, 65106],
94
+ [65108, 65126],
95
+ [65128, 65131],
96
+ [65281, 65376],
97
+ [65504, 65510],
98
+ [94176, 94180],
99
+ [94192, 94198],
100
+ [94208, 101594],
101
+ [101631, 101664],
102
+ [101760, 101874],
103
+ [101888, 102801],
104
+ [102816, 102866],
105
+ [110576, 110579],
106
+ [110581, 110587],
107
+ [110589, 110590],
108
+ [110592, 110888],
109
+ [110898, 110898],
110
+ [110928, 110930],
111
+ [110933, 110933],
112
+ [110948, 110952],
113
+ [110960, 111355],
114
+ [119552, 119638],
115
+ [119648, 119670],
116
+ [126980, 126980],
117
+ [127183, 127183],
118
+ [127374, 127374],
119
+ [127377, 127386],
120
+ [127406, 127406],
121
+ [127488, 127490],
122
+ [127504, 127547],
123
+ [127552, 127560],
124
+ [127568, 127569],
125
+ [127584, 127589],
126
+ [127744, 127776],
127
+ [127789, 127797],
128
+ [127799, 127868],
129
+ [127870, 127891],
130
+ [127904, 127946],
131
+ [127951, 127955],
132
+ [127968, 127984],
133
+ [127988, 127988],
134
+ [127992, 128062],
135
+ [128064, 128064],
136
+ [128066, 128252],
137
+ [128255, 128317],
138
+ [128331, 128334],
139
+ [128336, 128359],
140
+ [128378, 128378],
141
+ [128405, 128406],
142
+ [128420, 128420],
143
+ [128507, 128591],
144
+ [128640, 128709],
145
+ [128716, 128716],
146
+ [128720, 128722],
147
+ [128725, 128729],
148
+ [128732, 128735],
149
+ [128747, 128748],
150
+ [128756, 128764],
151
+ [128986, 128986],
152
+ [128992, 129003],
153
+ [129008, 129008],
154
+ [129292, 129338],
155
+ [129340, 129349],
156
+ [129351, 129535],
157
+ [129648, 129660],
158
+ [129664, 129734],
159
+ [129736, 129736],
160
+ [129740, 129757],
161
+ [129759, 129771],
162
+ [129775, 129786],
163
+ [131072, 196605],
164
+ [196608, 262141]
165
+ ];
166
+ var cell = (cp) => cp <= 65535 ? `\\u${cp.toString(16).toUpperCase().padStart(4, "0")}` : `\\u{${cp.toString(16).toUpperCase()}}`;
167
+ var WIDE = new RegExp(
168
+ "[" + WIDE_RANGES.map(([lo, hi]) => cell(lo) + (hi > lo ? `-${cell(hi)}` : "")).join("") + "]",
169
+ "u"
170
+ );
171
+ var ZERO = /[\u200B\p{Mn}\p{Me}\p{Cf}\u1160-\u11FF]/u;
172
+ var EMOJI = /\p{Emoji_Presentation}/u;
173
+ function width(char) {
174
+ if (typeof char !== "string") {
175
+ throw new TypeError("width() expects a string");
130
176
  }
131
- ;
132
- clone2.__isArray = __isArray;
133
- function __isRegExp(o) {
134
- return typeof o === "object" && __objToStr(o) === "[object RegExp]";
177
+ if (char.length === 0) {
178
+ return 0;
135
179
  }
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;
180
+ if (char.length > 1 && [...char].length > 1) {
181
+ throw new TypeError("width() expects exactly one Unicode code point");
144
182
  }
145
- ;
146
- clone2.__getRegExpFlags = __getRegExpFlags;
147
- return clone2;
148
- })();
149
- if (typeof module2 === "object" && module2.exports) {
150
- module2.exports = clone;
183
+ const cp = char.codePointAt(0);
184
+ if (cp < 32 || cp >= 127 && cp < 160) return 0;
185
+ if (cp === 173) return 1;
186
+ if (ZERO.test(char)) return 0;
187
+ if (EMOJI.test(char) && !(cp >= 127462 && cp <= 127487)) return 2;
188
+ return WIDE.test(char) ? 2 : 1;
151
189
  }
152
- }
153
- });
154
-
155
- // node_modules/defaults/index.js
156
- var require_defaults = __commonJS({
157
- "node_modules/defaults/index.js"(exports2, module2) {
158
- "use strict";
159
- var clone = require_clone();
160
- module2.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]);
190
+ module2.exports = function breakword2(input, breakAtLength) {
191
+ const str = String(input);
192
+ let indexOfLastFitChar = 0;
193
+ let fittableLength = 0;
194
+ let index = 0;
195
+ for (const char of str) {
196
+ const currentLength = fittableLength + width(char);
197
+ if (currentLength > breakAtLength) {
198
+ break;
165
199
  }
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"(exports2, module2) {
175
- "use strict";
176
- module2.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"(exports2, module2) {
326
- "use strict";
327
- var defaults2 = require_defaults();
328
- var combining = require_combining();
329
- var DEFAULTS = {
330
- nul: 0,
331
- control: 0
332
- };
333
- module2.exports = function wcwidth3(str) {
334
- return wcswidth(str, DEFAULTS);
335
- };
336
- module2.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;
200
+ indexOfLastFitChar = index;
201
+ fittableLength = currentLength;
202
+ index += 1;
375
203
  }
376
- return false;
377
- }
204
+ return indexOfLastFitChar;
205
+ };
206
+ module2.exports.width = width;
207
+ module2.exports.internals = { UNICODE_VERSION, WIDE_RANGES, WIDE, ZERO, EMOJI, width };
378
208
  }
379
209
  });
380
210
 
@@ -506,20 +336,21 @@ var isColorEnabled = () => {
506
336
  };
507
337
 
508
338
  // src/format.ts
509
- var import_strip_ansi2 = __toESM(require("strip-ansi"));
510
339
  var import_smartwrap = __toESM(require("smartwrap"));
511
- var import_wcwidth = __toESM(require_wcwidth());
340
+
341
+ // src/ansi.ts
342
+ var import_breakword = __toESM(require_main());
343
+ var ANSI = /\u001B\[[0-?]*[ -\/]*[@-~]/g;
344
+ var stripAnsi2 = (value) => value.replace(ANSI, "");
345
+ var codePointWidth = (value) => [...value].reduce((total, char) => total + import_breakword.default.width(char), 0);
346
+ var displayWidth = (value) => Math.max(0, ...stripAnsi2(value).split(/\r?\n/).map(codePointWidth));
347
+
348
+ // src/format.ts
512
349
  var addPadding = (config, width) => {
513
350
  return width + config.paddingLeft + config.paddingRight;
514
351
  };
515
352
  var getDisplayWidth = (value) => {
516
- const lines = (0, import_strip_ansi2.default)(value.toString()).split(/[\n\r]/);
517
- let widest = 0;
518
- for (const line of lines) {
519
- const width = (0, import_wcwidth.default)(line);
520
- if (width > widest) widest = width;
521
- }
522
- return widest;
353
+ return displayWidth(value.toString());
523
354
  };
524
355
  var getMaxLength = (columnOptions, rows, columnIndex) => {
525
356
  let widest = 0;
@@ -553,7 +384,7 @@ var getAvailableWidth = (config) => {
553
384
  return config.COLUMNS - config.marginLeft;
554
385
  };
555
386
  var getStringLength = (str) => {
556
- return (0, import_wcwidth.default)((0, import_strip_ansi2.default)(str));
387
+ return displayWidth(str);
557
388
  };
558
389
  var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
559
390
  const startAnsiRegexp = /^(\x1b\[[0-9;]*m)+/;
@@ -612,10 +443,10 @@ var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
612
443
  return { cell, innerWidth };
613
444
  };
614
445
  var truncate = (str, cellOptions, maxWidth) => {
615
- const stringWidth = (0, import_wcwidth.default)(str);
446
+ const stringWidth = displayWidth(str);
616
447
  if (maxWidth < stringWidth) {
617
448
  str = (0, import_smartwrap.default)(str, {
618
- width: maxWidth - cellOptions.truncate.length,
449
+ width: maxWidth - displayWidth(cellOptions.truncate),
619
450
  breakword: true
620
451
  }).split("\n")[0];
621
452
  str = str + cellOptions.truncate;
@@ -673,7 +504,7 @@ var getColumnWidths = (config, rows) => {
673
504
  };
674
505
 
675
506
  // src/render.ts
676
- var import_strip_ansi3 = __toESM(require("strip-ansi"));
507
+ var import_strip_ansi2 = __toESM(require("strip-ansi"));
677
508
  var stringifyData = (config, inputData) => {
678
509
  const sections = { header: [], body: [], footer: [] };
679
510
  const marginLeft = " ".repeat(config.marginLeft);
@@ -782,7 +613,7 @@ var buildCell = (config, elem, columnIndex, rowType, rowIndex, rowData, inputDat
782
613
  switch (true) {
783
614
  case (typeof elem === "undefined" || elem === null):
784
615
  cellValue = config.errorOnNull ? config.defaultErrorValue : config.defaultValue;
785
- if (!isColorEnabled()) cellValue = (0, import_strip_ansi3.default)(cellValue);
616
+ if (!isColorEnabled()) cellValue = (0, import_strip_ansi2.default)(cellValue);
786
617
  cellOptions.isNull = true;
787
618
  break;
788
619
  case (typeof elem === "object" && elem !== null && typeof elem.value !== "undefined"):