File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,31 @@ class In {
23
23
this . content = fs . readFileSync ( this . fileName , 'utf8' ) . toString ( ) . trim ( )
24
24
}
25
25
26
+ /**
27
+ * Returns if the In is empty.
28
+ */
29
+ isEmpty ( ) {
30
+ return this . content . length === 0
31
+ }
32
+
33
+ /**
34
+ * Parses the file's content to and
35
+ * array of strings separated by new lines and whitespace,
36
+ * then, it returns the first element of the array.
37
+ */
38
+ readString ( ) {
39
+ if ( ! this . _isArrayOfStrings ) {
40
+ this . content = this . content . split ( / [ \n \r \s ] * / )
41
+ this . _isArrayOfStrings = true
42
+ }
43
+
44
+ if ( this . isEmpty ( ) ) throw new ReferenceError ( `stream ${ this . fileName } is empty` )
45
+
46
+ const string = this . content . shift ( )
47
+
48
+ return string
49
+ }
50
+
26
51
/**
27
52
* Parses the file's contents to Integers
28
53
* @returns {[number] } The array of parsed integers.
You can’t perform that action at this time.
0 commit comments