1+ "use strict" ;
12// Demo JavaScript code
2- csvToJson = window . csvToJson ;
3+ const csvToJson = window . csvToJson ;
34
45// Initialize when DOM is loaded
56document . addEventListener ( 'DOMContentLoaded' , function ( ) {
@@ -66,8 +67,9 @@ function showTab(tabName) {
6667function toggleFileOnlyOptions ( ) {
6768 const activeTab = document . querySelector ( '.tab-content.active' ) . id ;
6869 const fileOnlyOptions = document . getElementById ( 'file-only-options' ) ;
69- if ( ! fileOnlyOptions ) return ;
70-
70+ if ( ! fileOnlyOptions ) {
71+ return ;
72+ }
7173 if ( activeTab === 'file-tab' ) {
7274 fileOnlyOptions . style . display = 'block' ;
7375 } else {
@@ -129,11 +131,11 @@ function handleFileSelect(event) {
129131 fileInfo . innerHTML = `Selected file: ${ file . name } (${ size } MB)` ;
130132 fileInfo . style . display = 'block' ;
131133 const useStreaming = document . getElementById ( 'use-streaming' ) ;
132- if ( file . size > 1000000 ) {
134+ if ( file . size > 1000000 ) {
133135 useStreaming . checked = true ;
134136 useStreaming . disabled = true ;
135137 updateOptions ( ) ;
136- } else {
138+ } else {
137139 const useChecked = document . getElementById ( 'use-chunked' ) ;
138140 useStreaming . checked = false ;
139141 useStreaming . disabled = false ;
@@ -171,13 +173,9 @@ Seminar,2024-03-10,200`,
171173}
172174
173175async function convert ( ) {
174- const output = document . getElementById ( 'output' ) ;
175176 const convertBtn = document . getElementById ( 'convert-btn' ) ;
176-
177-
178177 // Clear previous output
179178 clearOutput ( ) ;
180-
181179 // Disable button during conversion
182180 convertBtn . disabled = true ;
183181 convertBtn . textContent = 'Converting...' ;
@@ -220,7 +218,7 @@ async function convert() {
220218 displayResult ( result ) ;
221219 const endTime = performance . now ( ) ;
222220 const takenTimeInMs = Math . floor ( endTime - startTime ) ;
223- const takenTimeInSeconds = ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
221+ const takenTimeInSeconds = ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
224222 document . getElementById ( 'progress-fill' ) . style . width = '100%' ;
225223
226224 const statsOutput = document . getElementById ( 'stats-output' ) ;
@@ -242,7 +240,7 @@ async function convert() {
242240 // Re-enable button
243241 convertBtn . disabled = false ;
244242 convertBtn . textContent = 'Convert to JSON' ;
245- setTimeout ( ( ) => {
243+ setTimeout ( ( ) => {
246244 removeProgressDisplay ( ) ;
247245 } , 1500 ) ;
248246
@@ -262,15 +260,13 @@ function initProgressDisplay(output) {
262260 // Create progress display
263261 const progressDiv = document . createElement ( 'div' ) ;
264262 progressDiv . id = 'progress-display' ;
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>' ;
263+ 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.5s ;"></div></div>' ;
266264 output . insertBefore ( progressDiv , output . firstChild ) ;
267265}
268266
269267async function processFileInChunks ( file , chunkSize ) {
270268 const output = document . getElementById ( 'output' ) ;
271269 const jsonOutput = document . getElementById ( 'json-output' ) ;
272- const tableOutput = document . getElementById ( 'table-output' ) ;
273- const statsOutput = document . getElementById ( 'stats-output' ) ;
274270
275271 // Show results container
276272 output . classList . remove ( 'hidden' ) ;
@@ -283,7 +279,6 @@ async function processFileInChunks(file, chunkSize) {
283279 initProgressDisplay ( output ) ;
284280
285281 try {
286- const startTime = performance . now ( ) ;
287282 await csvToJson . getJsonFromFileStreamingAsyncWithCallback ( file , {
288283 chunkSize : chunkSize ,
289284 onChunk : ( rows , processed , total ) => {
@@ -295,8 +290,6 @@ async function processFileInChunks(file, chunkSize) {
295290 // Update progress
296291 const progressPercent = total ? Math . round ( ( processed / total ) * 100 ) : Math . min ( Math . round ( ( processed / 10000 ) * 100 ) , 95 ) ;
297292 document . getElementById ( 'progress-fill' ) . style . width = progressPercent + '%' ;
298- document . getElementById ( 'progress-text' ) . textContent = `Processed ${ processed } rows...` ;
299-
300293 // For very large files, show the first 1000 rows only
301294 if ( allRows . length <= 1000 ) {
302295 displayTable ( allRows ) ;
@@ -305,15 +298,9 @@ async function processFileInChunks(file, chunkSize) {
305298 }
306299 } ,
307300 onComplete : ( allRowsComplete ) => {
308- const endTime = performance . now ( ) ;
309- const takenTimeInMs = Math . floor ( endTime - startTime ) ;
310- const takenTimeInSeconds = ( ( takenTimeInMs ) / 1000 ) . toFixed ( 2 ) ;
311301 allRows = allRowsComplete ;
312-
313302 // Update progress to 100%
314303 document . getElementById ( 'progress-fill' ) . style . width = '100%' ;
315- document . getElementById ( 'progress-text' ) . textContent = `Complete! Processed ${ allRows . length } rows in ${ takenTimeInSeconds } seconds (${ takenTimeInMs } milliseconds)` ;
316-
317304 // Display final results
318305 jsonOutput . textContent = JSON . stringify ( allRows , null , 2 ) ;
319306 displayStats ( allRows ) ;
@@ -337,8 +324,6 @@ async function processFileInChunks(file, chunkSize) {
337324function displayResult ( result ) {
338325 const output = document . getElementById ( 'output' ) ;
339326 const jsonOutput = document . getElementById ( 'json-output' ) ;
340- const tableOutput = document . getElementById ( 'table-output' ) ;
341- const statsOutput = document . getElementById ( 'stats-output' ) ;
342327
343328 // Show results container
344329 output . classList . remove ( 'hidden' ) ;
@@ -446,7 +431,6 @@ function displayError(error) {
446431
447432function clearOutput ( ) {
448433 removeProgressDisplay ( ) ;
449- const output = document . getElementById ( 'output' ) ;
450434 const jsonOutput = document . getElementById ( 'json-output' ) ;
451435 const tableOutput = document . getElementById ( 'table-output' ) ;
452436 const statsOutput = document . getElementById ( 'stats-output' ) ;
@@ -474,8 +458,9 @@ function clearAll() {
474458function downloadJSON ( ) {
475459 const jsonOutput = document . getElementById ( 'json-output' ) ;
476460 const data = jsonOutput . textContent ;
477- if ( ! data ) return ;
478-
461+ if ( ! data ) {
462+ return ;
463+ }
479464 const blob = new Blob ( [ data ] , { type : 'application/json' } ) ;
480465 const url = URL . createObjectURL ( blob ) ;
481466 const a = document . createElement ( 'a' ) ;
0 commit comments