MCPcopy Create free account
hub / github.com/banga/git-split-diffs / yieldLinesFromString

Function yieldLinesFromString

src/iterLinesFromReadable.ts:9–21  ·  view source on GitHub ↗

* Given a string, yields each part in the string terminated by a newline and * returns the final part without a newline.

(string: string)

Source from the content-addressed store, hash-verified

7 * returns the final part without a newline.
8 */
9function* 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

Callers 1

iterlinesFromReadableFunction · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected