Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 26, 2024
1 parent fe546e8 commit d352926
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

⇔ Conventionally and Safely convert between various JavaScript data types:

- [ArrayBuffer][ArrayBuffer]
- [Blob][Blob]
- [DataView][DataView]
- [Number Array][Number Array]
- [ReadableStream](ReadableStream)
- [String][String]
- [Uint8Array][Uint8Array]
👍 [ArrayBuffer][ArrayBuffer]
👍 [Blob][Blob]
👍 [DataView][DataView]
👍 [Number Array][Number Array]
👍[ReadableStream](ReadableStream)
👍 [String][String]
👍 [Uint8Array][Uint8Array]

And enjoy...

Expand Down Expand Up @@ -98,20 +98,27 @@ assertArrayBuffer(value); // Throws an error if value is not ArrayBuffer

## Auto Convert

You can either use explicit `*To*(value)` utils (see "all utils" section) or use auto detection.
Undio automatically detects input type and uses the proper method to convert it to expected type.

**Example:**

```ts
import { detectType, toString } from "undio";
import { detectType, toString, toReadableStream } from "undio";

// Convert any supported type (auto detected)
const string = await toString(value);
const stream = await toReadableStream(value);

// "ArrayBuffer" | "Blob"| "DataView" | "NumberArray" | "ReadableStream" | "String" | "Uint8Array";
const type = detectType(value);

// Convert any supported type (auto detected)
const value = await toString(value);
```

> [!NOTE]
> Because of stream support, the return type can be a promise. Always make sure to use an `await` before them.
> [!NOTE]
> Alternatively you can use low level `*To*(value)` utils to explicitly convert from one type to another. See [all utils](#all-utils) section.
## All utils

<details>
Expand Down

0 comments on commit d352926

Please sign in to comment.