bun-plugin-csv
v0.1.5
Published
A Bun plugin which converts .csv and .tsv files into JavaScript modules.
Readme
bun-plugin-csv
A Bun plugin which converts .csv and .tsv files into JavaScript modules.
Install
bun add bun-plugin-csv -dBundler Usage
import csv from 'bun-plugin-csv'
await Bun.build({
entrypoints: ['./src/index.ts'],
// other config
plugins: [csv()]
})Suppose that you have a CSV which contains some info:
type,count
apples,7
pears,4
bananas,5The import will provide an Array of Objects representing rows from the CSV file:
import fruit from './fruit.csv';
console.log(fruit);
// [
// { type: 'apples', count: '7' },
// { type: 'pears', count: '4' },
// { type: 'bananas', count: '5' }
// ]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:
/// <reference types="bun-plugin-csv/env" />License
MIT
