From 20557ccf58e4d473c287691030648e98a6d8483f Mon Sep 17 00:00:00 2001 From: Nick Playfair <842413+nplayfair@users.noreply.github.com> Date: Tue, 10 Jun 2025 18:06:32 +0100 Subject: [PATCH] Remove extraneous quotes from CSV so it doesn't break the JSON --- src/csvToJSON.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/csvToJSON.ts b/src/csvToJSON.ts index 21bdabc..92a01fb 100644 --- a/src/csvToJSON.ts +++ b/src/csvToJSON.ts @@ -1,8 +1,35 @@ +import { CSVParseParam } from '../node_modules/csvtojson/v2/Parameters'; import { isJunk } from './utils'; const csv = require('csvtojson'); -export function csvToJSON(csvBOM: string): void { - csv() +//CSV Config for EAGLE BOM +const csvConfig = { + delimiter: `;`, + // quote: 'off', + ignoreEmpty: true, + includeColumns: /(Part|Value)/, +}; + +export async function csvToJSON(csvBOM: string) { + // csv() + // .fromString(csvBOM) + // .then((jsonObj: object) => { + // console.log(jsonObj); + // }); + const obj: object = await csv({ csvConfig }) + .preRawData((csvRawData: string) => { + return new Promise((resolve, reject) => { + var newData = csvRawData.replace('"', ''); + resolve(newData); + }); + }) + .fromString(csvBOM) + .then((jsonObj: object) => { + return jsonObj; + }); +} +export function simpleCsvToJSON(csvBOM: string) { + csv({ csvConfig }) .fromString(csvBOM) .then((jsonObj: object) => { console.log(jsonObj);