@@ -30,7 +30,7 @@ document.addEventListener('DOMContentLoaded', function () {
3030 document . getElementById ( 'header-index' ) . addEventListener ( 'input' , updateOptions ) ;
3131 document . getElementById ( 'use-streaming' ) . addEventListener ( 'change' , updateOptions ) ;
3232 document . getElementById ( 'use-chunked' ) . addEventListener ( 'change' , toggleChunkedOptions ) ;
33-
33+ document . getElementById ( 'use-chunked' ) . disabled = true ;
3434
3535 // File input change
3636 document . getElementById ( 'csv-file' ) . addEventListener ( 'change' , handleFileSelect ) ;
@@ -94,12 +94,20 @@ function updateOptions() {
9494 const quotedFields = document . getElementById ( 'quoted-fields' ) . checked ;
9595 const delimiter = document . getElementById ( 'delimiter' ) . value ;
9696 const headerIndex = parseInt ( document . getElementById ( 'header-index' ) . value ) || 0 ;
97-
9897 csvToJson . formatValueByType ( formatValues ) ;
98+
9999 csvToJson . supportQuotedField ( quotedFields ) ;
100100 csvToJson . fieldDelimiter ( delimiter ) ;
101101 csvToJson . indexHeader ( headerIndex ) ;
102-
102+ const useStreaming = document . getElementById ( 'use-streaming' ) ;
103+ const useChunk = document . getElementById ( 'use-chunked' ) ;
104+ if ( useStreaming . checked ) {
105+ useChunk . disabled = false ;
106+ } else {
107+ useChunk . disabled = true ;
108+ useChunk . removeAttr ( 'checked' ) ;
109+ }
110+
103111}
104112
105113function toggleChunkedOptions ( ) {
@@ -152,6 +160,7 @@ async function convert() {
152160 const output = document . getElementById ( 'output' ) ;
153161 const convertBtn = document . getElementById ( 'convert-btn' ) ;
154162
163+
155164 // Clear previous output
156165 clearOutput ( ) ;
157166
@@ -189,8 +198,20 @@ async function convert() {
189198 await processFileInChunks ( fileInput . files [ 0 ] , chunkSize ) ;
190199 } else if ( useStreaming ) {
191200 // Use streaming API
201+ const output = document . getElementById ( 'output' ) ;
202+ output . classList . remove ( 'hidden' ) ;
203+ initProgressDisplay ( output ) ;
204+ const startTime = performance . now ( ) ;
192205 result = await csvToJson . getJsonFromFileStreamingAsync ( fileInput . files [ 0 ] ) ;
206+ console . log ( result ) ;
193207 displayResult ( result ) ;
208+ const endTime = performance . now ( ) ;
209+ const takenTimeInMs = Math . floor ( endTime - startTime ) ;
210+ const takenTimeInSeconds = Math . floor ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
211+ document . getElementById ( 'progress-fill' ) . style . width = '100%' ;
212+ document . getElementById ( 'progress-text' ) . textContent = `Complete! Processed ${ result . length } rows in ${ takenTimeInSeconds } seconds (${ takenTimeInMs } milliseconds)` ;
213+
214+
194215 } else {
195216 // Use regular file parsing
196217 result = await csvToJson . parseFile ( fileInput . files [ 0 ] ) ;
@@ -206,6 +227,23 @@ async function convert() {
206227 }
207228}
208229
230+ function removeProgressDisplay ( ) {
231+ const progressDisplay = document . getElementById ( 'progress-display' ) ;
232+ if ( progressDisplay ) {
233+ progressDisplay . remove ( ) ;
234+ }
235+ }
236+
237+ function initProgressDisplay ( output ) {
238+ removeProgressDisplay ( ) ;
239+
240+ // Create progress display
241+ const progressDiv = document . createElement ( 'div' ) ;
242+ progressDiv . id = 'progress-display' ;
243+ progressDiv . innerHTML = '<h4>Processing large file...</h4><div id="progress-bar" style="width: 100%; background: #f0f0f0; height: 20px; border-radius: 10px; margin: 10px 0;"><div id="progress-fill" style="width: 0%; height: 100%; background: linear-gradient(135deg, #007bff 0%, #0056b3 100%); border-radius: 10px; transition: width 0.3s;"></div></div><div id="progress-text">Initializing...</div>' ;
244+ output . insertBefore ( progressDiv , output . firstChild ) ;
245+ }
246+
209247async function processFileInChunks ( file , chunkSize ) {
210248 const output = document . getElementById ( 'output' ) ;
211249 const jsonOutput = document . getElementById ( 'json-output' ) ;
@@ -220,13 +258,10 @@ async function processFileInChunks(file, chunkSize) {
220258 let allRows = [ ] ;
221259 let totalProcessed = 0 ;
222260
223- // Create progress display
224- const progressDiv = document . createElement ( 'div' ) ;
225- progressDiv . id = 'progress-display' ;
226- progressDiv . innerHTML = '<h4>Processing large file...</h4><div id="progress-bar" style="width: 100%; background: #f0f0f0; height: 20px; border-radius: 10px; margin: 10px 0;"><div id="progress-fill" style="width: 0%; height: 100%; background: linear-gradient(135deg, #007bff 0%, #0056b3 100%); border-radius: 10px; transition: width 0.3s;"></div></div><div id="progress-text">Initializing...</div>' ;
227- output . insertBefore ( progressDiv , output . firstChild ) ;
261+ initProgressDisplay ( output ) ;
228262
229263 try {
264+ const startTime = performance . now ( ) ;
230265 await csvToJson . getJsonFromFileStreamingAsyncWithCallback ( file , {
231266 chunkSize : chunkSize ,
232267 onChunk : ( rows , processed , total ) => {
@@ -249,36 +284,33 @@ async function processFileInChunks(file, chunkSize) {
249284 } ,
250285 onComplete : ( allRowsComplete ) => {
251286 console . log ( 'onComplete called' , allRowsComplete . length ) ;
287+ const endTime = performance . now ( ) ;
288+ const takenTimeInMs = Math . floor ( endTime - startTime ) ;
289+ const takenTimeInSeconds = Math . floor ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
252290 allRows = allRowsComplete ;
253291
254292 // Update progress to 100%
255293 document . getElementById ( 'progress-fill' ) . style . width = '100%' ;
256- document . getElementById ( 'progress-text' ) . textContent = `Complete! Processed ${ allRows . length } rows. ` ;
294+ document . getElementById ( 'progress-text' ) . textContent = `Complete! Processed ${ allRows . length } rows in ${ takenTimeInSeconds } seconds ( ${ takenTimeInMs } milliseconds) ` ;
257295
258296 // Display final results
259297 jsonOutput . textContent = JSON . stringify ( allRows , null , 2 ) ;
260298 displayStats ( allRows ) ;
261299 displayTable ( allRows ) ;
262300 showOutputTab ( 'table' ) ;
263301
264- // Remove progress after a delay
265- setTimeout ( ( ) => {
266- const progressDisplay = document . getElementById ( 'progress-display' ) ;
267- if ( progressDisplay ) progressDisplay . remove ( ) ;
268- } , 3000 ) ;
302+
269303 } ,
270304 onError : ( error ) => {
271305 console . error ( 'Error:' , error ) ;
272306 displayError ( error ) ;
273- const progressDisplay = document . getElementById ( 'progress-display' ) ;
274- if ( progressDisplay ) progressDisplay . remove ( ) ;
307+ removeProgressDisplay ( ) ;
275308 }
276309 } ) ;
277310 } catch ( error ) {
278311 console . error ( 'Catch error:' , error ) ;
279312 displayError ( error ) ;
280- const progressDisplay = document . getElementById ( 'progress-display' ) ;
281- if ( progressDisplay ) progressDisplay . remove ( ) ;
313+ removeProgressDisplay ( ) ;
282314 }
283315}
284316
@@ -373,6 +405,7 @@ function displayError(error) {
373405}
374406
375407function clearOutput ( ) {
408+ removeProgressDisplay ( ) ;
376409 const output = document . getElementById ( 'output' ) ;
377410 const jsonOutput = document . getElementById ( 'json-output' ) ;
378411 const tableOutput = document . getElementById ( 'table-output' ) ;
0 commit comments