source: trip-planner-front/node_modules/text-table/readme.markdown@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1# text-table
2
3generate borderless text table strings suitable for printing to stdout
4
5[![build status](https://secure.travis-ci.org/substack/text-table.png)](http://travis-ci.org/substack/text-table)
6
7[![browser support](https://ci.testling.com/substack/text-table.png)](http://ci.testling.com/substack/text-table)
8
9# example
10
11## default align
12
13``` js
14var table = require('text-table');
15var t = table([
16 [ 'master', '0123456789abcdef' ],
17 [ 'staging', 'fedcba9876543210' ]
18]);
19console.log(t);
20```
21
22```
23master 0123456789abcdef
24staging fedcba9876543210
25```
26
27## left-right align
28
29``` js
30var table = require('text-table');
31var t = table([
32 [ 'beep', '1024' ],
33 [ 'boop', '33450' ],
34 [ 'foo', '1006' ],
35 [ 'bar', '45' ]
36], { align: [ 'l', 'r' ] });
37console.log(t);
38```
39
40```
41beep 1024
42boop 33450
43foo 1006
44bar 45
45```
46
47## dotted align
48
49``` js
50var table = require('text-table');
51var t = table([
52 [ 'beep', '1024' ],
53 [ 'boop', '334.212' ],
54 [ 'foo', '1006' ],
55 [ 'bar', '45.6' ],
56 [ 'baz', '123.' ]
57], { align: [ 'l', '.' ] });
58console.log(t);
59```
60
61```
62beep 1024
63boop 334.212
64foo 1006
65bar 45.6
66baz 123.
67```
68
69## centered
70
71``` js
72var table = require('text-table');
73var t = table([
74 [ 'beep', '1024', 'xyz' ],
75 [ 'boop', '3388450', 'tuv' ],
76 [ 'foo', '10106', 'qrstuv' ],
77 [ 'bar', '45', 'lmno' ]
78], { align: [ 'l', 'c', 'l' ] });
79console.log(t);
80```
81
82```
83beep 1024 xyz
84boop 3388450 tuv
85foo 10106 qrstuv
86bar 45 lmno
87```
88
89# methods
90
91``` js
92var table = require('text-table')
93```
94
95## var s = table(rows, opts={})
96
97Return a formatted table string `s` from an array of `rows` and some options
98`opts`.
99
100`rows` should be an array of arrays containing strings, numbers, or other
101printable values.
102
103options can be:
104
105* `opts.hsep` - separator to use between columns, default `' '`
106* `opts.align` - array of alignment types for each column, default `['l','l',...]`
107* `opts.stringLength` - callback function to use when calculating the string length
108
109alignment types are:
110
111* `'l'` - left
112* `'r'` - right
113* `'c'` - center
114* `'.'` - decimal
115
116# install
117
118With [npm](https://npmjs.org) do:
119
120```
121npm install text-table
122```
123
124# Use with ANSI-colors
125
126Since the string length of ANSI color schemes does not equal the length
127JavaScript sees internally it is necessary to pass the a custom string length
128calculator during the main function call.
129
130See the `test/ansi-colors.js` file for an example.
131
132# license
133
134MIT
Note: See TracBrowser for help on using the repository browser.