table-layout
Advanced tools
Comparing version 0.2.3 to 0.3.0-0
@@ -15,3 +15,3 @@ var detect = require('feature-detect-es6') | ||
module.exports = detect.all('class', 'arrowFunction', 'templateStrings') | ||
? require('./lib/table-layout') | ||
: require('./es5/table-layout') | ||
? require('./src/lib/table-layout') | ||
: require('./es5/lib/table-layout') |
{ | ||
"name": "table-layout", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.2.3", | ||
"version": "0.3.0-0", | ||
"description": "Stylable text tables, handling ansi colour. Useful for console output.", | ||
@@ -9,3 +9,2 @@ "repository": "https://github.com/75lb/table-layout.git", | ||
"main": "index", | ||
"bin": "bin/cli.js", | ||
"keywords": [ | ||
@@ -21,15 +20,12 @@ "wrap", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.12.0" | ||
}, | ||
"scripts": { | ||
"test": "test-runner test/*.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js -p list --member-index-format list > README.md; echo", | ||
"es5": "babel --presets babel-preset-es2015 --no-comments lib --out-dir es5", | ||
"cover": "istanbul cover test-runner -- test/*.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage; echo" | ||
"test": "node test.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs src/lib/*.js -p list --member-index-format list > README.md; echo", | ||
"es5": "rm -rf es5 && babel --presets babel-preset-es2015 --no-comments src --out-dir es5 && cp -r src/test/fixture es5/test", | ||
"cover": "istanbul cover test-runner -- node test.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage; echo" | ||
}, | ||
"dependencies": { | ||
"ansi-escape-sequences": "^3.0.0", | ||
"array-back": "^1.0.3", | ||
"collect-json": "^1.0.8", | ||
"command-line-tool": "~0.6.4", | ||
"core-js": "^2.4.1", | ||
@@ -39,10 +35,10 @@ "deep-extend": "~0.4.1", | ||
"typical": "^2.6.0", | ||
"wordwrapjs": "^1.2.1" | ||
"wordwrapjs": "^2.0.0-0" | ||
}, | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.16.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"core-assert": "~0.2.1", | ||
"coveralls": "^2.11.14", | ||
"coveralls": "^2.11.15", | ||
"jsdoc-to-markdown": "^2.0.1", | ||
"test-runner": "~0.2.5" | ||
"test-runner": "~0.3.0" | ||
}, | ||
@@ -49,0 +45,0 @@ "standard": { |
181
README.md
@@ -8,116 +8,48 @@ [![view on npm](http://img.shields.io/npm/v/table-layout.svg)](https://www.npmjs.org/package/table-layout) | ||
# table-layout | ||
Stylable text tables, handling ansi colour. Useful for console output. | ||
Generates plain-text tables from JSON recordset input (array of objects). Useful for presenting text in column layout or data in table layout in text-based user interfaces. Also [available as a command-line tool](https://github.com/75lb/table-layout-cli). | ||
## Synopsis | ||
Converts arrays of row data to text tables. For example - one row, two columns: | ||
```json | ||
[ | ||
{ | ||
"column 1": "The Kingdom of Scotland was a state in north-west Europe traditionally said to have been founded in 843, which joined with the Kingdom of England to form a unified Kingdom of Great Britain in 1707. Its territories expanded and shrank, but it came to occupy the northern third of the island of Great Britain, sharing a land border to the south with the Kingdom of England. ", | ||
"column 2": "Operation Barbarossa (German: Unternehmen Barbarossa) was the code name for Nazi Germany's invasion of the Soviet Union during World War II, which began on 22 June 1941. Over the course of the operation, about four million soldiers of the Axis powers invaded Soviet Russia along a 2,900 kilometer front, the largest invasion force in the history of warfare. In addition to troops, the Germans employed some 600,000 motor vehicles and between 600–700,000 horses." | ||
} | ||
] | ||
``` | ||
pipe it through `table-layout`: | ||
```sh | ||
$ cat example/two-columns.json | table-layout | ||
``` | ||
> const Table = require('table-layout') | ||
> const issues = require('./example/issues') | ||
to get this: | ||
``` | ||
The Kingdom of Scotland was a state in Operation Barbarossa (German: Unternehmen | ||
north-west Europe traditionally said to Barbarossa) was the code name for Nazi | ||
have been founded in 843, which joined Germany's invasion of the Soviet Union | ||
with the Kingdom of England to form a during World War II, which began on 22 | ||
unified Kingdom of Great Britain in 1707. June 1941. Over the course of the | ||
Its territories expanded and shrank, but operation, about four million soldiers of | ||
it came to occupy the northern third of the Axis powers invaded Soviet Russia | ||
the island of Great Britain, sharing a along a 2,900 kilometer front, the | ||
land border to the south with the Kingdom largest invasion force in the history of | ||
of England. warfare. In addition to troops, the | ||
Germans employed some 600,000 motor | ||
vehicles and between 600–700,000 horses. | ||
``` | ||
> const table = new Table(issues, { maxWidth: 60 }) | ||
> console.log(table.toString()) | ||
15134 Coveralls has no source available ndelangen 0 | ||
15133 Fixing --preserve-symlinks. phestermcs 0 | ||
Enhancing node to exploit. | ||
15131 Question - Confused about NPM's the1mills 0 | ||
local installation philosophy | ||
15130 Question - global npm cache ORESoftware 0 | ||
directory if user is root? | ||
15127 how to installa gulp fontfacegen aramgreat 0 | ||
on Windows 10 | ||
15097 Cannot install package from mastertinner 3 | ||
tarball out of package.json entry | ||
generated by npm | ||
15067 npm "SELF_SIGNED_CERT_IN_CHAIN" LegendsLyfe 3 | ||
error when installing discord.js | ||
with .log | ||
Columns containing wrappable data (like the above) are auto-sized by default to fit the available space. You can set specific column widths using `--width` | ||
```sh | ||
$ cat example/two-columns.json | table-layout --width "column 2: 55" | ||
``` | ||
``` | ||
The Kingdom of Scotland was a Operation Barbarossa (German: Unternehmen Barbarossa) | ||
state in north-west Europe was the code name for Nazi Germany's invasion of the | ||
traditionally said to have Soviet Union during World War II, which began on 22 | ||
been founded in 843, which June 1941. Over the course of the operation, about | ||
joined with the Kingdom of four million soldiers of the Axis powers invaded | ||
England to form a unified Soviet Russia along a 2,900 kilometer front, the | ||
Kingdom of Great Britain in largest invasion force in the history of warfare. In | ||
1707. Its territories addition to troops, the Germans employed some 600,000 | ||
expanded and shrank, but it motor vehicles and between 600–700,000 horses. | ||
came to occupy the northern | ||
third of the island of Great | ||
Britain, sharing a land | ||
border to the south with the | ||
Kingdom of England. | ||
``` | ||
## More Examples | ||
Read the latest npm issues: (example requires [jq](https://stedolan.github.io/jq/)) | ||
```sh | ||
$ curl -s https://api.github.com/repos/npm/npm/issues \ | ||
| jq 'map({ number, title, login:.user.login, comments })' \ | ||
| table-layout | ||
``` | ||
``` | ||
10263 npm run start Slepperpon 4 | ||
10262 npm-shrinkwrap.json being ignored for a dependency of a maxkorp 0 | ||
dependency (2.14.9, 3.3.10) | ||
10261 EPROTO Error Installing Packages azkaiart 2 | ||
10260 ENOENT during npm install with npm v3.3.6/v3.3.12 and lencioni 2 | ||
node v5.0.0 | ||
10259 npm install failed geraldvillorente 1 | ||
10258 npm moves common dependencies under a dependency on trygveaa 2 | ||
install | ||
10257 [NPM3] Missing top level dependencies after npm install naholyr 0 | ||
10256 Yo meanjs app creation problem nrjkumar41 0 | ||
10254 sapnwrfc is not installing RamprasathS 0 | ||
10253 npm install deep dependence folder "node_modules" duyetvv 2 | ||
10251 cannot npm login w0ps 2 | ||
10250 Update npm-team.md louislarry 0 | ||
10248 cant install module I created nousacademy 4 | ||
10247 Cannot install passlib nicola883 3 | ||
10246 Error installing Gulp AlanIsrael0 1 | ||
10245 cannot install packages through NPM RoyGeagea 11 | ||
10244 Remove arguments from npm-dedupe.md bengotow 0 | ||
etc. | ||
etc. | ||
``` | ||
## Install | ||
As a library: | ||
``` | ||
$ npm install table-layout --save | ||
``` | ||
As a command-line tool: | ||
``` | ||
$ npm install -g table-layout | ||
``` | ||
## API Reference | ||
* [table-layout](#module_table-layout) | ||
* [tableLayout(data, [options])](#exp_module_table-layout--tableLayout) ⏏ | ||
* [.lines()](#module_table-layout--tableLayout.lines) ⇒ <code>Array.<string></code> | ||
* [~columnOption](#module_table-layout--tableLayout..columnOption) | ||
* [Table](#exp_module_table-layout--Table) ⏏ | ||
* [new Table(data, [options])](#new_module_table-layout--Table_new) | ||
* [table.renderLines()](#module_table-layout--Table+renderLines) ⇒ <code>Array.<string></code> | ||
* [table.toString()](#module_table-layout--Table+toString) ⇒ <code>string</code> | ||
* [Table~columnOption](#module_table-layout--Table..columnOption) | ||
<a name="exp_module_table-layout--tableLayout"></a> | ||
<a name="exp_module_table-layout--Table"></a> | ||
### tableLayout(data, [options]) ⏏ | ||
### Table ⏏ | ||
Recordset data in (array of objects), text table out. | ||
**Kind**: Exported function | ||
**Kind**: Exported class | ||
<a name="new_module_table-layout--Table_new"></a> | ||
#### new Table(data, [options]) | ||
**Params** | ||
@@ -128,13 +60,14 @@ | ||
- [.maxWidth] <code>number</code> - maximum width of layout | ||
- [.nowrap] <code>boolean</code> - disable wrapping on all columns | ||
- [.noWrap] <code>boolean</code> - disable wrapping on all columns | ||
- [.noTrim] <code>boolean</code> - disable line-trimming | ||
- [.break] <code>boolean</code> - enable word-breaking on all columns | ||
- [.columns] <code>[columnOption](#module_table-layout--tableLayout..columnOption)</code> - array of column options | ||
- [.ignoreEmptyColumns] <code>boolean</code> | ||
- [.columns] <code>[columnOption](#module_table-layout--Table..columnOption)</code> - array of column-specific options | ||
- [.ignoreEmptyColumns] <code>boolean</code> - if set, empty columns or columns containing only whitespace are not rendered. | ||
- [.padding] <code>object</code> - Padding values to set on each column. Per-column overrides can be set in the `options.columns` array. | ||
- [.left] <code>string</code> | ||
- [.right] <code>string</code> | ||
- [.left] <code>string</code> - Defaults to a single space. | ||
- [.right] <code>string</code> - Defaults to a single space. | ||
**Example** | ||
```js | ||
> tableLayout = require('table-layout') | ||
> Table = require('table-layout') | ||
> jsonData = [{ | ||
@@ -144,3 +77,4 @@ col1: 'Some text you wish to read in table layout', | ||
}] | ||
> tableLayout(jsonData, { maxWidth: 30 }) | ||
> table = new Table(jsonData, { maxWidth: 30 }) | ||
> console.log(table.toString()) | ||
Some text you And some more | ||
@@ -151,25 +85,18 @@ wish to read text in | ||
``` | ||
<a name="module_table-layout--tableLayout.lines"></a> | ||
<a name="module_table-layout--Table+renderLines"></a> | ||
#### tableLayout.lines() ⇒ <code>Array.<string></code> | ||
Identical to `tableLayout()` with the exception of the rendered result being returned as an array of lines, rather that a single string. | ||
#### table.renderLines() ⇒ <code>Array.<string></code> | ||
Identical to `.toString()` with the exception that the result will be an array of lines, rather than a single, multi-line string. | ||
**Kind**: static method of <code>[tableLayout](#exp_module_table-layout--tableLayout)</code> | ||
**Example** | ||
```js | ||
> tableLayout = require('table-layout') | ||
> jsonData = [{ | ||
col1: 'Some text you wish to read in table layout', | ||
col2: 'And some more text in column two. ' | ||
}] | ||
> tableLayout.lines(jsonData, { maxWidth: 30 }) | ||
[ ' Some text you And some more ', | ||
' wish to read text in ', | ||
' in table column two. ', | ||
' layout ' ] | ||
``` | ||
<a name="module_table-layout--tableLayout..columnOption"></a> | ||
**Kind**: instance method of <code>[Table](#exp_module_table-layout--Table)</code> | ||
<a name="module_table-layout--Table+toString"></a> | ||
#### tableLayout~columnOption | ||
**Kind**: inner typedef of <code>[tableLayout](#exp_module_table-layout--tableLayout)</code> | ||
#### table.toString() ⇒ <code>string</code> | ||
Returns the input data as a text table. | ||
**Kind**: instance method of <code>[Table](#exp_module_table-layout--Table)</code> | ||
<a name="module_table-layout--Table..columnOption"></a> | ||
#### Table~columnOption | ||
**Kind**: inner typedef of <code>[Table](#exp_module_table-layout--Table)</code> | ||
**Properties** | ||
@@ -180,3 +107,3 @@ | ||
| name | <code>string</code> | column name, must match a property name in the input | | ||
| width | <code>number</code> | column width | | ||
| width | <code>number</code> | A specific column width. Supply either this or a min and/or max width. | | ||
| minWidth | <code>number</code> | column min width | | ||
@@ -183,0 +110,0 @@ | maxWidth | <code>number</code> | column max width | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
52856
35
1219
116
1
- Removedansi-escape-sequences@^3.0.0
- Removedcollect-json@^1.0.8
- Removedcommand-line-tool@~0.6.4
- Removedansi-escape-sequences@3.0.0(transitive)
- Removedcollect-all@1.0.4(transitive)
- Removedcollect-json@1.0.9(transitive)
- Removedcommand-line-args@3.0.5(transitive)
- Removedcommand-line-tool@0.6.4(transitive)
- Removedcommand-line-usage@3.0.8(transitive)
- Removedfind-replace@1.0.3(transitive)
- Removedstream-connect@1.0.2(transitive)
- Removedstream-via@1.0.4(transitive)
- Removedtable-layout@0.3.0(transitive)
- Removedtest-value@2.1.0(transitive)
- Removedwordwrapjs@1.2.1(transitive)
Updatedwordwrapjs@^2.0.0-0