From c72e0700902db8456bb62d92821211dede62317e Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Mon, 11 Dec 2023 22:26:10 +0100 Subject: [PATCH] feat: fetch text --- README.md | 6 +++--- examples/vanilla-ts/src/main.ts | 4 ++-- src/{fetchText.ts => fetch/text.ts} | 2 +- test/{fetchText.test.ts => fetch/text.test.ts} | 10 +++++----- test/ndJson/parse.test.ts | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) rename src/{fetchText.ts => fetch/text.ts} (90%) rename test/{fetchText.test.ts => fetch/text.test.ts} (62%) diff --git a/README.md b/README.md index 6c48764..1ffedd0 100644 --- a/README.md +++ b/README.md @@ -69,14 +69,14 @@ concat(
-fetchText +text ```javascript -import { fetchText } from '@ilteoood/re-flusso/fetchText'; +import { text } from '@ilteoood/re-flusso/fetch/text'; const response = await fetch('...') -fetchText(response) +text(response) ```
diff --git a/examples/vanilla-ts/src/main.ts b/examples/vanilla-ts/src/main.ts index 0797d64..772875d 100644 --- a/examples/vanilla-ts/src/main.ts +++ b/examples/vanilla-ts/src/main.ts @@ -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"; @@ -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( diff --git a/src/fetchText.ts b/src/fetch/text.ts similarity index 90% rename from src/fetchText.ts rename to src/fetch/text.ts index d7d825d..d55f921 100644 --- a/src/fetchText.ts +++ b/src/fetch/text.ts @@ -1,4 +1,4 @@ -export const fetchText = ( +export const text = ( response: Response, label?: string, options?: TextDecoderOptions, diff --git a/test/fetchText.test.ts b/test/fetch/text.test.ts similarity index 62% rename from test/fetchText.test.ts rename to test/fetch/text.test.ts index d87f2d6..5218ce3 100644 --- a/test/fetchText.test.ts +++ b/test/fetch/text.test.ts @@ -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); }); diff --git a/test/ndJson/parse.test.ts b/test/ndJson/parse.test.ts index cf268b1..d6a8f30 100644 --- a/test/ndJson/parse.test.ts +++ b/test/ndJson/parse.test.ts @@ -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 () => { @@ -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); });