@@ -118,6 +118,7 @@ function toggleChunkedOptions() {
118118 } else {
119119 chunkedOptions . style . display = 'none' ;
120120 }
121+
121122}
122123
123124function handleFileSelect ( event ) {
@@ -127,6 +128,19 @@ function handleFileSelect(event) {
127128 const size = ( file . size / 1024 / 1024 ) . toFixed ( 2 ) ;
128129 fileInfo . innerHTML = `Selected file: ${ file . name } (${ size } MB)` ;
129130 fileInfo . style . display = 'block' ;
131+ const useStreaming = document . getElementById ( 'use-streaming' ) ;
132+ if ( file . size > 1000000 ) {
133+ useStreaming . checked = true ;
134+ useStreaming . disabled = true ;
135+ updateOptions ( ) ;
136+ } else {
137+ const useChecked = document . getElementById ( 'use-chunked' ) ;
138+ useStreaming . checked = false ;
139+ useStreaming . disabled = false ;
140+ useChecked . checked = false ;
141+ useChecked . disabled = true ;
142+ updateOptions ( ) ;
143+ }
130144 }
131145}
132146
@@ -203,19 +217,23 @@ async function convert() {
203217 initProgressDisplay ( output ) ;
204218 const startTime = performance . now ( ) ;
205219 result = await csvToJson . getJsonFromFileStreamingAsync ( fileInput . files [ 0 ] ) ;
206- console . log ( result ) ;
207220 displayResult ( result ) ;
208221 const endTime = performance . now ( ) ;
209222 const takenTimeInMs = Math . floor ( endTime - startTime ) ;
210223 const takenTimeInSeconds = ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
211224 document . getElementById ( 'progress-fill' ) . style . width = '100%' ;
212- document . getElementById ( 'progress-text' ) . textContent = `Complete! Processed ${ result . length } rows in ${ takenTimeInSeconds } seconds (${ takenTimeInMs } milliseconds)` ;
213225
226+ const statsOutput = document . getElementById ( 'stats-output' ) ;
227+
228+ statsOutput . innerHTML += `
229+ <div><strong>Processed:</strong> in ${ takenTimeInSeconds } seconds (${ takenTimeInMs } milliseconds)</div>
230+ ` ;
214231
215232 } else {
216233 // Use regular file parsing
217234 result = await csvToJson . parseFile ( fileInput . files [ 0 ] ) ;
218235 displayResult ( result ) ;
236+
219237 }
220238 }
221239 } catch ( error ) {
@@ -224,6 +242,10 @@ async function convert() {
224242 // Re-enable button
225243 convertBtn . disabled = false ;
226244 convertBtn . textContent = 'Convert to JSON' ;
245+ setTimeout ( ( ) => {
246+ removeProgressDisplay ( ) ;
247+ } , 1500 ) ;
248+
227249 }
228250}
229251
@@ -240,7 +262,7 @@ function initProgressDisplay(output) {
240262 // Create progress display
241263 const progressDiv = document . createElement ( 'div' ) ;
242264 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>' ;
265+ progressDiv . innerHTML = '<h5 >Processing large file...</h5 ><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>' ;
244266 output . insertBefore ( progressDiv , output . firstChild ) ;
245267}
246268
@@ -283,7 +305,6 @@ async function processFileInChunks(file, chunkSize) {
283305 }
284306 } ,
285307 onComplete : ( allRowsComplete ) => {
286- console . log ( 'onComplete called' , allRowsComplete . length ) ;
287308 const endTime = performance . now ( ) ;
288309 const takenTimeInMs = Math . floor ( endTime - startTime ) ;
289310 const takenTimeInSeconds = ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
@@ -297,9 +318,8 @@ async function processFileInChunks(file, chunkSize) {
297318 jsonOutput . textContent = JSON . stringify ( allRows , null , 2 ) ;
298319 displayStats ( allRows ) ;
299320 displayTable ( allRows ) ;
321+ displayDownloadButton ( ) ;
300322 showOutputTab ( 'table' ) ;
301-
302-
303323 } ,
304324 onError : ( error ) => {
305325 console . error ( 'Error:' , error ) ;
@@ -331,6 +351,7 @@ function displayResult(result) {
331351
332352 // Display stats
333353 displayStats ( result ) ;
354+ displayDownloadButton ( ) ;
334355
335356 // Show table tab by default
336357 showOutputTab ( 'table' ) ;
@@ -367,11 +388,16 @@ function displayTable(data) {
367388 } ) ;
368389 html += '</tbody></table>' ;
369390
391+ tableOutput . innerHTML = html ;
392+ displayTableTitle ( data ) ;
393+ }
394+
395+ function displayTableTitle ( data ) {
396+ const maxRows = 1000 ;
397+ const tableTitle = document . getElementById ( 'table-title' ) ;
370398 if ( data . length > maxRows ) {
371- html = `<p><b>Showing first ${ maxRows } rows only. Full data is available in JSON view and row count is shown in stats. </h4></p>${ html } ` ;
399+ tableTitle . innerHTML = `<p><b>Showing first ${ maxRows } rows only. Full data is available in JSON View for files containing less than 1,000 lines. For bigger files click to the Download JSON button. </h4></p>` ;
372400 }
373-
374- tableOutput . innerHTML = html ;
375401}
376402
377403function displayStats ( data ) {
@@ -392,6 +418,20 @@ function displayStats(data) {
392418 }
393419}
394420
421+ function displayDownloadButton ( ) {
422+ const downloadButton = document . getElementById ( 'download-json-btn' ) ;
423+ downloadButton . classList . remove ( 'hidden' ) ;
424+ downloadButton . classList . remove ( 'download-btn-hidden' ) ;
425+ downloadButton . classList . add ( 'download-btn' ) ;
426+ }
427+
428+ function hideDownloadButton ( ) {
429+ const downloadButton = document . getElementById ( 'download-json-btn' ) ;
430+ downloadButton . classList . add ( 'hidden' ) ;
431+ downloadButton . classList . add ( 'download-btn-hidden' ) ;
432+ downloadButton . classList . remove ( 'download-btn' ) ;
433+ }
434+
395435function displayError ( error ) {
396436 const output = document . getElementById ( 'output' ) ;
397437 const errorOutput = document . getElementById ( 'error-output' ) ;
@@ -425,6 +465,10 @@ function clearAll() {
425465 document . getElementById ( 'csv-input' ) . value = '' ;
426466 document . getElementById ( 'csv-file' ) . value = '' ;
427467 document . getElementById ( 'file-info' ) . style . display = 'none' ;
468+ document . getElementById ( 'use-streaming' ) . checked = false ;
469+ document . getElementById ( 'use-chunked' ) . checked = false ;
470+ toggleChunkedOptions ( ) ;
471+ hideDownloadButton ( ) ;
428472}
429473
430474function downloadJSON ( ) {
0 commit comments