Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
table-layout
Advanced tools
The table-layout package is a utility for Node.js that allows for the easy formatting of text into a table structure. It provides a way to organize data in rows and columns, with options for customizing alignment, width, and padding. This package is useful for CLI tools and scripts that need to present data in a structured, readable format.
Basic table layout
This feature allows you to create a basic table layout by specifying an array of objects, where each object represents a row in the table. The keys of the object represent column names.
const Table = require('table-layout');
const data = [{ colA: 'row 1 column A', colB: 'row 1 column B' }, { colA: 'row 2 column A', colB: 'row 2 column B' }];
const table = new Table(data);
console.log(table.toString());
Custom column width and wrapping
This feature demonstrates how to customize the width of columns and enable text wrapping. It is useful for controlling the appearance of the table and ensuring that it fits within a specific layout.
const Table = require('table-layout');
const data = [{ name: 'Some really long name that exceeds the default column width', age: '30' }];
const options = { columns: [{ name: 'name', width: 30, nowrap: true }, { name: 'age', width: 10 }] };
const table = new Table(data, options);
console.log(table.toString());
cli-table is a similar package that provides functionalities for rendering unicode-aided tables on the command line. Compared to table-layout, cli-table focuses more on the visual styling of the table borders and padding but does not offer as much control over text wrapping and column width.
ascii-table is another package for creating ASCII tables. It allows for quick and easy table generation with minimal configuration. While it's simpler and less feature-rich than table-layout, it's suitable for applications that require basic table functionalities without the need for advanced formatting options.
Stylable text tables, handling ansi colour. Useful for console output.
Converts arrays of row data to text tables. For example - one row, two columns:
[
{
"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
:
$ cat example/two-columns.json | table-layout
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.
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
$ 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.
Read the latest npm issues: (example requires jq)
$ 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.
As a library:
$ npm install table-layout --save
As a command-line tool:
$ npm install -g table-layout
Array.<string>
Recordset data in (array of objects), text table out.
Kind: Exported function
Params
Array.<object>
- input dataobject
- optional settings
number
- maximum width of layoutboolean
- disable wrapping on all columnsboolean
- enable word-breaking on all columnscolumnOption
- array of column optionsboolean
object
- Padding values to set on each column. Per-column overrides can be set in the options.columns
array.
string
string
Example
> tableLayout = require('table-layout')
> jsonData = [{
col1: 'Some text you wish to read in table layout',
col2: 'And some more text in column two. '
}]
> tableLayout(jsonData, { maxWidth: 30 })
Some text you And some more
wish to read text in
in table column two.
layout
Array.<string>
Identical to tableLayout()
with the exception of the rendered result being returned as an array of lines, rather that a single string.
Kind: static method of tableLayout
Example
> 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 ' ]
Kind: inner typedef of tableLayout
Properties
Name | Type | Description |
---|---|---|
name | string | column name, must match a property name in the input |
width | number | column width |
minWidth | number | column min width |
maxWidth | number | column max width |
nowrap | boolean | disable wrapping for this column |
break | boolean | enable word-breaking for this columns |
padding | object | padding options |
padding.left | string | a string to pad the left of each cell (default: ' ' ) |
padding.right | string | a string to pad the right of each cell (default: ' ' ) |
© 2015-16 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
FAQs
Stylable text tables, handling ansi colour. Useful for console output.
The npm package table-layout receives a total of 1,579,940 weekly downloads. As such, table-layout popularity was classified as popular.
We found that table-layout demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.