Refactor csv to JSON function
This commit is contained in:
parent
20557ccf58
commit
5378da4fe2
@ -5,33 +5,12 @@ const csv = require('csvtojson');
|
||||
//CSV Config for EAGLE BOM
|
||||
const csvConfig = {
|
||||
delimiter: `;`,
|
||||
// quote: 'off',
|
||||
quote: '"',
|
||||
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);
|
||||
});
|
||||
export async function getBOM(csvBOM: string) {
|
||||
const bom = await csv(csvConfig).fromString(csvBOM);
|
||||
return bom;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user