1 | import {
|
2 | Body as NodeBody,
|
3 | Headers as NodeHeaders,
|
4 | Request as NodeRequest,
|
5 | Response as NodeResponse,
|
6 | RequestInit as NodeRequestInit
|
7 | } from "node-fetch";
|
8 |
|
9 | declare namespace unfetch {
|
10 | export type IsomorphicHeaders = Headers | NodeHeaders;
|
11 | export type IsomorphicBody = Body | NodeBody;
|
12 | export type IsomorphicResponse = Response | NodeResponse;
|
13 | export type IsomorphicRequest = Request | NodeRequest;
|
14 | export type IsomorphicRequestInit = RequestInit | NodeRequestInit;
|
15 | }
|
16 |
|
17 | type UnfetchResponse = {
|
18 | ok: boolean,
|
19 | statusText: string,
|
20 | status: number,
|
21 | url: string,
|
22 | text: () => Promise<string>,
|
23 | json: () => Promise<any>,
|
24 | blob: () => Promise<Blob>,
|
25 | clone: () => UnfetchResponse,
|
26 | headers: {
|
27 | keys: () => string[],
|
28 | entries: () => Array<[string, string]>,
|
29 | get: (key: string) => string | undefined,
|
30 | has: (key: string) => boolean,
|
31 | }
|
32 | }
|
33 |
|
34 | type Unfetch = (
|
35 | url: string,
|
36 | options?: {
|
37 | method?: string,
|
38 | headers?: Record<string, string>,
|
39 | credentials?: 'include' | 'omit',
|
40 | body?: Parameters<XMLHttpRequest["send"]>[0]
|
41 | }
|
42 | ) => Promise<UnfetchResponse>
|
43 |
|
44 | declare const unfetch: Unfetch;
|
45 |
|
46 | export default unfetch;
|