File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 25
25
* console.log(buffer.flush())
26
26
*/
27
27
export class FileBuffer {
28
+ /**
29
+ * Whether to add an end-of-line character at the end of the output
30
+ */
31
+ #eol: boolean = false
32
+
28
33
/**
29
34
* Collected lines
30
35
*/
@@ -60,6 +65,21 @@ export class FileBuffer {
60
65
return this . #buffer. length
61
66
}
62
67
68
+ /**
69
+ * Enable or disable end-of-line character at the end of output
70
+ *
71
+ * @param enabled - Whether to add EOL character
72
+ * @returns This FileBuffer instance for method chaining
73
+ *
74
+ * @example
75
+ * const buffer = new FileBuffer()
76
+ * buffer.eol(true).writeLine('Hello').flush() // 'Hello\n\n'
77
+ */
78
+ eol ( enabled : boolean ) {
79
+ this . #eol = enabled
80
+ return this
81
+ }
82
+
63
83
/**
64
84
* Write a new line to the output with current indentation
65
85
*
@@ -115,6 +135,14 @@ export class FileBuffer {
115
135
return this
116
136
}
117
137
138
+ /**
139
+ * Convert the buffer to a string representation
140
+ *
141
+ * @example
142
+ * const buffer = new FileBuffer()
143
+ * buffer.writeLine('Hello')
144
+ * console.log(buffer.toString())
145
+ */
118
146
toString ( ) {
119
147
return this . flush ( )
120
148
}
@@ -133,6 +161,6 @@ export class FileBuffer {
133
161
}
134
162
135
163
this . #compiledOutput = this . #buffer. join ( '\n' )
136
- return this . #compiledOutput
164
+ return this . #eol ? ` ${ this . #compiledOutput } \n` : this . # compiledOutput
137
165
}
138
166
}
You can’t perform that action at this time.
0 commit comments