* Given a string, yields each part in the string terminated by a newline and * returns the final part without a newline.
(string: string)
| 7 | * returns the final part without a newline. |
| 8 | */ |
| 9 | function* yieldLinesFromString(string: string) { |
| 10 | // Strip out carraige returns. We can't simply look for \r\n because git can |
| 11 | // sometimes emit ansi color codes between \r and \n. |
| 12 | string = string.replace(/\r/g, ''); |
| 13 | |
| 14 | let lastIndex = 0; |
| 15 | let match: RegExpExecArray | null; |
| 16 | while ((match = NEWLINE_REGEX.exec(string))) { |
| 17 | yield string.slice(lastIndex, match.index); |
| 18 | lastIndex = match.index + match[0].length; |
| 19 | } |
| 20 | return string.slice(lastIndex); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Converts a readable stream to an iterator that yields the stream's contents |
no test coverage detected