1
0
Fork 0
mirror of synced 2024-07-30 02:26:11 +12:00

Add csvutils

This commit is contained in:
Adria Navarro 2023-05-02 10:34:45 +01:00
parent 608a38489f
commit 29df12c247
2 changed files with 8 additions and 2 deletions

View file

@ -10,7 +10,7 @@ import { getDatasourceParams } from "../../../db/utils"
import { context, events } from "@budibase/backend-core"
import { Table, UserCtx } from "@budibase/types"
import sdk from "../../../sdk"
import csv from "csvtojson"
import { jsonFromCsvString } from "../../../utilities/csv"
function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
if (table && !tableId) {
@ -104,7 +104,7 @@ export async function bulkImport(ctx: UserCtx) {
export async function csvToJson(ctx: UserCtx) {
const { csvString } = ctx.request.body
const result = await csv().fromString(csvString)
const result = await jsonFromCsvString(csvString)
ctx.status = 200
ctx.body = result

View file

@ -0,0 +1,6 @@
import csv from "csvtojson"
export async function jsonFromCsvString(csvString: string) {
const result = await csv().fromString(csvString)
return result
}