@dephub/table
v1.0.0
Published
Tiny table builder for any format — text, HTML, CSV, Markdown, JSON, or custom outputs.
Maintainers
Readme
@dephub/table 📊
Tiny table builder for any format — text, HTML, CSV, Markdown, JSON, or custom outputs.
Features ✨
- 🧱 Build tables row-by-row using a fluent API
- 📜 Output to text, HTML, CSV, JSON, or Markdown
- 🧩 Extend with custom builders via callback functions
- 💥 Type-safe errors and validation through
TableError - 🪶 Lightweight, dependency-free, and works in Node.js or browser ESM
Installation 📦
- npm:
npm install @dephub/table - pnpm:
pnpm add @dephub/table - yarn:
yarn add @dephub/table - bun:
bun add @dephub/table
Usage 🎯
Basic Builder
import { Builder } from '@dephub/table';
const table = new Builder()
.add('Name', 'Age')
.add('Alice', 30)
.add('Bob', 25)
.build();
console.log(table);
// [["Name","Age"],["Alice",30],["Bob",25]]CSV Output
import { Csv } from '@dephub/table';
const csv = new Csv().add('Name', 'Age').add('Alice', 30).build();
console.log(csv);
// "Name","Age"\n"Alice","30"HTML Output
import { Html } from '@dephub/table';
const html = new Html().add('Product', 'Price').add('Apple', 1.99).build();
console.log(html);
// "<table><tr><td>Product</td><td>Price</td></tr><tr><td>Apple</td><td>1.99</td></tr></table>"Markdown Output
import { Markdown } from '@dephub/table';
const md = new Markdown().add('Name', 'Age').add('Lila', 3).build();
console.log(md);
/*
| Name | Age |
| ---- | --- |
| Lila | 3 |
*/Custom Output
import { Custom } from '@dephub/table';
const xml = new Custom(
(rows) =>
`<root>${rows.map((r) => `<row>${r.join('')}</row>`).join('')}</root>`,
'data.xml',
)
.add('Name', 'Age')
.add('Zoe', 21)
.build();
console.log(xml);
// "<root><row>NameAge</row><row>Zoe21</row></root>"License 📄
MIT License – see LICENSE for details.
Author: Estarlin R. — estarlincito.com
