From d25d2ee1b42624281a7a36bbe2daf7970ecb02a8 Mon Sep 17 00:00:00 2001 From: Hugues Stefanski Date: Mon, 29 Jan 2018 21:12:59 +0100 Subject: [PATCH] Completed fetch API --- types/d3-fetch/d3-fetch-tests.ts | 15 ++++++++++++ types/d3-fetch/index.d.ts | 42 ++++++++++++++++++++++++++++++++ types/d3-fetch/tsconfig.json | 3 ++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/types/d3-fetch/d3-fetch-tests.ts b/types/d3-fetch/d3-fetch-tests.ts index e69de29bb2..b82ea8ffbe 100644 --- a/types/d3-fetch/d3-fetch-tests.ts +++ b/types/d3-fetch/d3-fetch-tests.ts @@ -0,0 +1,15 @@ +import * as d3Fetch from 'd3-fetch'; + +interface MyType { + foo: string; +} + +let promise: Promise; +const url = 'foo.bar'; + +const init: RequestInit = {}; + +promise = d3Fetch.blob(url); +promise = d3Fetch.blob(url, init); +promise = d3Fetch.buffer(url); +promise = d3Fetch.buffer(url, init); diff --git a/types/d3-fetch/index.d.ts b/types/d3-fetch/index.d.ts index f5b195ca04..f46a779003 100644 --- a/types/d3-fetch/index.d.ts +++ b/types/d3-fetch/index.d.ts @@ -3,3 +3,45 @@ // Definitions by: Hugues Stefanski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/**Fetches the binary file at the specified input URL as a Blob. */ +export function blob(input: string): Promise; +/**Fetches the binary file at the specified input URL as a Blob. Passes init along to the underlying call to fetch. */ +export function blob(input: string, init: RequestInit): Promise; +/**Fetches the binary file at the specified input URL as an ArrayBuffer. */ +export function buffer(input: string): Promise; +/**Fetches the binary file at the specified input URL as an ArrayBuffer. Passes init along to the underlying call to fetch. */ +export function buffer(input: string, init: RequestInit): Promise; + +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv(input: string): Promise; +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv(input: string, init: RequestInit): Promise; +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv(input: string, init: RequestInit, row: (d: any) => any): Promise; + +/**Fetches the DSV file at the specified input URL. */ +export function dsv(delimiter: string, input: string): Promise; +export function dsv(delimiter: string, input: string, init: RequestInit): Promise; +export function dsv(delimiter: string, input: string, init: RequestInit, row: any): Promise; + +/**Fetches the image at the specified input URL. */ +export function image(input: string): Promise; +/**Fetches the image at the specified input URL. Passes init along to the underlying call to fetch. */ +export function image(input: string, init: RequestInit): Promise; + +/**Fetches the json file at the specified input URL. */ +export function json(input: string): Promise; +/**Fetches the json file at the specified input URL. Passes init along to the underlying call to fetch. */ +export function json(input: string, init: RequestInit): Promise; + +/**Fetches the text file at the specified input URL. */ +export function text(input: string): Promise; +/**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; + +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv(input: string): Promise; +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv(input: string, init: RequestInit): Promise; +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv(input: string, init: RequestInit, row: (d: any) => any): Promise; diff --git a/types/d3-fetch/tsconfig.json b/types/d3-fetch/tsconfig.json index d4e382e338..4d18bd9ade 100644 --- a/types/d3-fetch/tsconfig.json +++ b/types/d3-fetch/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es2017", + "dom" ], "noImplicitAny": true, "noImplicitThis": true,