@pilag6/csv-downloader
v1.0.2
Published
Lightweight CSV export utility for Vue and React
Maintainers
Readme
📄 CSV Downloader
CSV Downloader is a lightweight and fast utility to export data as CSV directly from the browser.
It works with Vue, React, and any JavaScript or TypeScript project.
🚀 Installation
npm install @pilag6/csv-downloader📦 Basic usage
Vue 3
<script setup lang="ts">
import { downloadCSV } from '@pilag6/csv-downloader';
const exportData = () => {
downloadCSV({
headers: ['Name', 'Age', 'Country'],
contents: [
['John Doe', 30, 'USA'],
['Jane Smith', 25, 'UK']
]
});
};
</script>
<template>
<button @click="exportData">Export CSV</button>
</template>React
import React from 'react';
import { downloadCSV } from '@pilag6/csv-downloader';
export default function App() {
const exportData = () => {
downloadCSV({
headers: ['Name', 'Age', 'Country'],
contents: [
['John Doe', 30, 'USA'],
['Jane Smith', 25, 'UK']
],
filename: 'users.csv'
});
};
return <button onClick={exportData}>Export CSV</button>;
}⚙️ Options
| Option | Type | Default | Description |
|------------|------------------------|-------------|-------------|
| headers | string[] | Required| Column names |
| contents | (string\|number)[][] | Required| Data in rows and columns |
| filename | string | data.csv | CSV file name |
| separator| string | , | Column separator |
| bom | boolean | true | Add UTF-8 BOM for Excel compatibility |
🧪 Advanced example
import { downloadCSV } from '@pilag6/csv-downloader';
downloadCSV({
headers: ['Product', 'Quantity', 'Price (€)'],
contents: [
['T-Shirt', 3, 19.99],
['Pants', 1, 39.5],
['Shoes', 2, 59.0]
],
filename: 'inventory.csv',
separator: ';', // Use semicolon as separator
bom: true // Excel compatible
});💡 Features
✅ Works with Vue, React, and plain JavaScript projects
✅ Supports any separator (;, ,, \t, etc.)
✅ Automatically escapes double quotes
✅ Optional BOM for Excel compatibility
✅ Lightweight, zero dependencies
📥 Quick install & run
npm install @pilag6/csv-downloaderImport and use:
import { downloadCSV } from '@pilag6/csv-downloader';
downloadCSV({
headers: ['A', 'B', 'C'],
contents: [['1', '2', '3']]
});🛠 Support
Found a bug or have a suggestion? Open an issue on GitHub or contact me.
📄 License
MIT — Free for personal and commercial use.
