Skip to content

Commit

Permalink
feat: fetch text
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Dec 11, 2023
1 parent eec2906 commit c72e070
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ concat(
</details>
<details>
<summary>fetchText</summary>
<summary>text</summary>
```javascript
import { fetchText } from '@ilteoood/re-flusso/fetchText';
import { text } from '@ilteoood/re-flusso/fetch/text';

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

fetchText(response)
text(response)
```
</details>
Expand Down
4 changes: 2 additions & 2 deletions examples/vanilla-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchText } from "@ilteoood/re-flusso/fetchText";
import { text } from "@ilteoood/re-flusso/fetch/text";
import { filter } from "@ilteoood/re-flusso/filter";
import { map } from "@ilteoood/re-flusso/map";
import { parse } from "@ilteoood/re-flusso/ndJson/parse";
Expand All @@ -17,7 +17,7 @@ interface ReducedUser {
}

const response = await fetch("/users");
const [response1, response2] = fetchText(response).tee();
const [response1, response2] = text(response).tee();

const containers = {
adult: document.querySelector<HTMLUListElement>(
Expand Down
2 changes: 1 addition & 1 deletion src/fetchText.ts → src/fetch/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const fetchText = (
export const text = (
response: Response,
label?: string,
options?: TextDecoderOptions,
Expand Down
10 changes: 5 additions & 5 deletions test/fetchText.test.ts → test/fetch/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { describe, expect, test } from "vitest";
import { fetchText } from "../src/fetchText";
import { pipeline } from "../src/pipeline";
import { toArray } from "../src/toArray";
import { text } from "../../src/fetch/text";
import { pipeline } from "../../src/pipeline";
import { toArray } from "../../src/toArray";

describe("fetchText", () => {
describe("text", () => {
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));
await pipeline(text(response), toArray(destinationArray));

expect(destinationArray.join("")).toHaveLength(7476);
});
Expand Down
6 changes: 3 additions & 3 deletions test/ndJson/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from "vitest";
import { fetchText } from "../../src/fetchText";
import { text } from "../../src/fetch/text";
import { parse } from "../../src/ndJson/parse";
import { pipeline } from "../../src/pipeline";
import { toArray } from "../../src/toArray";
import { parse } from "../../src/ndJson/parse";

describe("ndJson parse", () => {
it("should parse an ndJson string", async () => {
Expand All @@ -11,7 +11,7 @@ describe("ndJson parse", () => {
"https://gist.githubusercontent.com/rfmcnally/0a5a16e09374da7dd478ffbe6ba52503/raw/095e75121f31a8b7dc88aa89dbd637a944ce264a/ndjson-sample.json",
);

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

expect(destinationArray).toHaveLength(5);
});
Expand Down

0 comments on commit c72e070

Please sign in to comment.