Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wobsoriano/bun-plugin-csv
A Bun plugin which converts .csv and .tsv files into JavaScript modules.
https://github.com/wobsoriano/bun-plugin-csv
bun csv
Last synced: 3 months ago
JSON representation
A Bun plugin which converts .csv and .tsv files into JavaScript modules.
- Host: GitHub
- URL: https://github.com/wobsoriano/bun-plugin-csv
- Owner: wobsoriano
- License: mit
- Created: 2023-08-02T07:23:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-26T06:15:16.000Z (11 months ago)
- Last Synced: 2024-10-02T08:52:05.453Z (3 months ago)
- Topics: bun, csv
- Language: TypeScript
- Homepage:
- Size: 101 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bun-plugin-csv
A Bun plugin which converts `.csv` and `.tsv` files into JavaScript modules.
## Install
```bash
bun add bun-plugin-csv -d
```## Bundler Usage
```ts
import csv from 'bun-plugin-csv'await Bun.build({
entrypoints: ['./src/index.ts'],
// other configplugins: [csv()]
})
```Suppose that you have a CSV which contains some info:
```csv
type,count
apples,7
pears,4
bananas,5
```The import will provide an `Array` of `Objects` representing rows from the CSV file:
```ts
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:
```ts
import csv from 'bun-plugin-csv'Bun.plugin(csv())
```Then preload it in your `bunfig.toml`:
```toml
preload = ['./csv.ts']
```## TypeScript Intellisense
Add the following to your `.d.ts` file:
```ts
///
```## License
MIT