Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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 987,522 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.