This commit is contained in:
Asher Gomez 2023-11-03 12:08:06 +11:00
parent fdcec21070
commit 4e50956b4d
2 changed files with 19 additions and 2 deletions

View File

@ -12,7 +12,7 @@ export interface TextLineStreamOptions {
/**
* Transform a stream into a stream where each chunk is divided by a newline,
* be it `\n` or `\r\n`.
* be it `\n` or `\r\n`. `\r` can be enabled via the `allowCR` option.
*
* @example
* ```ts

View File

@ -24,6 +24,15 @@ Deno.test("TextLineStream() parses simple input", async () => {
"",
"654321\r",
]);
const stream2 = ReadableStream.from("rewq0987\r\n\r\n654321\n")
.pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream2), [
"rewq0987",
"",
"654321",
]);
});
Deno.test("TextLineStream() parses with `allowCR` enabled", async () => {
@ -35,7 +44,6 @@ Deno.test("TextLineStream() parses with `allowCR` enabled", async () => {
"\nrewq0987\n\n654321",
"\nrewq0987\r\n\r\n654321\r",
]).pipeThrough(new TextLineStream({ allowCR: true }));
assertEquals(await Array.fromAsync(stream), [
"qwertzuiopasd",
"mnbvcxylk",
@ -51,6 +59,15 @@ Deno.test("TextLineStream() parses with `allowCR` enabled", async () => {
"",
"654321",
]);
const stream2 = ReadableStream.from("rewq0987\r\n\r\n654321\n")
.pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream2), [
"rewq0987",
"",
"654321",
]);
});
Deno.test("TextLineStream() parses large chunks", async () => {