From d9c402ca1e27a2e30c99f0afc81cca6894334406 Mon Sep 17 00:00:00 2001 From: Mikkel RINGAUD Date: Tue, 27 Feb 2024 19:08:08 +0100 Subject: [PATCH] docs: cleanup --- README.md | 45 +++----------------------- docs/src/content/docs/guides/tauri.mdx | 37 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 docs/src/content/docs/guides/tauri.mdx diff --git a/README.md b/README.md index 7dc1437..6bbfe31 100644 --- a/README.md +++ b/README.md @@ -89,50 +89,13 @@ yarn add pawnote npm install pawnote ``` -## Usage +## Documentation & Guides -You can see multiple examples in the [`examples`](./examples) folder. +You can find the documentation, some guides and small examples at [pawnote.js.org](https://pawnote.js.org) for more informations about the API and how to use it. -### Tauri +If you need complete examples, then we got **a lot** of those in the [`examples`](./examples) folder, hoping you can find your joy in there. -Since Pawnote uses `fetch` as default fetcher, you need to use a custom fetcher to make it work with the [Tauri HTTP API](https://tauri.app/v1/api/js/http). - -Here's an example fetcher made to work with Tauri (v1) : - -```typescript -import { type PawnoteFetcher } from "pawnote"; -import { Body, ResponseType, getClient } from "@tauri-apps/api/http"; - -const tauriPawnoteFetcher: PawnoteFetcher = async (url, options) => { - const client = await getClient(options.redirect === "manual" ? { - maxRedirections: 0 - } : void 0); - - const response = await client.request({ - url, - method: options.method, - headers: options.headers, - body: options.method !== "GET" && options.body ? Body.text(options.body) : void 0, - responseType: ResponseType.Text - }); - - return { - headers: response.headers, - text: async () => response.data, - json: async () => JSON.parse(response.data) as T - } -}; - -export default tauriPawnoteFetcher; -``` - -## API - -Documentation is not yet available, for now you'll have to use intellisense. -Most of the methods are self-explanatory and well commented. - -We'll see if we can generate a documentation website -using comments from the source code in the future. +If none of those are helpful, you can always [open an issue](https://github.com/LiterateInk/Pawnote/issues) to ask for help. ## Resources diff --git a/docs/src/content/docs/guides/tauri.mdx b/docs/src/content/docs/guides/tauri.mdx new file mode 100644 index 0000000..cafdf58 --- /dev/null +++ b/docs/src/content/docs/guides/tauri.mdx @@ -0,0 +1,37 @@ +--- +title: Tauri +description: Want to make Pawnote run under Tauri ? Here's how to do it. +--- + +## Fetcher (for Tauri v1) + +Since Pawnote uses [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) as default fetcher, you need to create a custom fetcher to make it work with the [Tauri HTTP API](https://tauri.app/v1/api/js/http). + +Here's a simple one that should always work for Pawnote: + +```typescript +import { type PawnoteFetcher } from "pawnote"; +import { Body, ResponseType, getClient } from "@tauri-apps/api/http"; + +const tauriPawnoteFetcher: PawnoteFetcher = async (url, options) => { + const client = await getClient(options.redirect === "manual" ? { + maxRedirections: 0 + } : void 0); + + const response = await client.request({ + url, + method: options.method, + headers: options.headers, + body: options.method !== "GET" && options.body ? Body.text(options.body) : void 0, + responseType: ResponseType.Text + }); + + return { + headers: response.headers, + text: async () => response.data, + json: async () => JSON.parse(response.data) as T + } +}; + +export default tauriPawnoteFetcher; +```