oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager ā€“ all in one
https://bun.sh
Other
74.07k stars 2.76k forks source link

Import CSV files #6722

Open A-D-E-A opened 1 year ago

A-D-E-A commented 1 year ago

What is the problem this feature would solve?

I would like to import CSV data in my JS/TS code.

What is the feature you are proposing to solve the problem?

Since there are ways to import JSON, YAML and TOML, why not CSV?

I propose a plugin to import CSV files, either as a simple string[][] ([["col1", "col2", "col3"], [...], ...]) or as Record<string, string>[] when using headers ([{col1: "data1", col2: "data2", col3: "data3"}, ...]).

That plugin could do both by adding either an import attribute (though I don't think it's supported by the API yet) or a "query" after the file extension. Example:

import * as withoutHeaders from "./without-headers.csv";
import * as withHeaders from "./with-headers.csv?with-headers";

The plugin is quite easy to code and doesn't need libraries. I could open a PR.

What alternatives have you considered?

Electroid commented 1 year ago

If we were to support this, I think we would use import attributes for options.

import * as csv from "./file.csv" with { headers: true };
newbie-lad commented 10 months ago

why not CSV?

Is plan for bun (no pun) to add 1ā€‰000ā€‰000 features with no real standardisation? šŸž

// once javascript was underrated and no one wanted to use it, now it seems the other way

Although it would be cool to be able to do something natively, bun to me seems to be a Javascript runtime. Not a syntactic sugar.

bitdom8 commented 6 months ago

Any update please?

bitdom8 commented 6 months ago

@A-D-E-A thanks. is your code recognizing the changes made to CSV and hot reload bun?