Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
A simple function that print objects / arrays as ASCII tables. Handles ANSI styling and weird 💩 Unicode emoji symbols – they won't break the layout.
The 'as-table' npm package is a simple utility for formatting arrays of objects into a readable table format. It is particularly useful for displaying tabular data in a console or terminal environment.
Basic Table Formatting
This feature allows you to format an array of objects into a readable table. The code sample demonstrates how to use 'as-table' to display a list of people with their names and ages in a tabular format.
const asTable = require('as-table');
const data = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
console.log(asTable(data));
Custom Column Formatting
This feature allows you to customize the formatting of specific columns. The code sample shows how to append 'years' to the age column values.
const asTable = require('as-table');
const data = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const options = {
age: x => x + ' years'
};
console.log(asTable.configure(options)(data));
Column Alignment
This feature allows you to align the content of specific columns. The code sample demonstrates how to right-align the age column.
const asTable = require('as-table');
const data = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const options = {
align: { age: 'right' }
};
console.log(asTable.configure(options)(data));
The 'cli-table' package is another utility for formatting data into tables for the console. It offers more advanced features such as nested tables, custom styles, and text wrapping. Compared to 'as-table', 'cli-table' provides more customization options but may be more complex to use.
The 'table' package is a highly configurable library for generating text tables. It supports features like text wrapping, column alignment, and custom border styles. It is more feature-rich than 'as-table' and is suitable for more complex table formatting needs.
The 'easy-table' package is designed for simple and quick table formatting. It offers basic features like column alignment and custom formatting. It is similar to 'as-table' in terms of simplicity and ease of use, but with slightly different API and customization options.
A simple function that print objects and arrays as ASCII tables. Supports ANSI styling and weird 💩 Unicode emoji symbols (they won't break the layout), thanks to printable-characters
.
npm install as-table
asTable = require ('as-table')
asTable ([ { foo: true, string: 'abcde', num: 42 },
{ foo: false, string: 'qwertyuiop', num: 43 },
{ string: null, num: 44 } ])
foo string num
----------------------
true abcde 42
false qwertyuiop 43
null 44
asTable ([['qwe', '123456789', 'zxcvbnm'],
['qwerty', '12', 'zxcvb'],
['qwertyiop', '1234567', 'z']])
qwe 123456789 zxcvbnm
qwerty 12 zxcvb
qwertyiop 1234567 z
asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (data)
qwe | 1234… | zxc…
qwer… | 12 | zxc…
qwer… | 1234… | z
asTable.configure ({ right: true }) (data)
foo bar baz
-----------------------------
qwe 123456789 zxcvbnm
qwerty 12 zxcvb
qwertyiop 1234567 z
asTable.configure ({ print: x => (typeof x === 'boolean') ? (x ? 'yes' : 'no') : String (x) }) (data)
foo string num
--------------------
yes abcde 42
no qwertyuiop 43
null 44
The callback also receives a field name (in case of objects) or a column index (in case of arrays):
asTable = require ('as-table').configure ({
print (x, k) {
if (k === 'timestamp') return new Date (x).toGMTString()
return String (x)
}
})
asTable ([ { name: 'A', timestamp: 1561202591572 },
{ name: 'B', timestamp: 1558524240034 } ])
asTable = require ('as-table').configure ({ maxTotalWidth: 25, delimiter: ' | ' })
asTable (data)
With string coloring by ansicolor
(just for the demo purposes, any library will fit):
asTable = require ('as-table').configure ({ title: x => x.bright, delimiter: ' | '.dim.cyan, dash: '-'.bright.cyan })
console.log (
asTable ([ { foo: true, string: 'abcde', num: 42 },
{ foo: false, string: 'qwertyuiop'.bgMagenta.green.bright, num: 43 } ])
FAQs
A simple function that print objects / arrays as ASCII tables. Handles ANSI styling and weird 💩 Unicode emoji symbols – they won't break the layout.
The npm package as-table receives a total of 926,235 weekly downloads. As such, as-table popularity was classified as popular.
We found that as-table demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.