Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 9 additions & 8 deletions src/utils/resultsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ export function formatResult(queryResult: string | number): string {

export function convertToCsv(data: any[]): string[] {
const keys = Object.keys(data[0]);
const header = keys.join(",");
const rows = data.map((obj) => {
return keys
.map((key) => {
return obj[key];
})
.join(",");
});
const header = keys.map((k) => normalize(k)).join(",");
const rows = data.map((obj) =>
keys.map((key) => normalize(obj[key])).join(","),
);
return [header, ...rows];
}

function normalize(obj: any) {
const o = `${obj}`;
return `"${o.replace(/"/gs, '""')}"`;
}
2 changes: 1 addition & 1 deletion test/suite/webPanels/resultsPanelProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ describe("ResultsPanelProvider", () => {
{ a: "2", b: "2" },
{ a: "3", b: "3" },
];
const expectedOutput = ["a,b", "1,1", "2,2", "3,3"];
const expectedOutput = ['"a","b"', '"1","1"', '"2","2"', '"3","3"'];
const actualOutput = renderer.convertToCsv(inputQueryResult);
assert.deepStrictEqual(actualOutput, expectedOutput);
});
Expand Down