0.1.5 • Published 8 months ago

bun-plugin-csv v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
8 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/env" />

License

MIT

0.1.5

8 months ago

0.1.4

1 year ago

0.1.2

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago