js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
37 lines (36 loc) • 1.17 kB
TypeScript
/**
* Utility functions for handling fetch in different environments
*/
export interface FetchResponse {
json(): Promise<any>;
text(): Promise<string>;
arrayBuffer(): Promise<ArrayBuffer>;
body: ReadableStream<Uint8Array>;
ok: boolean;
status: number;
statusText: string;
headers: Headers;
}
export interface FetchOptions {
method?: string;
headers?: Record<string, string>;
body?: string | ArrayBuffer | Uint8Array;
}
export type FetchFunction = (url: string, options?: FetchOptions) => Promise<FetchResponse>;
/**
* Get a fetch implementation that works in both Node.js and browser environments
*
* This function tries to use:
* 1. The global fetch if available (browsers and Node.js >= 18)
* 2. node-fetch if installed (for older Node.js versions)
* 3. Falls back to a mock implementation that throws an error
*
* @returns A fetch function that works in the current environment
*/
export declare function getFetch(): FetchFunction;
/**
* Check if fetch is available in the current environment
*
* @returns True if fetch is available, false otherwise
*/
export declare function isFetchAvailable(): boolean;