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
|
//CSV Config for EAGLE BOM
|
||||||
const csvConfig = {
|
const csvConfig = {
|
||||||
delimiter: `;`,
|
delimiter: `;`,
|
||||||
// quote: 'off',
|
quote: '"',
|
||||||
ignoreEmpty: true,
|
ignoreEmpty: true,
|
||||||
includeColumns: /(Part|Value)/,
|
includeColumns: /(Part|Value)/,
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function csvToJSON(csvBOM: string) {
|
export async function getBOM(csvBOM: string) {
|
||||||
// csv()
|
const bom = await csv(csvConfig).fromString(csvBOM);
|
||||||
// .fromString(csvBOM)
|
return bom;
|
||||||
// .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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user