MCPcopy Create free account
hub / github.com/Snapchat/Valdi / eachLine

Function eachLine

npm_modules/cli/test/helpers/StreamHelpers.ts:1–13  ·  view source on GitHub ↗
(chunkOrString: Buffer | string)

Source from the content-addressed store, hash-verified

1export function* eachLine(chunkOrString: Buffer | string): Generator<Buffer | string> {
2 let position = 0;
3 const chunk = typeof chunkOrString === 'string' ? Buffer.from(chunkOrString) : chunkOrString;
4 while (position < chunk.length) {
5 const newline = chunk.indexOf('\n', position);
6 if (newline === -1) {
7 yield chunk.subarray(position).toString('utf8') + '\n';
8 break;
9 }
10 yield chunk.subarray(position, newline).toString('utf8') + `\n`;
11 position = newline + 1;
12 }
13}
14
15export async function* pipeEachLine(source: AsyncGenerator<Buffer | string>): AsyncGenerator<Buffer | string> {
16 for await (const chunk of source) {

Callers 2

insertLineFunction · 0.90
pipeEachLineFunction · 0.70

Calls 3

toStringMethod · 0.65
fromMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected