@wevu/web-apis
Version:
Web API polyfills and global installers for mini-program runtimes
54 lines (53 loc) • 1.95 kB
text/typescript
import { URLPolyfill } from "./url.mjs";
//#region src/http.d.ts
type HeaderRecord = Record<string, string>;
declare class HeadersPolyfill {
private readonly store;
constructor(init?: unknown);
append(key: string, value: string): void;
set(key: string, value: string): void;
get(key: string): string | null;
has(key: string): boolean;
delete(key: string): void;
forEach(callback: (value: string, key: string) => void): void;
entries(): ArrayIterator<[string, string]>;
keys(): ArrayIterator<string>;
values(): ArrayIterator<string>;
[Symbol.iterator](): ArrayIterator<[string, string]>;
}
type RequestBodyLike = string | ArrayBuffer | ArrayBufferView | Blob | null | undefined;
declare class RequestPolyfill {
readonly url: string;
readonly method: string;
readonly headers: HeadersPolyfill;
readonly signal: AbortSignal | null;
readonly [Symbol.toStringTag] = "Request";
constructor(input: string | URL | URLPolyfill | RequestPolyfill, init?: Record<string, any>);
get body(): ReadableStream<Uint8Array> | null;
get bodyUsed(): boolean;
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>;
clone(): RequestPolyfill;
}
declare class ResponsePolyfill {
readonly headers: HeadersPolyfill;
readonly status: number;
readonly statusText: string;
readonly ok: boolean;
readonly url: string;
readonly redirected = false;
readonly type: ResponseType;
readonly [Symbol.toStringTag] = "Response";
constructor(body?: RequestBodyLike, init?: Record<string, any>);
get body(): ReadableStream<Uint8Array> | null;
get bodyUsed(): boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<void>;
json(): Promise<any>;
text(): Promise<string>;
clone(): ResponsePolyfill;
}
declare function headersToObject(headers: HeadersPolyfill | Headers): HeaderRecord;
//#endregion
export { HeadersPolyfill, RequestPolyfill, ResponsePolyfill, headersToObject };