Separate out handler functions

This commit is contained in:
Nick Playfair 2025-06-11 13:41:32 +01:00
parent 5378da4fe2
commit 29ef5e92bf

View File

@ -1,5 +1,5 @@
//Modules //Modules
import { csvToJSON } from './csvToJSON'; import { getBOM } from './csvToJSON';
//DOM elements //DOM elements
const input = document.getElementById('csvInput') as HTMLInputElement; const input = document.getElementById('csvInput') as HTMLInputElement;
@ -13,16 +13,25 @@ function handleUpload(event: Event) {
//Read in from the file //Read in from the file
const reader = new FileReader(); const reader = new FileReader();
reader.onload = function (e) { reader.onload = function (e) {
const content = (e.target as FileReader).result; processCSV(e);
};
reader.readAsText(file);
}
}
function processCSV(fileReader: Event) {
const content = (fileReader.target as FileReader).result;
if (content === null) throw new Error('CSV Cannot be null.'); if (content === null) throw new Error('CSV Cannot be null.');
const csvString = content.toString(); const csvString = content.toString();
//Display the CSV contents //Display the CSV contents
csvTextOutput.innerText = csvString; csvTextOutput.innerText = csvString;
//Get JSON object from the file const bomJSON = createJSONbom(csvString);
console.log();
};
reader.readAsText(file);
} }
//TODO
async function createJSONbom(csvString: string) {
const bomJSON = await getBOM(csvString);
console.log(bomJSON);
} }
//Add event listener //Add event listener