Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
declare module "fetch-ponyfill" { | ||
export default FetchPonyfill.bootstrap; | ||
} | ||
|
||
declare namespace FetchPonyfill { | ||
export function bootstrap(options?: PonyfillCreateOptions): FetchPonyfillStatic; | ||
|
||
interface PonyfillCreateOptions { | ||
Promise?: Function; | ||
XMLHttpRequest?: Function; | ||
} | ||
|
||
interface FetchPonyfillStatic { | ||
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>; | ||
Headers: typeof Headers; | ||
Request: typeof Request; | ||
Response: typeof Response; | ||
} | ||
|
||
type HeadersInit = Headers | string[][] | { [key: string]: string }; | ||
class Headers { | ||
constructor(init?: HeadersInit); | ||
|
||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
get(name: string): string | null; | ||
has(name: string): boolean; | ||
set(name: string, value: string): void; | ||
|
||
// WebIDL pair iterator: iterable<ByteString, ByteString> | ||
entries(): IterableIterator<[string, string]>; | ||
forEach(callback: (value: string, index: number, headers: Headers) => void, thisArg?: any): void; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
} | ||
|
||
type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData /* | URLSearchParams */ | string; | ||
type ResponseBodyInit = BodyInit | ReadableStream; | ||
interface Body { | ||
readonly bodyUsed: boolean; | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
blob(): Promise<Blob>; | ||
formData(): Promise<FormData>; | ||
json(): Promise<any>; | ||
json<T>(): Promise<T>; | ||
text(): Promise<string>; | ||
} | ||
|
||
type RequestInfo = Request | string; | ||
class Request { | ||
constructor(input: RequestInfo, init?: RequestInit); | ||
|
||
readonly method: string; | ||
readonly url: string; | ||
readonly headers: Headers; | ||
|
||
readonly type: RequestType | ||
readonly destination: RequestDestination; | ||
readonly referrer: string; | ||
readonly referrerPolicy: ReferrerPolicy; | ||
readonly mode: RequestMode; | ||
readonly credentials: RequestCredentials; | ||
readonly cache: RequestCache; | ||
readonly redirect: RequestRedirect; | ||
readonly integrity: string; | ||
readonly keepalive: boolean; | ||
|
||
clone(): Request; | ||
} | ||
interface Request extends Body {} | ||
interface RequestInit { | ||
method?: string; | ||
headers?: HeadersInit; | ||
body?: BodyInit; | ||
referrer?: string; | ||
referrerPolicy?: ReferrerPolicy; | ||
mode?: RequestMode; | ||
credentials?: RequestCredentials; | ||
cache?: RequestCache; | ||
redirect?: RequestRedirect; | ||
integrity?: string; | ||
window?: null; // can only be set to null | ||
} | ||
|
||
type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video"; | ||
type RequestDestination = "" | "document" | "embed" | "font" | "image" | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "worker" | "xslt"; | ||
type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors"; | ||
type RequestCredentials = "omit" | "same-origin" | "include"; | ||
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached"; | ||
type RequestRedirect = "follow" | "error" | "manual"; | ||
|
||
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url"; | ||
|
||
class Response { | ||
constructor(body?: ResponseBodyInit, init?: ResponseInit); | ||
|
||
static error(): Response; | ||
static redirect(url: string, status?: number): Response; | ||
|
||
readonly type: ResponseType; | ||
|
||
readonly url: string; | ||
readonly redirected: boolean; | ||
readonly status: number; | ||
readonly ok: boolean; | ||
readonly statusText: string; | ||
readonly headers: Headers; | ||
readonly body: ReadableStream | null; | ||
readonly trailer: Promise<Headers>; | ||
|
||
clone(): Response; | ||
} | ||
interface Response extends Body {} | ||
|
||
interface ResponseInit { | ||
status?: number; | ||
statusText?: string; | ||
headers?: HeadersInit; | ||
} | ||
|
||
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
}, | ||
"files": [ | ||
"fetch-node.js", | ||
"build/fetch-browser.js" | ||
"build/fetch-browser.js", | ||
"index.d.ts" | ||
] | ||
} |