@@ -41,22 +41,23 @@ function myLineReader(file) {
4141/**
4242 * line by line diff of two files
4343 */
44- class FileDiffLine extends EventEmitter {
44+ class TextFileDiff extends EventEmitter {
4545 /**
4646 * initialize FileDiff
47- * @param { [type] } options [description]
48- * @return { [type] } [description]
47+ * @param Object options the options option
48+ * @return Object self
4949 */
5050 constructor ( options ) {
5151 super ( ) ;
5252 Object . assign ( this , options ) ;
53+ return this ;
5354 }
5455
5556 /**
5657 * run diff
5758 * @param String file1 path to file 1
5859 * @param String file2 path to file 2
59- * @return Object this
60+ * @return Object self
6061 */
6162 diff ( file1 , file2 ) {
6263 const lineReader1 = myLineReader ( file1 ) ;
@@ -71,33 +72,33 @@ class FileDiffLine extends EventEmitter {
7172
7273 // while both files has valid val
7374 while ( lineReader1 . val || lineReader2 . val ) {
74- // foreach line of file1 , compare each line of file2
75+ // ForEach line in File1 , compare to line in File2
7576 const line1 = lineReader1 . val . toString ( charset ) ;
7677 const line2 = lineReader2 . val . toString ( charset ) ;
7778 const cmp = compareFn ( line1 , line2 ) ;
7879
7980 // emit on compared
8081 this . emit ( 'compared' , line1 , line2 , cmp , lineReader1 , lineReader2 ) ;
8182
82- // equals: so both inc both lines position
83+ // equals: incr both files to next line
8384 if ( cmp === 0 ) {
8485 lineReader1 . moveNext ( ) ;
8586 lineReader2 . moveNext ( ) ;
8687 } else if ( cmp > 0 ) {
87- // line1 > line2: must be new line in file2
88+ // line1 > line2: new line detected
8889 if ( cmp === 1 ) {
8990 this . emit ( '+' , line2 , lineReader1 , lineReader2 ) ;
9091 }
9192
92- // inc file2 to next line
93+ // incr File2 to next line
9394 lineReader2 . moveNext ( ) ;
9495 } else if ( cmp < 0 ) {
95- // line1 < line2: must be new line in file2
96+ // line1 < line2: deleted line
9697 if ( cmp === - 1 ) {
9798 this . emit ( '-' , line1 , lineReader1 , lineReader2 ) ;
9899 }
99100
100- // inc file1 to next line
101+ // incr File1 to next line
101102 lineReader1 . moveNext ( ) ;
102103 }
103104 }
@@ -106,4 +107,4 @@ class FileDiffLine extends EventEmitter {
106107 }
107108}
108109
109- module . exports = FileDiffLine ;
110+ module . exports = TextFileDiff ;
0 commit comments