Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@oclif/table
Advanced tools
@oclif/table is a utility for formatting and displaying tables in command-line interfaces (CLIs) built with the oclif framework. It provides a simple way to present tabular data in a readable format.
Basic Table Rendering
This feature allows you to render a basic table with specified columns and data. The code sample demonstrates how to create a table with 'Name' and 'Age' columns using the @oclif/table package.
const { table } = require('@oclif/table');
const data = [
{ name: 'John Doe', age: 30 },
{ name: 'Jane Smith', age: 25 }
];
const columns = {
name: {
header: 'Name'
},
age: {
header: 'Age'
}
};
table(data, { columns });
Custom Column Formatting
This feature allows for custom formatting of table columns. The code sample shows how to format the 'Name' column to be uppercase and the 'Age' column to append 'years' to the age value.
const { table } = require('@oclif/table');
const data = [
{ name: 'John Doe', age: 30 },
{ name: 'Jane Smith', age: 25 }
];
const columns = {
name: {
header: 'Name',
get: row => row.name.toUpperCase()
},
age: {
header: 'Age',
get: row => `${row.age} years`
}
};
table(data, { columns });
Sorting Table Data
This feature allows you to sort table data by a specified column. The code sample demonstrates sorting the table by the 'Age' column.
const { table } = require('@oclif/table');
const data = [
{ name: 'John Doe', age: 30 },
{ name: 'Jane Smith', age: 25 }
];
const columns = {
name: {
header: 'Name'
},
age: {
header: 'Age'
}
};
table(data, { columns, sort: 'age' });
cli-table3 is a popular package for creating tables in the command line. It offers similar functionality to @oclif/table, such as custom column formatting and alignment. However, cli-table3 is more widely used outside of the oclif framework and provides more customization options for table styling.
The 'table' package is another alternative for rendering tables in the command line. It provides a flexible API for table creation and supports features like text wrapping and alignment. Compared to @oclif/table, it is more focused on general CLI applications rather than being tied to a specific framework like oclif.
Print tables to the terminal using ink
You can see examples of how to use it in the examples directory.
You can run any of these with the following:
tsx examples/basic.ts
See the contributing guide.
FAQs
Display table in terminal
The npm package @oclif/table receives a total of 113,786 weekly downloads. As such, @oclif/table popularity was classified as popular.
We found that @oclif/table 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.