@bota-apps/export
v0.1.1
Published
Framework-free client-side data export: turn header + row arrays into a downloaded CSV, XLSX, or PDF. One subpath per format (./csv is dependency-free; ./excel pulls xlsx, ./pdf pulls jspdf) plus an exportTable() format dispatcher on the barrel.
Maintainers
Readme
@bota-apps/export
Framework-free, client-side data export. Turn a headers array plus an array of
plain row objects into a file the browser downloads — CSV, XLSX, or PDF. No
React, no server round-trip: each helper builds the file in the browser and
triggers the download.
Row keys drive column order (taken from the first row); headers supplies the
display labels, positionally aligned to those keys.
Install
pnpm add @bota-apps/exportDependencies are per subpath, so you only pay for the format you import:
@bota-apps/export/csv— dependency-free.@bota-apps/export/excel— pulls inxlsx.@bota-apps/export/pdf— pulls injspdfandjspdf-autotable.
Importing the barrel (@bota-apps/export) reaches all three, so prefer a single
format's subpath when the format is fixed at build time.
Usage
Every helper takes a filename (no extension — the format's extension is
appended) followed by the headers labels and the rows. A row is an
ExportRow — Record<string, string | number | boolean | null | undefined>.
CSV — the lean, dependency-free path:
import { exportToCsv } from "@bota-apps/export/csv";
exportToCsv("projects", ["Name", "Department"], [{ name: "Jane Doe", department: "Engineering" }]);
// downloads projects.csvExcel — the same shape, one column per row key on a sheet named Report:
import { exportToExcel } from "@bota-apps/export/excel";
exportToExcel("projects", ["Name", "Department"], rows);
// downloads projects.xlsxPDF — takes an extra title argument, rendered above an auto-laid-out table:
import { exportToPdf } from "@bota-apps/export/pdf";
exportToPdf("projects", "Project Roster", ["Name", "Department"], rows);
// downloads projects.pdfWhen the format is chosen at runtime, use the exportTable dispatcher on the
barrel. It forwards to the matching helper (and title is used by the PDF
format only):
import { exportTable, type ExportFormat } from "@bota-apps/export";
const format: ExportFormat = "pdf"; // "csv" | "excel" | "pdf"
exportTable(format, "project-summary", "Project Summary", headers, rows);Subpaths
Each format is its own entry so you only bundle the dependency you use:
| Import | Exports | Deps pulled |
| ---------------------------- | ------------------------------------------------------------------ | -------------------------- |
| @bota-apps/export/csv | exportToCsv | none |
| @bota-apps/export/excel | exportToExcel | xlsx |
| @bota-apps/export/pdf | exportToPdf | jspdf, jspdf-autotable |
| @bota-apps/export (barrel) | exportTable, ExportFormat, ExportRow, plus all three helpers | all of the above |
Part of the @bota-apps packages monorepo.
