0.1.4 • Published 2 months ago

bun-plugin-csv v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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'],
  // other config

  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);
// [
//   { 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/client" />

License

MIT

0.1.4

2 months ago

0.1.2

8 months ago

0.1.3

4 months ago

0.1.1

9 months ago

0.1.0

9 months ago