(maxCharacters: number)
| 171 | } |
| 172 | |
| 173 | drain(maxCharacters: number): { output: string; truncated: boolean } { |
| 174 | if (!Number.isInteger(maxCharacters) || maxCharacters < 1) { |
| 175 | throw new Error("Output limit must be a positive integer."); |
| 176 | } |
| 177 | |
| 178 | const omittedByBuffer = Math.max( |
| 179 | 0, |
| 180 | this.totalCharacters - codePointLength(this.head) - codePointLength(this.tail), |
| 181 | ); |
| 182 | const retained = formatHeadTail(this.head, this.tail, omittedByBuffer); |
| 183 | const output = truncateOutput(retained, maxCharacters); |
| 184 | const truncated = omittedByBuffer > 0 || output.truncated; |
| 185 | |
| 186 | this.head = ""; |
| 187 | this.tail = ""; |
| 188 | this.totalCharacters = 0; |
| 189 | |
| 190 | return { output: output.output, truncated }; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | function truncateOutput(output: string, maxCharacters: number): { output: string; truncated: boolean } { |
no test coverage detected