table 5.2.3 → 5.3.3

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  <a name="table"></a>
2
2
  # Table
3
3
 
4
+ [![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/table?style=flat-square)](https://gitspo.com/mentions/gajus/table)
4
5
  [![Travis build status](http://img.shields.io/travis/gajus/table/master.svg?style=flat-square)](https://travis-ci.org/gajus/table)
5
6
  [![Coveralls](https://img.shields.io/coveralls/gajus/table.svg?style=flat-square)](https://coveralls.io/github/gajus/table)
6
7
  [![NPM version](http://img.shields.io/npm/v/table.svg?style=flat-square)](https://www.npmjs.org/package/table)
@@ -9,6 +10,7 @@
9
10
 
10
11
  * [Table](#table)
11
12
  * [Features](#table-features)
13
+ * [Install](#table-install)
12
14
  * [Usage](#table-usage)
13
15
  * [Cell Content Alignment](#table-usage-cell-content-alignment)
14
16
  * [Column Width](#table-usage-column-width)
@@ -36,6 +38,17 @@ Produces a string that represents array data in a text table.
36
38
  * Configurable column width.
37
39
  * Text wrapping.
38
40
 
41
+ <a name="table-install"></a>
42
+ ## Install
43
+
44
+ ```bash
45
+ npm install table
46
+
47
+ ```
48
+
49
+ [![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/gajus)
50
+ [![Become a Patron](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/gajus)
51
+
39
52
  <a name="table-usage"></a>
40
53
  ## Usage
41
54
 
@@ -132,6 +145,7 @@ console.log(output);
132
145
  ╟────┼────┼────╢
133
146
  ║ 2A │ 2B │ 2C ║
134
147
  ╚════╧════╧════╝
148
+
135
149
  ```
136
150
 
137
151
 
@@ -144,30 +158,30 @@ Valid values are: "left", "right" and "center".
144
158
 
145
159
  ```js
146
160
  let config,
147
- data,
148
- output;
161
+ data,
162
+ output;
149
163
 
150
164
  data = [
151
- ['0A', '0B', '0C'],
152
- ['1A', '1B', '1C'],
153
- ['2A', '2B', '2C']
165
+ ['0A', '0B', '0C'],
166
+ ['1A', '1B', '1C'],
167
+ ['2A', '2B', '2C']
154
168
  ];
155
169
 
156
170
  config = {
157
- columns: {
158
- 0: {
159
- alignment: 'left',
160
- minWidth: 10
161
- },
162
- 1: {
163
- alignment: 'center',
164
- minWidth: 10
165
- },
166
- 2: {
167
- alignment: 'right',
168
- minWidth: 10
169
- }
171
+ columns: {
172
+ 0: {
173
+ alignment: 'left',
174
+ minWidth: 10
175
+ },
176
+ 1: {
177
+ alignment: 'center',
178
+ minWidth: 10
179
+ },
180
+ 2: {
181
+ alignment: 'right',
182
+ minWidth: 10
170
183
  }
184
+ }
171
185
  };
172
186
 
173
187
  output = table(data, config);
@@ -192,21 +206,21 @@ console.log(output);
192
206
 
193
207
  ```js
194
208
  let data,
195
- output,
196
- options;
209
+ output,
210
+ options;
197
211
 
198
212
  data = [
199
- ['0A', '0B', '0C'],
200
- ['1A', '1B', '1C'],
201
- ['2A', '2B', '2C']
213
+ ['0A', '0B', '0C'],
214
+ ['1A', '1B', '1C'],
215
+ ['2A', '2B', '2C']
202
216
  ];
203
217
 
204
218
  options = {
205
- columns: {
206
- 1: {
207
- width: 10
208
- }
219
+ columns: {
220
+ 1: {
221
+ width: 10
209
222
  }
223
+ }
210
224
  };
211
225
 
212
226
  output = table(data, options);
@@ -231,36 +245,36 @@ console.log(output);
231
245
 
232
246
  ```js
233
247
  let config,
234
- data,
235
- output;
248
+ data,
249
+ output;
236
250
 
237
251
  data = [
238
- ['0A', '0B', '0C'],
239
- ['1A', '1B', '1C'],
240
- ['2A', '2B', '2C']
252
+ ['0A', '0B', '0C'],
253
+ ['1A', '1B', '1C'],
254
+ ['2A', '2B', '2C']
241
255
  ];
242
256
 
243
257
  config = {
244
- border: {
245
- topBody: `─`,
246
- topJoin: `┬`,
247
- topLeft: `┌`,
248
- topRight: `┐`,
249
-
250
- bottomBody: `─`,
251
- bottomJoin: `┴`,
252
- bottomLeft: `└`,
253
- bottomRight: `┘`,
254
-
255
- bodyLeft: `│`,
256
- bodyRight: `│`,
257
- bodyJoin: `│`,
258
-
259
- joinBody: `─`,
260
- joinLeft: `├`,
261
- joinRight: `┤`,
262
- joinJoin: `┼`
263
- }
258
+ border: {
259
+ topBody: `─`,
260
+ topJoin: `┬`,
261
+ topLeft: `┌`,
262
+ topRight: `┐`,
263
+
264
+ bottomBody: `─`,
265
+ bottomJoin: `┴`,
266
+ bottomLeft: `└`,
267
+ bottomRight: `┘`,
268
+
269
+ bodyLeft: `│`,
270
+ bodyRight: `│`,
271
+ bodyJoin: `│`,
272
+
273
+ joinBody: `─`,
274
+ joinLeft: `├`,
275
+ joinRight: `┤`,
276
+ joinJoin: `┼`
277
+ }
264
278
  };
265
279
 
266
280
  output = table(data, config);
@@ -285,27 +299,27 @@ console.log(output);
285
299
 
286
300
  ```js
287
301
  let data,
288
- output,
289
- options;
302
+ output,
303
+ options;
290
304
 
291
305
  data = [
292
- ['0A', '0B', '0C'],
293
- ['1A', '1B', '1C'],
294
- ['2A', '2B', '2C'],
295
- ['3A', '3B', '3C'],
296
- ['4A', '4B', '4C']
306
+ ['0A', '0B', '0C'],
307
+ ['1A', '1B', '1C'],
308
+ ['2A', '2B', '2C'],
309
+ ['3A', '3B', '3C'],
310
+ ['4A', '4B', '4C']
297
311
  ];
298
312
 
299
313
  options = {
300
- /**
301
- * @typedef {function} drawHorizontalLine
302
- * @param {number} index
303
- * @param {number} size
304
- * @return {boolean}
305
- */
306
- drawHorizontalLine: (index, size) => {
307
- return index === 0 || index === 1 || index === size - 1 || index === size;
308
- }
314
+ /**
315
+ * @typedef {function} drawHorizontalLine
316
+ * @param {number} index
317
+ * @param {number} size
318
+ * @return {boolean}
319
+ */
320
+ drawHorizontalLine: (index, size) => {
321
+ return index === 0 || index === 1 || index === size - 1 || index === size;
322
+ }
309
323
  };
310
324
 
311
325
  output = table(data, options);
@@ -334,25 +348,25 @@ console.log(output);
334
348
 
335
349
  ```js
336
350
  let config,
337
- data,
338
- output;
351
+ data,
352
+ output;
339
353
 
340
354
  data = [
341
- ['0A', 'AABBCC', '0C'],
342
- ['1A', '1B', '1C'],
343
- ['2A', '2B', '2C']
355
+ ['0A', 'AABBCC', '0C'],
356
+ ['1A', '1B', '1C'],
357
+ ['2A', '2B', '2C']
344
358
  ];
345
359
 
346
360
  config = {
347
- columns: {
348
- 0: {
349
- paddingLeft: 3
350
- },
351
- 1: {
352
- width: 2,
353
- paddingRight: 3
354
- }
361
+ columns: {
362
+ 0: {
363
+ paddingLeft: 3
364
+ },
365
+ 1: {
366
+ width: 2,
367
+ paddingRight: 3
355
368
  }
369
+ }
356
370
  };
357
371
 
358
372
  output = table(data, config);
@@ -379,21 +393,21 @@ You can load one of the predefined border templates using `getBorderCharacters`
379
393
 
380
394
  ```js
381
395
  import {
382
- table,
383
- getBorderCharacters
396
+ table,
397
+ getBorderCharacters
384
398
  } from 'table';
385
399
 
386
400
  let config,
387
- data;
401
+ data;
388
402
 
389
403
  data = [
390
- ['0A', '0B', '0C'],
391
- ['1A', '1B', '1C'],
392
- ['2A', '2B', '2C']
404
+ ['0A', '0B', '0C'],
405
+ ['1A', '1B', '1C'],
406
+ ['2A', '2B', '2C']
393
407
  ];
394
408
 
395
409
  config = {
396
- border: getBorderCharacters(`name of the template`)
410
+ border: getBorderCharacters(`name of the template`)
397
411
  };
398
412
 
399
413
  table(data, config);
@@ -481,23 +495,23 @@ console.log(output);
481
495
 
482
496
  ```js
483
497
  import {
484
- createStream
498
+ createStream
485
499
  } from 'table';
486
500
 
487
501
  let config,
488
- stream;
502
+ stream;
489
503
 
490
504
  config = {
491
- columnDefault: {
492
- width: 50
493
- },
494
- columnCount: 1
505
+ columnDefault: {
506
+ width: 50
507
+ },
508
+ columnCount: 1
495
509
  };
496
510
 
497
511
  stream = createStream(config);
498
512
 
499
513
  setInterval(() => {
500
- stream.write([new Date()]);
514
+ stream.write([new Date()]);
501
515
  }, 500);
502
516
  ```
503
517
 
@@ -505,38 +519,38 @@ setInterval(() => {
505
519
 
506
520
  `table` package uses ANSI escape codes to overwrite the output of the last line when a new row is printed.
507
521
 
508
- The underlying implementation is explained in this [Stack Overflow answer](http://stackoverflow.com/a/32938658/368691).
522
+ The underlying implementation is explained in this [Stack Overflow answer](http://stackoverflow.com/a/32938658/368691).
509
523
 
510
524
  Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.
511
525
 
512
526
  ```js
513
527
  import {
514
- createStream
528
+ createStream
515
529
  } from 'table';
516
530
 
517
531
  import _ from 'lodash';
518
532
 
519
533
  let config,
520
- stream,
521
- i;
534
+ stream,
535
+ i;
522
536
 
523
537
  config = {
524
- columnDefault: {
525
- width: 50
538
+ columnDefault: {
539
+ width: 50
540
+ },
541
+ columnCount: 3,
542
+ columns: {
543
+ 0: {
544
+ width: 10,
545
+ alignment: 'right'
546
+ },
547
+ 1: {
548
+ alignment: 'center',
526
549
  },
527
- columnCount: 3,
528
- columns: {
529
- 0: {
530
- width: 10,
531
- alignment: 'right'
532
- },
533
- 1: {
534
- alignment: 'center',
535
- },
536
- 2: {
537
- width: 10
538
- }
550
+ 2: {
551
+ width: 10
539
552
  }
553
+ }
540
554
  };
541
555
 
542
556
  stream = createStream(config);
@@ -544,15 +558,16 @@ stream = createStream(config);
544
558
  i = 0;
545
559
 
546
560
  setInterval(() => {
547
- let random;
561
+ let random;
548
562
 
549
- random = _.sample('abcdefghijklmnopqrstuvwxyz', _.random(1, 30)).join('');
563
+ random = _.sample('abcdefghijklmnopqrstuvwxyz', _.random(1, 30)).join('');
550
564
 
551
- stream.write([i++, new Date(), random]);
565
+ stream.write([i++, new Date(), random]);
552
566
  }, 500);
553
567
  ```
554
568
 
555
569
  ![Streaming random data.](./.README/streaming-random.gif)
570
+
556
571
  <a name="table-usage-text-truncation"></a>
557
572
  ### Text Truncation
558
573
 
@@ -562,20 +577,20 @@ To handle a content that overflows the container width, `table` package implemen
562
577
 
563
578
  ```js
564
579
  let config,
565
- data,
566
- output;
580
+ data,
581
+ output;
567
582
 
568
583
  data = [
569
- ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
584
+ ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
570
585
  ];
571
586
 
572
587
  config = {
573
- columns: {
574
- 0: {
575
- width: 20,
576
- truncate: 100
577
- }
588
+ columns: {
589
+ 0: {
590
+ width: 20,
591
+ truncate: 100
578
592
  }
593
+ }
579
594
  };
580
595
 
581
596
  output = table(data, config);
@@ -600,19 +615,19 @@ console.log(output);
600
615
 
601
616
  ```js
602
617
  let config,
603
- data,
604
- output;
618
+ data,
619
+ output;
605
620
 
606
621
  data = [
607
622
  ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
608
623
  ];
609
624
 
610
625
  config = {
611
- columns: {
612
- 0: {
613
- width: 20
614
- }
626
+ columns: {
627
+ 0: {
628
+ width: 20
615
629
  }
630
+ }
616
631
  };
617
632
 
618
633
  output = table(data, config);
@@ -637,20 +652,20 @@ When `wrapWord` is `true` the text is broken at the nearest space or one of the
637
652
 
638
653
  ```js
639
654
  let config,
640
- data,
641
- output;
655
+ data,
656
+ output;
642
657
 
643
658
  data = [
644
- ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
659
+ ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
645
660
  ];
646
661
 
647
662
  config = {
648
- columns: {
649
- 0: {
650
- width: 20,
651
- wrapWord: true
652
- }
663
+ columns: {
664
+ 0: {
665
+ width: 20,
666
+ wrapWord: true
653
667
  }
668
+ }
654
669
  };
655
670
 
656
671
  output = table(data, config);
@@ -671,5 +686,6 @@ console.log(output);
671
686
  ║ tempus nulla sit ║
672
687
  ║ amet viverra. ║
673
688
  ╚══════════════════════╝
689
+
674
690
  ```
675
691
 
@@ -56,7 +56,7 @@ const validateTableData = rows => {
56
56
  const cell = _step2.value;
57
57
 
58
58
  // eslint-disable-next-line no-control-regex
59
- if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
59
+ if (/[\u0001-\u0006\u0008-\u0009\u000B-\u001A]/.test(cell)) {
60
60
  throw new Error('Table data must not contain control characters.');
61
61
  }
62
62
  }
@@ -36,7 +36,7 @@ export default (rows) => {
36
36
 
37
37
  for (const cell of cells) {
38
38
  // eslint-disable-next-line no-control-regex
39
- if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
39
+ if (/[\u0001-\u0006\u0008-\u0009\u000B-\u001A]/.test(cell)) {
40
40
  throw new Error('Table data must not contain control characters.');
41
41
  }
42
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/validateTableData.js"],"names":["rows","Array","isArray","TypeError","length","Error","columnNumber","cells","cell","test"],"mappings":";;;;;;;AAAA;;;;AAIA;;;;AAIA;;;;0BAIgBA,I,IAAS;AACvB,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACxB,UAAM,IAAIG,SAAJ,CAAc,8BAAd,CAAN;AACD;;AAED,MAAIH,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;AACrB,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,MAAIL,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;AACD;;AAED,QAAMC,YAAY,GAAGN,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAA7B;AAbuB;AAAA;AAAA;;AAAA;AAevB,yBAAoBJ,IAApB,8HAA0B;AAAA,YAAfO,KAAe;;AACxB,UAAI,CAACN,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAL,EAA2B;AACzB,cAAM,IAAIJ,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,UAAII,KAAK,CAACH,MAAN,KAAiBE,YAArB,EAAmC;AACjC,cAAM,IAAID,KAAJ,CAAU,+CAAV,CAAN;AACD;;AAPuB;AAAA;AAAA;;AAAA;AASxB,8BAAmBE,KAAnB,mIAA0B;AAAA,gBAAfC,IAAe;;AACxB;AACA,cAAI,+BAA+BC,IAA/B,CAAoCD,IAApC,CAAJ,EAA+C;AAC7C,kBAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF;AAduB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAezB;AA9BsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BxB,C","sourcesContent":["/**\n * @typedef {string} cell\n */\n\n/**\n * @typedef {cell[]} validateData~column\n */\n\n/**\n * @param {column[]} rows\n * @returns {undefined}\n */\nexport default (rows) => {\n if (!Array.isArray(rows)) {\n throw new TypeError('Table data must be an array.');\n }\n\n if (rows.length === 0) {\n throw new Error('Table must define at least one row.');\n }\n\n if (rows[0].length === 0) {\n throw new Error('Table must define at least one column.');\n }\n\n const columnNumber = rows[0].length;\n\n for (const cells of rows) {\n if (!Array.isArray(cells)) {\n throw new TypeError('Table row data must be an array.');\n }\n\n if (cells.length !== columnNumber) {\n throw new Error('Table must have a consistent number of cells.');\n }\n\n for (const cell of cells) {\n // eslint-disable-next-line no-control-regex\n if (/[\\u0001-\\u0009\\u000B-\\u001A]/.test(cell)) {\n throw new Error('Table data must not contain control characters.');\n }\n }\n }\n};\n"],"file":"validateTableData.js"}
1
+ {"version":3,"sources":["../src/validateTableData.js"],"names":["rows","Array","isArray","TypeError","length","Error","columnNumber","cells","cell","test"],"mappings":";;;;;;;AAAA;;;;AAIA;;;;AAIA;;;;0BAIgBA,I,IAAS;AACvB,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACxB,UAAM,IAAIG,SAAJ,CAAc,8BAAd,CAAN;AACD;;AAED,MAAIH,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;AACrB,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,MAAIL,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;AACD;;AAED,QAAMC,YAAY,GAAGN,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAA7B;AAbuB;AAAA;AAAA;;AAAA;AAevB,yBAAoBJ,IAApB,8HAA0B;AAAA,YAAfO,KAAe;;AACxB,UAAI,CAACN,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAL,EAA2B;AACzB,cAAM,IAAIJ,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,UAAII,KAAK,CAACH,MAAN,KAAiBE,YAArB,EAAmC;AACjC,cAAM,IAAID,KAAJ,CAAU,+CAAV,CAAN;AACD;;AAPuB;AAAA;AAAA;;AAAA;AASxB,8BAAmBE,KAAnB,mIAA0B;AAAA,gBAAfC,IAAe;;AACxB;AACA,cAAI,4CAA4CC,IAA5C,CAAiDD,IAAjD,CAAJ,EAA4D;AAC1D,kBAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF;AAduB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAezB;AA9BsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BxB,C","sourcesContent":["/**\n * @typedef {string} cell\n */\n\n/**\n * @typedef {cell[]} validateData~column\n */\n\n/**\n * @param {column[]} rows\n * @returns {undefined}\n */\nexport default (rows) => {\n if (!Array.isArray(rows)) {\n throw new TypeError('Table data must be an array.');\n }\n\n if (rows.length === 0) {\n throw new Error('Table must define at least one row.');\n }\n\n if (rows[0].length === 0) {\n throw new Error('Table must define at least one column.');\n }\n\n const columnNumber = rows[0].length;\n\n for (const cells of rows) {\n if (!Array.isArray(cells)) {\n throw new TypeError('Table row data must be an array.');\n }\n\n if (cells.length !== columnNumber) {\n throw new Error('Table must have a consistent number of cells.');\n }\n\n for (const cell of cells) {\n // eslint-disable-next-line no-control-regex\n if (/[\\u0001-\\u0006\\u0008-\\u0009\\u000B-\\u001A]/.test(cell)) {\n throw new Error('Table data must not contain control characters.');\n }\n }\n }\n};\n"],"file":"validateTableData.js"}
package/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  "lint": "npm run build && eslint ./src ./test && flow",
80
80
  "test": "mocha --require @babel/register"
81
81
  },
82
- "version": "5.2.3"
82
+ "version": "5.3.3"
83
83
  }