diff --git a/types/d3-fetch/d3-fetch-tests.ts b/types/d3-fetch/d3-fetch-tests.ts new file mode 100644 index 0000000000..1dfff0e04f --- /dev/null +++ b/types/d3-fetch/d3-fetch-tests.ts @@ -0,0 +1,39 @@ +import * as d3Fetch from 'd3-fetch'; +import { DSVParsedArray, DSVRowString, DSVRowAny } from 'd3-dsv'; + +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); +promise = d3Fetch.image(url); +promise = d3Fetch.image(url, init); +promise = d3Fetch.json(url); +promise = d3Fetch.json(url, init); + +let myString: Promise; +myString = d3Fetch.text(url); +myString = d3Fetch.text(url, init); + +const parseRow = (d: {}) => { + const myType: MyType = { foo: 'foo' }; + return myType; +}; +let promise2: Promise>; +promise2 = d3Fetch.csv(url); +promise2 = d3Fetch.csv(url, init); +promise2 = d3Fetch.csv(url, init, parseRow); +promise2 = d3Fetch.dsv(';', url); +promise2 = d3Fetch.dsv(';', url, init); +promise2 = d3Fetch.dsv(';', url, init, parseRow); +promise2 = d3Fetch.tsv(url); +promise2 = d3Fetch.tsv(url, init); +promise2 = d3Fetch.tsv(url, init, parseRow); diff --git a/types/d3-fetch/index.d.ts b/types/d3-fetch/index.d.ts new file mode 100644 index 0000000000..6a62630808 --- /dev/null +++ b/types/d3-fetch/index.d.ts @@ -0,0 +1,64 @@ +// Type definitions for d3-fetch 1.0.1 +// Project: https://d3js.org/d3-fetch/ +// Definitions by: Hugues Stefanski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { DSVParsedArray, DSVRowString, DSVRowAny } from 'd3-dsv'; + +/**Fetches the binary file at the specified input URL as a Blob. */ +export function blob(url: 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(url: string, init: RequestInit): Promise; +/**Fetches the binary file at the specified input URL as an ArrayBuffer. */ +export function buffer(url: 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(url: string, init: RequestInit): Promise; + +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv(url: string): Promise>; +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv(url: string, init: RequestInit): Promise>; +/**Equivalent to d3.dsv with the comma character as the delimiter. */ +export function csv( + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>; + +/**Fetches the DSV file at the specified input URL. */ +export function dsv(delimiter: string, url: string): Promise>; +/**Fetches the DSV file at the specified input URL. */ +export function dsv(delimiter: string, url: string, init: RequestInit): Promise>; +/**Fetches the DSV file at the specified input URL. */ +export function dsv( + delimiter: string, + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>; + +/**Fetches the image at the specified input URL. */ +export function image(url: string): Promise; +/**Fetches the image at the specified input URL. Passes init along to the underlying call to fetch. */ +export function image(url: string, init: RequestInit): Promise; + +/**Fetches the json file at the specified input URL. */ +export function json(url: string): Promise; +/**Fetches the json file at the specified input URL. Passes init along to the underlying call to fetch. */ +export function json(url: string, init: RequestInit): Promise; + +/**Fetches the text file at the specified input URL. */ +export function text(url: string): Promise; +/**Fetches the text file at the specified input URL. Passes init along to the underlying call to fetch. */ +export function text(url: string, init: RequestInit): Promise; + +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv(url: string): Promise>; +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv(url: string, init: RequestInit): Promise>; +/**Equivalent to d3.dsv with the tab character as the delimiter. */ +export function tsv( + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>; diff --git a/types/d3-fetch/tsconfig.json b/types/d3-fetch/tsconfig.json new file mode 100644 index 0000000000..4d18bd9ade --- /dev/null +++ b/types/d3-fetch/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es2017", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "d3-fetch-tests.ts" + ] +} diff --git a/types/d3-fetch/tslint.json b/types/d3-fetch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/d3-fetch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }