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