Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export function parseTOML<T = unknown>(text: string): T {
*/
export function stringifyTOML(value: any): string {
const format = getFormat(value, { preserveIndentation: false });
const str = stringify(value);
const str = stringify(value).trimEnd();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return format.whitespace.start + str + format.whitespace.end;
}
12 changes: 12 additions & 0 deletions test/toml-roundtrip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vitest";
import { parseTOML, stringifyTOML } from "../src";

describe("TOML whitespace roundtrip", () => {
for (const source of ['name = "sample"\n', 'name = "sample"\n\n', 'name = "sample"']) {
it(`preserves final whitespace ${JSON.stringify(source)}`, () => {
const first = stringifyTOML(parseTOML(source));
expect(first).toBe(source);
expect(stringifyTOML(parseTOML(first))).toBe(first);
});
}
});