Completed fetch API

This commit is contained in:
Hugues Stefanski
2018-01-29 21:12:59 +01:00
parent 2a858618c3
commit d25d2ee1b4
3 changed files with 59 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
import * as d3Fetch from 'd3-fetch';
interface MyType {
foo: string;
}
let promise: Promise<MyType>;
const url = 'foo.bar';
const init: RequestInit = {};
promise = d3Fetch.blob<MyType>(url);
promise = d3Fetch.blob<MyType>(url, init);
promise = d3Fetch.buffer<MyType>(url);
promise = d3Fetch.buffer<MyType>(url, init);
+42
View File
@@ -3,3 +3,45 @@
// Definitions by: Hugues Stefanski <https://github.com/ledragon>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**Fetches the binary file at the specified input URL as a Blob. */
export function blob<ResponseData>(input: string): Promise<ResponseData>;
/**Fetches the binary file at the specified input URL as a Blob. Passes init along to the underlying call to fetch. */
export function blob<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Fetches the binary file at the specified input URL as an ArrayBuffer. */
export function buffer<ResponseData>(input: string): Promise<ResponseData>;
/**Fetches the binary file at the specified input URL as an ArrayBuffer. Passes init along to the underlying call to fetch. */
export function buffer<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Equivalent to d3.dsv with the comma character as the delimiter. */
export function csv<ResponseData>(input: string): Promise<ResponseData>;
/**Equivalent to d3.dsv with the comma character as the delimiter. */
export function csv<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Equivalent to d3.dsv with the comma character as the delimiter. */
export function csv<ResponseData>(input: string, init: RequestInit, row: (d: any) => any): Promise<ResponseData>;
/**Fetches the DSV file at the specified input URL. */
export function dsv<ResponseData>(delimiter: string, input: string): Promise<ResponseData>;
export function dsv<ResponseData>(delimiter: string, input: string, init: RequestInit): Promise<ResponseData>;
export function dsv<ResponseData>(delimiter: string, input: string, init: RequestInit, row: any): Promise<ResponseData>;
/**Fetches the image at the specified input URL. */
export function image<ResponseData>(input: string): Promise<ResponseData>;
/**Fetches the image at the specified input URL. Passes init along to the underlying call to fetch. */
export function image<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Fetches the json file at the specified input URL. */
export function json<ResponseData>(input: string): Promise<ResponseData>;
/**Fetches the json file at the specified input URL. Passes init along to the underlying call to fetch. */
export function json<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Fetches the text file at the specified input URL. */
export function text(input: string): Promise<string>;
/**Fetches the text file at the specified input URL. Passes init along to the underlying call to fetch. */
export function text(input: string, init: RequestInit): Promise<string>;
/**Equivalent to d3.dsv with the tab character as the delimiter. */
export function tsv<ResponseData>(input: string): Promise<ResponseData>;
/**Equivalent to d3.dsv with the tab character as the delimiter. */
export function tsv<ResponseData>(input: string, init: RequestInit): Promise<ResponseData>;
/**Equivalent to d3.dsv with the tab character as the delimiter. */
export function tsv<ResponseData>(input: string, init: RequestInit, row: (d: any) => any): Promise<ResponseData>;
+2 -1
View File
@@ -2,7 +2,8 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
"es2017",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,