How auto-detection and conversion work
mainUndio provides high-level utilities that automatically detect the input type and convert it to the requested target type. This simplifies code when dealing with polymorphic data (e.g., a value that could be a Blob, ArrayBuffer, or Uint8Array).
Important: Because some conversions involve streams, the returned value may be a Promise. Always use await when calling these utilities.
Supported types for auto-detection include:
ArrayBufferBase64BlobDataViewNumber ArrayReadableStreamNodeStreamResponseTextUint8Array
import { detectType, toText, toReadableStream } from "undio";
// Convert any supported type (auto-detected)
const string = await toText(value);
const stream = await toReadableStream(value);
// Returns: "ArrayBuffer" | "Blob"| "DataView" | "NumberArray" | "ReadableStream" | "String" | "Uint8Array"
const type = detectType(value);