1 | // Type definitions for d3-fetch 3.0
|
2 | // Project: https://d3js.org/d3-fetch/
|
3 | // Definitions by: Hugues Stefanski <https://github.com/ledragon>
|
4 | // denisname <https://github.com/denisname>
|
5 | // Nathan Bierema <https://github.com/Methuselah96>
|
6 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
7 |
|
8 | // Last module patch version validated against: 3.0.1
|
9 |
|
10 | import { DSVParsedArray, DSVRowArray, DSVRowString } from "d3-dsv";
|
11 |
|
12 | /**
|
13 | * Fetches the binary file at the specified input URL and returns it as a Promise of a Blob.
|
14 | * If init is specified, it is passed along to the underlying call to fetch.
|
15 | *
|
16 | * @param url A valid URL string.
|
17 | * @param init An optional request initialization object.
|
18 | */
|
19 | export function blob(url: string, init?: RequestInit): Promise<Blob>;
|
20 |
|
21 | /**
|
22 | * Fetches the binary file at the specified input URL and returns it as a Promise of an ArrayBuffer.
|
23 | * If init is specified, it is passed along to the underlying call to fetch.
|
24 | *
|
25 | * @param url A valid URL string.
|
26 | * @param init An optional request initialization object.
|
27 | */
|
28 | export function buffer(url: string, init?: RequestInit): Promise<ArrayBuffer>;
|
29 |
|
30 | /**
|
31 | * Fetches the CSV file at the specified input URL and returns
|
32 | * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
|
33 | * objects are represented as strings.
|
34 | *
|
35 | * If init is specified, it is passed along to the underlying call to fetch.
|
36 | *
|
37 | * The generic parameter describes the column names as a union of string literal types.
|
38 | *
|
39 | * @param url A valid URL string.
|
40 | * @param init An optional request initialization object.
|
41 | */
|
42 | export function csv<Columns extends string>(
|
43 | url: string,
|
44 | init?: RequestInit
|
45 | // tslint:disable-next-line:no-unnecessary-generics
|
46 | ): Promise<DSVRowArray<Columns>>;
|
47 | /**
|
48 | * Fetches the CSV file at the specified input URL and returns
|
49 | * a promise of an array of objects representing the parsed rows.
|
50 | *
|
51 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
52 | * see dsv.csvParse for details.
|
53 | *
|
54 | * The first generic parameter describes the type of the object representation of a parsed row.
|
55 | * The second generic parameter describes the column names as a union of string literal types.
|
56 | *
|
57 | * @param url A valid URL string.
|
58 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
59 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
60 | * the row is skipped and will be omitted from the array returned by dsv.csvParse; otherwise, the returned value defines the corresponding row object.
|
61 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
62 | */
|
63 | export function csv<ParsedRow extends object, Columns extends string = string>(
|
64 | url: string,
|
65 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
66 | ): Promise<DSVParsedArray<ParsedRow>>;
|
67 | /**
|
68 | * Fetches the CSV file at the specified input URL and returns
|
69 | * a promise of an array of objects representing the parsed rows.
|
70 | *
|
71 | * The init object is passed along to the underlying call to fetch.
|
72 | *
|
73 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
74 | * see dsv.csvParse for details.
|
75 | *
|
76 | * The first generic parameter describes the type of the object representation of a parsed row.
|
77 | * The second generic parameter describes the column names as a union of string literal types.
|
78 | *
|
79 | * @param url A valid URL string.
|
80 | * @param init An request initialization object.
|
81 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
82 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
83 | * the row is skipped and will be omitted from the array returned by dsv.csvParse; otherwise, the returned value defines the corresponding row object.
|
84 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
85 | */
|
86 | export function csv<ParsedRow extends object, Columns extends string = string>(
|
87 | url: string,
|
88 | init: RequestInit,
|
89 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
90 | ): Promise<DSVParsedArray<ParsedRow>>;
|
91 |
|
92 | /**
|
93 | * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
|
94 | * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
|
95 | * objects are represented as strings.
|
96 | *
|
97 | * If init is specified, it is passed along to the underlying call to fetch.
|
98 | *
|
99 | * The generic parameter describes the column names as a union of string literal types.
|
100 | *
|
101 | * @param delimiter The delimiter character used in the DSV file to be fetched.
|
102 | * @param url A valid URL string.
|
103 | * @param init An optional request initialization object.
|
104 | */
|
105 | export function dsv<Columns extends string>(
|
106 | delimiter: string,
|
107 | url: string,
|
108 | init?: RequestInit
|
109 | // tslint:disable-next-line:no-unnecessary-generics
|
110 | ): Promise<DSVRowArray<Columns>>;
|
111 | /**
|
112 | * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
|
113 | * a promise of an array of objects representing the parsed rows.
|
114 | *
|
115 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
116 | * see dsv.parse for details.
|
117 | *
|
118 | * The first generic parameter describes the type of the object representation of a parsed row.
|
119 | * The second generic parameter describes the column names as a union of string literal types.
|
120 | *
|
121 | * @param delimiter The delimiter character used in the DSV file to be fetched.
|
122 | * @param url A valid URL string.
|
123 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
124 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
125 | * the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object.
|
126 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
127 | */
|
128 | export function dsv<ParsedRow extends object, Columns extends string = string>(
|
129 | delimiter: string,
|
130 | url: string,
|
131 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
132 | ): Promise<DSVParsedArray<ParsedRow>>;
|
133 | /**
|
134 | * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
|
135 | * a promise of an array of objects representing the parsed rows.
|
136 | *
|
137 | * The init object is passed along to the underlying call to fetch.
|
138 | *
|
139 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
140 | * see dsv.parse for details.
|
141 | *
|
142 | * The first generic parameter describes the type of the object representation of a parsed row.
|
143 | * The second generic parameter describes the column names as a union of string literal types.
|
144 | *
|
145 | * @param delimiter The delimiter character used in the DSV file to be fetched.
|
146 | * @param url A valid URL string.
|
147 | * @param init An request initialization object.
|
148 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
149 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
150 | * the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object.
|
151 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
152 | */
|
153 | export function dsv<ParsedRow extends object, Columns extends string = string>(
|
154 | delimiter: string,
|
155 | url: string,
|
156 | init: RequestInit,
|
157 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
158 | ): Promise<DSVParsedArray<ParsedRow>>;
|
159 |
|
160 | /**
|
161 | * Fetches the file at the specified input URL as text, parses it as HTML and returns a Promise of an HTML DOM Document.
|
162 | *
|
163 | * If init is specified, it is passed along to the underlying call to fetch.
|
164 | *
|
165 | * @param url A valid URL string.
|
166 | * @param init An optional request initialization object.
|
167 | */
|
168 | export function html(url: string, init?: RequestInit): Promise<Document>;
|
169 |
|
170 | /**
|
171 | * Fetches the image at the specified input URL and returns a promise of an HTML image element.
|
172 | *
|
173 | * If init is specified, sets any additional properties on the image before loading.
|
174 | *
|
175 | * @param url A valid URL string.
|
176 | * @param init An optional object of image properties to set.
|
177 | */
|
178 | export function image(url: string, init?: Partial<HTMLImageElement>): Promise<HTMLImageElement>;
|
179 |
|
180 | /**
|
181 | * Fetches the json file at the specified input URL and returns it as a Promise of a parsed JSON object.
|
182 | *
|
183 | * If init is specified, it is passed along to the underlying call to fetch.
|
184 | *
|
185 | * If the server returns a status code of [204 No Content](https://developer.mozilla.org/docs/Web/HTTP/Status/204)
|
186 | * or [205 Reset Content](https://developer.mozilla.org/docs/Web/HTTP/Status/205), the promise resolves to `undefined`.
|
187 | *
|
188 | * The generic parameter describes the type of the object parsed from the returned JSON.
|
189 | *
|
190 | * @param url A valid URL string.
|
191 | * @param init An optional request initialization object.
|
192 | */
|
193 | // tslint:disable-next-line:no-unnecessary-generics
|
194 | export function json<ParsedJSONObject extends any>(url: string, init?: RequestInit): Promise<ParsedJSONObject | undefined>;
|
195 |
|
196 | /**
|
197 | * Fetches the file at the specified input URL as text, parses it as SVG and returns a Promise of an SVG Document.
|
198 | *
|
199 | * If init is specified, it is passed along to the underlying call to fetch.
|
200 | *
|
201 | * @param url A valid URL string.
|
202 | * @param init An optional request initialization object.
|
203 | */
|
204 | export function svg(url: string, init?: RequestInit): Promise<Document>;
|
205 |
|
206 | /**
|
207 | * Fetches the text file at the specified input URL and returns it as a Promise of a string.
|
208 | *
|
209 | * If init is specified, it is passed along to the underlying call to fetch.
|
210 | *
|
211 | * @param url A valid URL string.
|
212 | * @param init An optional request initialization object.
|
213 | */
|
214 | export function text(url: string, init?: RequestInit): Promise<string>;
|
215 |
|
216 | /**
|
217 | * Fetches the TSV file at the specified input URL and returns
|
218 | * a promise of an array of objects representing the parsed rows.
|
219 | *
|
220 | * If init is specified, it is passed along to the underlying call to fetch.
|
221 | *
|
222 | * The generic parameter describes the column names as a union of string literal types.
|
223 | *
|
224 | * @param url A valid URL string.
|
225 | * @param init An optional request initialization object.
|
226 | */
|
227 | export function tsv<Columns extends string>(
|
228 | url: string,
|
229 | init?: RequestInit
|
230 | // tslint:disable-next-line:no-unnecessary-generics
|
231 | ): Promise<DSVRowArray<Columns>>;
|
232 | /**
|
233 | * Fetches the TSV file at the specified input URL and returns
|
234 | * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
|
235 | * objects are represented as strings.
|
236 | *
|
237 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
238 | * see dsv.tsvParse for details.
|
239 | *
|
240 | * The first generic parameter describes the type of the object representation of a parsed row.
|
241 | * The second generic parameter describes the column names as a union of string literal types.
|
242 | *
|
243 | * @param url A valid URL string.
|
244 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
245 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
246 | * the row is skipped and will be omitted from the array returned by dsv.tsvParse; otherwise, the returned value defines the corresponding row object.
|
247 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
248 | */
|
249 | export function tsv<ParsedRow extends object, Columns extends string = string>(
|
250 | url: string,
|
251 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
252 | ): Promise<DSVParsedArray<ParsedRow>>;
|
253 | /**
|
254 | * Fetches the TSV file at the specified input URL and returns
|
255 | * a promise of an array of objects representing the parsed rows.
|
256 | *
|
257 | * The init object is passed along to the underlying call to fetch.
|
258 | *
|
259 | * The specified row conversion function is used to map and filter row objects to a more-specific representation;
|
260 | * see dsv.tsvParse for details.
|
261 | *
|
262 | * The first generic parameter describes the type of the object representation of a parsed row.
|
263 | * The second generic parameter describes the column names as a union of string literal types.
|
264 | *
|
265 | * @param url A valid URL string.
|
266 | * @param init An request initialization object.
|
267 | * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
|
268 | * the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined,
|
269 | * the row is skipped and will be omitted from the array returned by dsv.tsvParse; otherwise, the returned value defines the corresponding row object.
|
270 | * In effect, row is similar to applying a map and filter operator to the returned rows.
|
271 | */
|
272 | export function tsv<ParsedRow extends object, Columns extends string = string>(
|
273 | url: string,
|
274 | init: RequestInit,
|
275 | row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null
|
276 | ): Promise<DSVParsedArray<ParsedRow>>;
|
277 |
|
278 | /**
|
279 | * Fetches the file at the specified input URL as text, parses it as XML and returns a Promise of an XML Document.
|
280 | *
|
281 | * If init is specified, it is passed along to the underlying call to fetch.
|
282 | *
|
283 | * @param url A valid URL string.
|
284 | * @param init An optional request initialization object.
|
285 | */
|
286 | export function xml(url: string, init?: RequestInit): Promise<XMLDocument>;
|