From 29ef5e92bfc49c64ef5aad081f4b9a522133f165 Mon Sep 17 00:00:00 2001 From: Nick Playfair <842413+nplayfair@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:41:32 +0100 Subject: [PATCH] Separate out handler functions --- src/index.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8fb927a..1672ca7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ //Modules -import { csvToJSON } from './csvToJSON'; +import { getBOM } from './csvToJSON'; //DOM elements const input = document.getElementById('csvInput') as HTMLInputElement; @@ -13,18 +13,27 @@ function handleUpload(event: Event) { //Read in from the file const reader = new FileReader(); reader.onload = function (e) { - const content = (e.target as FileReader).result; - if (content === null) throw new Error('CSV Cannot be null.'); - const csvString = content.toString(); - //Display the CSV contents - csvTextOutput.innerText = csvString; - //Get JSON object from the file - console.log(); + 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.'); + const csvString = content.toString(); + //Display the CSV contents + csvTextOutput.innerText = csvString; + const bomJSON = createJSONbom(csvString); +} + +//TODO +async function createJSONbom(csvString: string) { + const bomJSON = await getBOM(csvString); + console.log(bomJSON); +} + //Add event listener input.addEventListener('change', handleUpload);