oven-sh / bun

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

Add TOML support to BunFile interface #2798

Open Kruithne opened 1 year ago

Kruithne commented 1 year ago

What is the problem this feature would solve?

Bun provides support for JSON, TOML and TXT imports via the ESM syntax. In contrast, the BunFile interface only provides parsing for JSON and TXT via .json() and .text() respectively.

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

Since Bun already has support for TOML for the ESM import syntax, it should be expanded to the BunFile interface as a .toml() function, exactly the same as the .json() which already exists.

# test.toml
[[icecream]]
flavor = "chocolate"
// test.ts
const file = Bun.file('./test.toml');
const parsed = await file.toml();

console.log(parsed);

// Output
// {
//   "icecream": [
//     {
//       "flavor": "chocolate"
//     }
//   ]
// }

What alternatives have you considered?

No response

Jarred-Sumner commented 11 months ago

reasonable