
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
table-renderer
Advanced tools
convert table or spreadsheet data into an image
One day, I had to build a slack slash command which reports marketing reports to our company slack channel. I wanted to format the command results look like table, but I could not find a simple way to do that. I decided to build a table-like view using markdown text, and struggled to do that. However, the layout was broken with small windows or with CJK charaters. So I decided to build the report as an image.

I hope this module will help someone who wants to convert a simple spreadsheet data into an image,
npm install table-renderer canvas
node-canvas module is peer-dependency. You have to install it, too.
import path from 'path';
import TableRenderer, { saveImage } from 'table-renderer';
const renderTable = TableRenderer().render;
const canvas = renderTable({
title: 'Marketing Summary',
columns: [
{ width: 200, title: 'Campaign', dataIndex: 'campaign' },
{ width: 100, title: 'Install', dataIndex: 'install', align: 'right' },
{ width: 100, title: 'Cost', dataIndex: 'cost', align: 'right' },
],
dataSource: [
'-',
{ campaign: 'Google CPC', install: '12', cost: '$ 400' },
{ campaign: 'Facebook CPC', install: '3', cost: '$ 60' },
{ campaign: 'Youtube Video', install: '131', cost: '$ 1,230' },
'-',
{ campaign: 'Total', install: '146', cost: '$ 1,690' },
],
});
saveImage(canvas, path.join(__dirname, 'example.png'));

TableRenderer(options = {}) => ({ render: function });
cellWidth {number} default width for a table cell. default = 100cellHeight {number} default height for a table cell. default = 40offsetLeft {number} default text offset from left border of table cell. default = 8offsetTop {number} default text offset from top border of table cell. default = 26spacing {number} spacing between tables. default = 20titleSpacing {number} spacing between title and a table. default = 10fontFamily {string} default = 'sans-serif'paddingVertical {number} vertical padding of a page. default = 0paddingHorizontal {number} horizontal padding of a page. default = 0backgroundColor {string} page background color. default = '#ffffff'render((tables: Object | Array)) => Canvas;
tables parameter is either Object or Array. Single table is comprised of title, columns, and dataSource, where title is optional. Parameters of render function resembles ant-design Table paramters.
The function returns Canvas object, which is an instance of node-canvas. So, you can add canvas operations to it.
render({
title: 'Marketing Summary',
columns: [...],
dataSource: [...]
});
saveImage((canvas: Canvas), (filepath: String)) => Promise;
FAQs
convert table or spreadsheet data into an image
We found that table-renderer 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.