
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
string-table
Advanced tools
A groundbreaking, innovative JavaScript library to do something that's literally never been attempted before: formatting an array of data objects as a textual table.
var users = [
{ name: 'Dan', gender: 'M', age: 29 },
{ name: 'Adam', gender: 'M', age: 31 },
{ name: 'Lauren', gender: 'F', age: 33 }
];
var table = stringTable.create(users);
console.log(table);
/*
* Output:
*
* | name | gender | age |
* -------------------------
* | Dan | M | 29 |
* | Adam | M | 31 |
* | Lauren | F | 33 |
*/
You can also specify options to customize how the table is formatted:
var table = stringTable.create(users, options);
The available options are summarized below.
headersAn array of strings indicating which column headers to include (and in what order)
Default: every property from the first object in the list
stringTable.create(users, { headers: ['age', 'name'] });
/*
* Output:
*
* | age | name |
* ----------------
* | 29 | Dan |
* | 31 | Adam |
* | 33 | Lauren |
*/
capitalizeHeadersWhether or not to capitalize the table's column headers
Default: false
stringTable.create(users, { capitalizeHeaders: true });
/*
* Output:
*
* | Name | Gender | Age |
* -------------------------
* | Dan | M | 29 |
* | Adam | M | 31 |
* | Lauren | F | 33 |
*/
formattersAn object mapping column names to formatter functions
Default: none
stringTable.create(users, {
formatters: {
name: function(value) { return value.toUpperCase(); }
}
});
/*
* Output:
*
* | name | gender | age |
* -------------------------
* | DAN | M | 29 |
* | ADAM | M | 31 |
* | LAUREN | F | 33 |
*/
typeFormattersAn object mapping data types ('string', 'number', 'boolean', etc.) to formatter functions (has lower precedence than formatters option)
Default: none
stringTable.create(users, {
typeFormatters: {
number: function(value) { return value.toFixed(2); }
}
});
/*
* Output:
*
* | name | gender | age |
* ----------------------------
* | Dan | M | 29.00 |
* | Adam | M | 31.00 |
* | Lauren | F | 33.00 |
*/
outerBorder and innerBorderThe character(s) used to enclose the table and to delimit cells within the table, respectively
Defaults: '|' for both
stringTable.create(users, {
outerBorder: '%',
innerBorder: '$'
});
/*
* Output:
*
* % name $ gender $ age %
* -------------------------
* % Dan $ M $ 29 %
* % Adam $ M $ 31 %
* % Lauren $ F $ 33 %
*/
rowSeparatorThe character used to separate rows in the table
Default: undefined
stringTable.create(users, { rowSeparator: '~' });
/*
* Output:
*
* | name | gender | age |
* -------------------------
* | Dan | M | 29 |
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* | Adam | M | 31 |
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* | Lauren | F | 33 |
*/
headerSeparatorThe character used to separate the header row from the table body
Default: '-'
stringTable.create(users, { headerSeparator: '*' });
/*
* Output:
*
* | name | gender | age |
* *************************
* | Dan | M | 29 |
* | Adam | M | 31 |
* | Lauren | F | 33 |
*/
FAQs
Format an array of data objects as a textual table
The npm package string-table receives a total of 2,437 weekly downloads. As such, string-table popularity was classified as popular.
We found that string-table demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.