Socket
Socket
Sign inDemoInstall

tty-table

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tty-table - npm Package Compare versions

Comparing version 2.6.15 to 2.7.0

examples/config/header.js

68

adapters/terminal-adapter.js
#!/usr/bin/env node
let path = require('path');
let fs = require('fs');
let Csv = require('csv');

@@ -8,2 +10,6 @@ let Chalk = require('chalk');

Yargs.option('config',{
describe:'Specify the configuration for your table.'
});
Yargs.option('csv-delimiter',{

@@ -36,5 +42,4 @@ describe:'Set the field delimiter. One character only.',

let sendError = function(msg){
msg = '\ntty-table error: ' + msg + '\n';
console.log(msg);
let emitError = function(type,detail){
console.log('\n' + Chalk.bgRed.white(type) + '\n\n' + Chalk.bold(detail));
process.exit(1);

@@ -57,3 +62,3 @@ };

//look for options-*
//look for individually flagged options-*
let options = {};

@@ -67,27 +72,22 @@ Object.keys(Yargs).forEach(function(key){

//look for header-n-*
//Object.keys(Yargs).forEach(function(key){
// let keyParts = key.split('-');
// if(keyParts[0] === 'header'){
// //find out which column we're setting an option on
// let column = keyParts[1];
// if(typeof header[column] === 'undefined'){
// header[column] = {}
// }
// header[column][keyParts[2]] = Yargs[key];
// }
//});
//look for options passed via config file
let header = []
if(Yargs.header){
if(!fs.existsSync(path.resolve(Yargs.header))){
emitError(
'Invalid file path',
'Cannot find config file at: ' + Yarg.header+ '.'
)
}
//merge with any individually flagged options
header = require(path.resolve(Yargs.header))
}
//if header is specified, we'll need to have a size on it
//because different dataFormats
let runTable = function(input){
let runTable = function(header,body){
let header = [],
body = input;
//footer = [],
let Table = require('../src/factory.js');
options.terminalAdapter = true;
let t1 = Table(header,body,options);
let t1 = Table(header, body,options);

@@ -126,3 +126,3 @@ //hide cursor

case(dataFormat==='json'):
let data,msg;
let data;
try {

@@ -132,7 +132,8 @@ data = JSON.parse(chunk);

catch(e){
msg = Chalk.bgRed.white(msg);
msg = msg + "\n\nPlease check to make sure that your input data consists of JSON or specify a different format with the --format flag.";
sendError(msg);
emitError(
"JSON parse error",
"Please check to make sure that your input data consists of JSON or specify a different format with the --format flag."
);
}
runTable(data);
runTable(header,data);
break;

@@ -150,9 +151,8 @@ default:

if(typeof data === 'undefined'){
let msg = "CSV parse error.";
msg = Chalk.bgRed.white(msg);
msg = msg + '\n\n' + err;
msg = msg + '\n\n' + 'Please check to make sure that your input data consists of valid comma separated values or specify a different format with the --format flag.';
sendError(msg);
emitError(
"CSV parse error",
"Please check to make sure that your input data consists of valid comma separated values or specify a different format with the --format flag."
);
}
runTable(data);
runTable(header,data);
});

@@ -159,0 +159,0 @@ }

var tickers = [
["AAPL",138],
["IBM",120],
["WMT",68],
["ABX",13],
["MSFT",35]
["AAPL",138],
["IBM",120],
["WMT",68],
["ABX",13],
["MSFT",35]
];

@@ -11,44 +11,44 @@

var makeTicker = function(){
var text = [];
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var length = 25;
var text = [];
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var length = 25;
for(var i=0;i<length;i++){
var char = possible.charAt(Math.floor(Math.random()*possible.length));
text.push(char);
}
for(var i=0;i<length;i++){
var char = possible.charAt(Math.floor(Math.random()*possible.length));
text.push(char);
}
return [text.join(""),Math.floor(Math.random(3)*100)];
return [text.join(""),Math.floor(Math.random(3)*100)];
}
var cycle = function(iterator,tickers){
//remove or add a random ticker to test auto resizing
if(iterator % 6 === 0){
tickers.pop();
}
else if(iterator % 3 === 0){
tickers.push(makeTicker());
}
//remove or add a random ticker to test auto resizing
// if(iterator % 6 === 0){
// tickers.pop();
// }
// else if(iterator % 3 === 0){
// tickers.push(makeTicker());
// }
//change ticker values
tickers = tickers.map(function(value){
var sign = (Math.random()) < .5 ? -1 : 1;
var increment = Math.random();
var newVal = (value[1]+sign*increment).toFixed(2)*1;
return [value[0],newVal];
})
//change ticker values
tickers = tickers.map(function(value){
var sign = (Math.random()) < .5 ? -1 : 1;
var increment = Math.random();
var newVal = (value[1]+sign*increment).toFixed(2)*1;
return [value[0],newVal];
})
console.log(JSON.stringify(tickers));
iterator++;
console.log(JSON.stringify(tickers));
iterator++;
setTimeout(function(){
cycle(iterator,tickers)
},500);
setTimeout(function(){
cycle(iterator,tickers)
},500);
}
process.stdout.on('error',function(){
process.exit(1);
process.exit(1);
});
cycle(1,tickers);
{
"name": "tty-table",
"version": "2.6.15",
"version": "2.7.0",
"description": "Command line table generator.",

@@ -5,0 +5,0 @@ "main": "src/main.js",

# tty-table 电传打字台
[![Build Status](https://travis-ci.org/tecfu/tty-table.svg?branch=master)](https://travis-ci.org/tecfu/tty-table) [![Dependency Status](https://david-dm.org/tecfu/tty-table.png)](https://david-dm.org/tecfu/tty-table) [![NPM version](https://badge.fury.io/js/tty-table.svg)](http://badge.fury.io/js/tty-table)
[![Build Status](https://travis-ci.org/tecfu/tty-table.svg?branch=master)](https://travis-ci.org/tecfu/tty-table) [![NPM version](https://badge.fury.io/js/tty-table.svg)](http://badge.fury.io/js/tty-table)

@@ -15,10 +15,9 @@ ---

- To install as a [terminal application](docs/terminal.md):
- [Terminal](docs/terminal.md):
```sh
$ sudo apt-get install nodejs
$ npm install tty-table -g
```
- As a Nodejs module:
- Node Module

@@ -29,3 +28,3 @@ ```sh

- Browser (via browserify)
- Browser

@@ -40,33 +39,4 @@ ```html

## Why would someone do such a thing?
## [Examples](examples/)
- Can be used as a bugfixed, drop-in replacement for the [unmaintained, but popular Automattic/cli-table](https://github.com/Automattic/cli-table/issues/91):
```js
var Table = require('tty-table')('automattic-cli-table');
//now runs with same syntax as Automattic/cli-table
...
```
- Fixes these open issues with Automattic/cli-table:
- [Text alignment](https://github.com/Automattic/cli-table/issues/64)
- [Alternative table character sets](https://github.com/Automattic/cli-table/issues/10)
- [Automatic text wrapping](https://github.com/Automattic/cli-table/issues/35)
- [Wide character support](https://github.com/Automattic/cli-table/issues/82)
- [Chokes on null values](https://github.com/Automattic/cli-table/issues/65)
- [Automatically resize to terminal width](https://github.com/tecfu/tty-table/issues/4)
### In addition to the fixes listed above, the native API also supports:
- Optional callbacks on column values
- Header, body column alignment
- Padding
- Passing of rows as either arrays or objects
- Colors (not supported in browser)
- [Footer](https://github.com/tecfu/tty-table/issues/6)
- [Works in the browser as well as nodejs](https://cdn.rawgit.com/tecfu/tty-table/master/examples/browser-example.html)
- [Can be run as a standalone terminal application](docs/terminal.md)
## Output Examples
### Terminal (Static)

@@ -81,6 +51,6 @@

```
$ node examples/data/fake-stream.js | tty-table --format=json
$ node examples/data/fake-stream.js | tty-table --format json --header examples/config/header.js
```
![Streaming](https://cloud.githubusercontent.com/assets/7478359/26528893/88e38e38-4369-11e7-8125-05df0259511e.gif "Streaming Example")
![Streaming](https://user-images.githubusercontent.com/7478359/51738817-47c25700-204d-11e9-9df1-04e478331658.gif "Streaming Example")

@@ -87,0 +57,0 @@ - See the built-in help for the terminal version of tty-table with:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc