11import fs from 'fs'
2+ import { readdir } from 'fs/promises'
23import path from 'path'
34import { fileURLToPath } from 'url'
45import { exit } from 'process'
@@ -35,12 +36,12 @@ const DATA_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '
3536
3637do {
3738 console . clear ( )
38- print ( `
39- ==========================
39+ print (
40+ ` ==========================
4041 WELCOME!
4142==========================
4243SIMPLE LINEAR REGRESSION DEMO
43- `)
44+ ` )
4445
4546 const answers = await select ( {
4647 message : 'Choose menu' ,
@@ -55,21 +56,11 @@ SIMPLE LINEAR REGRESSION DEMO
5556
5657
5758 switch ( answers ) {
58- case '1. Guide' :
59- await showGuide ( )
60- break ;
61- case '2. Run Demo' :
62- await runDemo ( )
63- break ;
64- case '3. Exit' :
65- print ( 'Thanks, bye!' )
66- exit ( 0 )
67- break ;
68- default :
69- print ( 'Invalid input!' )
70- break ;
59+ case '1. Guide' : await showGuide ( ) ; break ;
60+ case '2. Run Demo' : await runDemo ( ) ; break ;
61+ case '3. Exit' : print ( 'Thanks, bye!' ) ; exit ( 0 ) ;
7162 }
72- } while ( await confirm ( { message : '\nContinue program? ' } ) )
63+ } while ( await confirm ( { message : 'Continue program?' } ) )
7364
7465
7566
@@ -94,7 +85,7 @@ async function runDemo() {
9485 let files
9586 try {
9687 print ( 'Scanning data input file ...' )
97- files = fs . readdirSync ( DATA_DIR )
88+ files = await readdir ( DATA_DIR )
9889 } catch ( error ) {
9990 print ( chalk . red ( 'Error reading directory: ' , error . message ) )
10091 return ;
@@ -142,15 +133,16 @@ async function previewData(filePath) {
142133
143134 print ( table . toString ( ) )
144135
145- if ( await confirm ( { message : '\nContinue next process' } ) ) {
136+ if ( await confirm ( { message : 'Continue next process' } ) ) {
146137 await dataIdentification ( data )
147138 }
148139}
149140
150141
151142
152143async function dataIdentification ( data ) {
153- print ( '\n-----------------------------------------------------\n' )
144+ console . clear ( )
145+ print ( '-----------------------------------------------------\n' )
154146 print ( 'Data identification' )
155147
156148
@@ -165,14 +157,7 @@ async function dataIdentification(data) {
165157 console . clear ( )
166158
167159 switch ( answers ) {
168- case '1. Single feature' :
169- await singleFeatureProcess ( data )
170- break ;
171- case '2. Multi feature' :
172- await multiFeatureProcess ( data )
173- break ;
174- default :
175- print ( 'Invalid input!' )
176- break ;
160+ case '1. Single feature' : await singleFeatureProcess ( data ) ; break ;
161+ case '2. Multi feature' : await multiFeatureProcess ( data ) ; break ;
177162 }
178163}
0 commit comments