allows additional CSV delimiters
This commit is contained in:
parent
fd1dee993a
commit
a52cdbe54d
|
@ -1511,5 +1511,20 @@ datasourceDescribe(
|
|||
})
|
||||
})
|
||||
})
|
||||
describe("csvToJson", () => {
|
||||
const delimiters = [",", ";", ":", "|", "~", "\t", " "]
|
||||
it.only.each(delimiters)(
|
||||
"can parse CSVs with delimiter; %s",
|
||||
async delimiter => {
|
||||
const rows = await config.api.table.csvToJson({
|
||||
csvString: [
|
||||
["a", "b", "c", "d", "e"].join(delimiter),
|
||||
["1", "2", "3", "4", "5"].join(delimiter),
|
||||
].join("\n"),
|
||||
})
|
||||
expect(rows).toEqual([{ a: "1", b: "2", c: "3", d: "4", e: "5" }])
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
|
|
@ -9,7 +9,10 @@ export async function jsonFromCsvString(csvString: string) {
|
|||
// is causing issues on conversion. ignoreEmpty will remove the key completly
|
||||
// if empty, so creating this empty object will ensure we return the values
|
||||
// with the keys but empty values
|
||||
const result = await csv({ ignoreEmpty: false }).fromString(csvString)
|
||||
const result = await csv({
|
||||
ignoreEmpty: false,
|
||||
delimiter: [",", ";", ":", "|", "~", "\t", " "],
|
||||
}).fromString(csvString)
|
||||
result.forEach((r, i) => {
|
||||
for (const [key] of Object.entries(r).filter(([, value]) => value === "")) {
|
||||
if (castedWithEmptyValues[i][key] === undefined) {
|
||||
|
|
Loading…
Reference in New Issue