bun-plugin-csv
A Bun plugin which converts .csv
and .tsv
files into JavaScript modules.
Install
bun add bun-plugin-csv -d
Bundler Usage
import csv from 'bun-plugin-csv'
await Bun.build({
entrypoints: ['./src/index.ts'],
plugins: [csv()]
})
Suppose that you have a CSV which contains some info:
type,count
apples,7
pears,4
bananas,5
The import will provide an Array
of Objects
representing rows from the CSV file:
import fruit from './fruit.csv';
console.log(fruit);
Runtime usage
To use as a runtime plugin, create a file that registers the plugin:
import csv from 'bun-plugin-csv'
Bun.plugin(csv())
Then preload it in your bunfig.toml
:
preload = ['./csv.ts']
TypeScript Intellisense
Add the following to your .d.ts
file:
License
MIT