@@ -20,32 +20,36 @@ if(args.length === 0){
2020}
2121
2222const path = args [ 0 ] ;
23- const content = await fs . readFile ( path , "utf-8" )
23+ const content = await fs . readFile ( path , "utf-8" ) ;
2424
2525
2626// function to count the number of lines in a files
2727function countLines ( content ) {
28- const lines = content . split ( / \r ? \n / )
29- return lines . length
28+ const lines = content . split ( / \r ? \n / ) ;
29+ return lines . length ;
3030}
3131
3232//function to count the words
3333function countWords ( content ) {
3434 const words = content . trim ( ) . split ( / \s + / ) ;
35- return words . length
35+ return words . length ;
3636}
3737
3838//function to count the bytes
3939function countBytes ( content ) {
4040 return Buffer . byteLength ( content , "utf-8" ) ;
4141}
4242
43- if ( opts . line ) {
44- console . log ( countLines ( content ) )
45- } else if ( opts . words ) { console . log ( countWords ( content ) , path ) }
46- else if ( opts . bytes ) { console . log ( countBytes ( content ) , path ) }
47- else {
48- console . log ( countLines ( content ) , countWords ( content ) , countBytes ( content ) , path )
49- }
50-
51-
43+ const lines = countLines ( content ) ;
44+ const words = countWords ( content ) ;
45+ const bytes = countBytes ( content ) ;
46+
47+ if ( opts . line ) {
48+ console . log ( lines ) ;
49+ } else if ( opts . words ) {
50+ console . log ( words , path ) ;
51+ } else if ( opts . bytes ) {
52+ console . log ( bytes , path ) ;
53+ } else {
54+ console . log ( lines , words , bytes , path ) ;
55+ }
0 commit comments