Skip to content

Commit

Permalink
fix: fetch-n
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Nov 29, 2023
1 parent 61c4ef2 commit df64328
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ concat(
```
</details>
<details>
<summary>fetchText</summary>
```javascript
import { fetchText } from '@ilteoood/re-flusso/fetchText';

const response = await fetch('...')

fetchText(response)
```
</details>
<details>
<summary>filter</summary>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"streams"
],
"devDependencies": {
"@biomejs/biome": "^1.3.3",
"@biomejs/biome": "^1.4.0",
"@edge-runtime/vm": "^3.1.7",
"happy-dom": "^12.10.3",
"tsup": "^8.0.1",
Expand Down
44 changes: 22 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/fetchText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const fetchText = (response: Response, label?: string, options?: TextDecoderOptions) =>
// biome-ignore lint/style/noNonNullAssertion: For this function, response must be correctly resolved
response.body!.pipeThrough(new TextDecoderStream(label, options));
17 changes: 17 additions & 0 deletions test/fetchText.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from "vitest";
import { fetchText } from "../src/fetchText";
import { pipeline } from "../src/pipeline";
import { toArray } from "../src/toArray";

describe("fetchText", () => {
test("should fetch text", async () => {
const destinationArray = [];
const response = await fetch(
"https://gist.githubusercontent.com/rfmcnally/0a5a16e09374da7dd478ffbe6ba52503/raw/095e75121f31a8b7dc88aa89dbd637a944ce264a/ndjson-sample.json",
);

await pipeline(fetchText(response), toArray(destinationArray));

expect(destinationArray.join("")).toHaveLength(7476);
});
});

0 comments on commit df64328

Please sign in to comment.